Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

...

SMART on FHIR Authorization

Request Authorization

In order to receive the current user, you must request the openid and profile scopes.The fhir-client.js JavaScript library from SMART contains methods to help you handle the SMART on FHIR Authorization workflow with in your app. Include fhir-client.js and jquery in a file which will be loaded when your app is launched. In this snippet, we are showing an example of initiating SMART on FHIR Authorization within html code. To request authorization, call the FHIR.oauth2.authorize method.   

Code Block
languagejs
titleAuthorize
<head>
	<script src="fhir-client.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
</head>
<body>  
<script type="text/javascript">


    FHIR.oauth2.authorize({
        client_id: "my_client_id",
        redirect_uri: "https://mydomain.com/app/index.html",
        scope: "patient/*.read"
openid   profile" });

</script>
...
</body>

Authorization Success

After successful authorization, retrieve the resulting SMART FHIR Client. The current user's fully qualified FHIR URL is on the FHIR client at userId. 

Ex: https://sandbox.hspconsortium.org/dstu2/open-hspc-reference-api/data/Practitioner/COREPRACTITIONER1

Code Block
languagejs
titleAuthorization Success
var currentUserFhirUrl;
 
FHIR.oauth2.ready(function(fhirClient){
	currentUserFhirUrl = fhirClient.userId;
});