For a client application to access REST API resources, it must be authorized as a safe visitor. To implement this authorization, use a connected app and an OAuth 2.0 authorization flow.
A connected app requests access to REST API resources on behalf of the client application. For a connected app to request access, it must be integrated with your org’s REST API using the OAuth 2.0 protocol. OAuth 2.0 is an open protocol that authorizes secure data sharing between applications through the exchange of tokens.
Create OAuth Custom Scopes
A connected app can use the OAuth authorization protocol to access protected resources. As part of the protocol, OAuth default scopes fine-tune the app’s permissions to access protected resources in Salesforce. However, these default scopes are insufficient when an external entity hosts the protected resource. In this scenario, Salesforce plays the role of OAuth authentication and authorization provider, but it has little knowledge about the resource it’s protecting. To define a connected app’s permissions to access protected resources hosted by an external entity, create an OAuth custom scope. The custom scope tells the external entity which information the connected app is authorized to access.
The following custom scopes are available for the Healthcare APIs:
|Medication||GET||user_medication_read OR user_all_read OR system_all_read||Allows read access to the Medication resource.|
|POST||user_medication_write OR user_all_write OR system_all_write||Allows write access to the Medication resource.|
|Condition||GET||user_condition_read OR user_all_read OR system_all_read||Allows read access to the Condition resource.|
|POST||user_condition_write OR user_all_write OR system_all_write||Allows write access to the Condition resource.|
|AllergyIntolerance||GET||user_allergyIntolerance_read OR user_all_read OR system_all_read||Allows read access to the AllergyIntolerance resource.|
|POST||user_allergyIntolerance_write OR user_all_write OR system_all_write||Allows write access to the AllergyIntolerance resource.|
|Procedure||GET||user_procedure_read OR user_all_read OR system_all_read||Allows read access to the Procedure resource.|
|POST||user_procedure_write OR user_all_write OR system_all_write||Allows write access to the Procedure resource.|
Assign an OAuth Custom Scope to the Connected App
After you create an OAuth custom scope in your Salesforce org, you can assign it to a connected app to set data-access permissions for the app.
Note - You must assign the refresh_token scope to the connected app. For detailed instructions, see Assign an OAuth Custom Scope to a Connected App in Salesforce Help.
OAuth authorization flows grant a client app restricted access to REST API resources on a resource server. Each OAuth flow offers a different process for approving access to a client app, but in general the flows consist of three main steps.
- To initiate an authorization flow, a connected app on behalf of a client app requests access to a REST API resource.
- In response, an authorizing server grants access tokens to the connected app.
- A resource server validates these access tokens and approves access to the protected REST API resource.
After reviewing and selecting an OAuth authorization flow, apply it to your connected app. For details about each supported flow, see OAuth Authorization Flows in Salesforce Help.
You must register your connected app by making a POST request on the following registration URL.
where the domain name is api.healthcloud.salesforce.com.
Example of a registration request:
After you register your connected app, the registration is valid for 30 days. If the API is not used in the last seven days, the registration expires. If you use the API in the last seven days, the registration is extended for the next 30 days.