Introduction
This sample will show how to request authorization for an app, using the SMART on FHIR JavaScript Client.
SMART on FHIR Authorization
Request Authorization
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.
<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" }); </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
var currentUserFhirUrl; FHIR.oauth2.ready(function(fhirClient){ currentUserFhirUrl = fhirClient.userId; });