Get the Token
After completing the SMART on FHIR authorization flow, the user is redirected to your system with an authorization code. Your application must exchange this code for an access token before launching the Patient Chart.
To exchange the authorization code
- Receive the
codeandstateparameters at your registeredredirect_uri. Note: Health Gorilla redirects the browser to your registered URI with thecodeneeded for token exchange and thestatevalue you originally passed for session verification. - Send a POST request to the token endpoint from your backend. Use
https://api.healthgorilla.com/oauth2/tokenwithContent-Type: application/x-www-form-urlencoded. - Include the following parameters in the request body:
grant_type=authorization_codecode=YOUR_AUTHORIZATION_CODEredirect_uri=YOUR_REGISTERED_REDIRECT_URIclient_id=YOUR_CLIENT_IDclient_secret=YOUR_CLIENT_SECRET(if you use a confidential client)
- Parse the token response returned by Health Gorilla. If the request is successful, the response includes:
access_tokenrefresh_token(if issued)expires_in(token lifetime in seconds)scopetoken_type(usually Bearer)
- Store the token securely for authorized API access. Use the
access_tokenin session or request headers. If arefresh_tokenis provided, save it securely for future token renewal.