Use OAuth 2.0 Access Token Based Authentication
Oracle Blockchain Platform supports OAuth access token based authorization, which is superior to basic authorization (using a user name and password). The OAuth 2.0 token services provided by Oracle Identity Cloud Service (IDCS) and Identity and Access Management (IAM) are mechanisms that enable you to use a secured token to access Oracle Blockchain Platform REST endpoints. To use this function, you must get an OAuth access token from IDCS or IAM and then use the OAuth access token to call the blockchain REST proxy APIs.
Previously you could fetch an OAuth access token from IDCS by using the IDCS application associated with the blockchain platform instance and the client credentials information from this application, but this function is no longer supported. If you are using the client credentials from the IDCS application associated with the blockchain platform instance to get OAuth tokens, you must now instead follow the steps at Create an IDCS Confidential Application to generate an OAuth token.
Note:
After you generate an OAuth token using the IDCS blockchain application, use it only for making calls to blockchain REST APIs. If your OAuth token is used for other IDCS operations, those operations may fail.Create an IDCS Confidential Application
When an Oracle Blockchain Platform instance is created, an IDCS application is automatically created and associated with the instance. This IDCS application, or instance application, is read-only.
- Expand the Navigation Drawer and then click Oracle Cloud Services.
- In the search field, enter the blockchain platform instance name, and then
click the search icon. In the results, locate and select the entry. The
entry name is in following format:
<OBP_instance_name>-<uuid>.
Use the instance application to grant the REST_CLIENT,
ADMIN, CA_USER and USER roles
as needed for this instance.
Complete the following steps to create a confidential application and use it to generate an access token:
- Sign in to the Oracle Identity Cloud Service administrative console.
- Open the Navigation Drawer, and then select Applications.
- Click Add and then select Confidential Application.
- Enter a name for the application and then click Next.
- Select Configure this application as a client now, and under Authorization, select one or more supported grant types.
- Under Token Issuance Policy, select Add Scope.
- In the Select Scope dialog, click the arrow next to your Oracle Blockchain Platform target instance. In the detailed view of that instance, select the /restproxy resource, then click Add.
- Click Next through the rest of the wizard.
- Click Activate.
curl -u '<client_id>:<client_secret>' \
https://<IDCS-Service-Instance>.identity.oraclecloud.com/oauth2/v1/token \
-H 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' \
-d "grant_type=password&username=<user_name>&password=<user_password>&scope=<primary_audience>/restproxy" The variables in the syntax have the following values:
- <client_id> is the client ID.
- <client_secret> is the client secret.
- <user_name> is the user name of an IDCS user with the REST_CLIENT role.
- <user_password> is the password for the user name.
- <primary_audience> is the instance's REST proxy endpoint URL.
- <IDCS-Service-Instance> is your identity domain ID. It
begins with the characters
idcs-and then is followed by a string of numbers and letters, for example, idcs-88c15f1e68604c058062a4220f560123.
See Generate Access Token and Other OAuth Runtime Tokens to Access the Resource for more information.
curl -u 'myobpinstance-cvirs2oo5e4bpg7pj5kw73oqxcareqrz_APPID:c63b437-1768-4cb6-911e-1e6eg2g3456' \
https://idcs-88c15f1e68604c058062a4220f560123.identity.oraclecloud.com/oauth2/v1/token \
-H 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' \
-d "grant_type=password&username=obpuser1&password=obppassword1&scope=https://myobpinstance-mytenancy-iad.blockchain.ocp.example.com:7443/restproxy"The contents of the response body in JSON format will be similar to the following text:{"access_token":"<access_token>","token_type":"Bearer","expires_in":3600}The value of access_token is an OAuth access token, in which the sub (subject) claim is the <user_name> you used in the request.
IDCS supports various grant types to get an OAuth token from the Oracle Identity Cloud Service authorization server. For additional information about supported grant types, see: Supported Access Grant Types.
JWT Assertion Grant Type
- The
aud(audience) claim in the user assertion must include the IDCS audiencehttps://identity.oraclecloud.com/:"aud": [ "https://identity.oraclecloud.com/" ],
Get an OAuth Access Token from IAM
You need get an access token using the IAM REST API. See Generate Access Token and Other OAuth Runtime Tokens to Access the Resource.
IAM supports various grant types to get an OAuth token from the IAM authorization server. For additional information about supported grant types, see: Supported Access Grant Types.
Use the OAuth Access Token in Oracle Blockchain Platform REST API Requests
Authorization: Bearer <OAuth_access_token> in the request
header to call the REST
API.curl -i -X GET -H "Authorization: Bearer OAuth_access_token" "https://primary-audience/rest-endpoint-path"
The variables in the syntax have the following values:OAuth_access_tokenis the OAuth access token that you obtained.primary-audienceis the primary audience URL.rest-endpoint-pathis the relative path that defines the Oracle Blockchain Platform REST resource (note that the identity domain ID of Oracle Identity Cloud Service is used in the path).
curl -i -X GET -H "Authorization: Bearer <OAuth_access_token>" https://myobpinstance-mytenancy-iad.blockchain.ocp.oraclecloud.com:7443/restproxy/api/version"Authorization
Oracle Blockchain Platform REST proxy authorization
is based on application roles. The user who accesses the REST proxy must be assigned
the REST_CLIENT application role in the Oracle Blockchain Platform
instance application. When an OAuth access token is used for authentication, the
sub (subject) claim in the token is used as the user
name.
Note:
When Client Credentials Grant Type is used to get the access token, the client ID is put to the sub (subject) claim in the token. The authorization will fail unless an IDCS or IAM identity domain user with the same name as the client ID is created and assigned to the proper application role.