3.1.7.6 Generate Access Token to Execute a Public RESTful API
You can generate access token using TLS to execute a public RESTful API.
Prerequisite: Organization-wide ca.crt,
client.crt, and client.key (you can generate
client.crt and client.key using
openssl.)
Create a client.crt
using openssl
openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 -out ca.crtCreate a client.key using
openssl
openssl genrsa -out client.key 2048- Log in to Admin Console.
- Under Domains, go to Integrated Applications.
- Create a confidential application with an app name. Example: TLS_APP_<tenant.
- After creating the application, edit the OAuth configuration as follows:
- Under the Client configuration, Select "Configure this application as a client now"
- Enable the below Auth grant types( TLS should be checked for TLS authorization )
- Enable Allow non-HTTPS URLs
- Add the redirect URL: http://%hostid%/cloudgate/v1/oauth2/callback
- Add the Logout URL: http://%hostid%/cloudgate/v1/oauth2/logout
- Set the client type as "Confidential"
- Under Certificate file, import the
client.crtgenerated earlier. - Click Submit.
- Import the following Webtier
policy:
{ "cloudgatePolicy": { "version": "2.6", "requireSecureCookies": true, "disableAuthorize": false, "allowCors": true, "webtierPolicy": [ { "policyName": "default", "comment": "", "resourceFilters": [ { "filter": "/.*", "comment": "Protect all resources", "type": "regex", "method": "oauth", "headers": [ { "user_groups": "$subject.user.groups" }, { "ofs_remote_user": "$subject.user.userName" }, { "ofs_remote_username": "$subject.user.name" }, { "ofs_mapped_groups": "$subject.user.groups" }, { "ofs_remote_user_email": "$subject.user.emails" } ], "authorize": false } ] } ] } } - Activate the application.
Creating custom scopes for the Integrated Application (Optional)
- Under Resource Server Configuration, select "Configure this application as a resource server now".
- Set the access token expiration.
- Set the primary audience.
- Under the Scopes, click Add.
- Under Add Scope, provide the following details:
- Scope:
urn:app:tls.testNote: Should begin withurnand delimited by ":"(colon)). - Display name: Custom scope.
- Click Add.
- Scope:
- Click Submit.
- Get the IDCS Host URL from the domain.
- Click on the URL to get the IDCS configuration details.
Example:
https://idcs-8523776c08804de1b5613af6d662f94e.identity.oraclecloud.com:443/.well-known/idcs-configuration - Search for "secure_token_endpoint" to get the secure token endpoint.
Example:
https://idcs-8523776c08804de1b5613af6d662f94e.us-ashburn-idcs-1.secure.identity.oraclecloud.com/oauth2/v1/token - In the Postman, paste the
secure_token_endpointin the address bar as follows:- Method: POST
- Body:
- grant_type: tls_client_auth
- scope: urn:opc:idm:__myscopes__ # if the custom scope is required, the change the scope to <primary_audience><new_scope>
- client_id: caf14860726e48a18b76b80704987285 #(Client ID from the above generated app)
- Content-type:
x-www-form-urlencodedas header. - For custom scope, provide the details as follows:
- grant_type: tls_client_auth
- scope: urn:app:tls.auth.test
- client_id: ecccdd63304a4483a9f2bb8e1fdfe45a
- Click on postman settings and navigate to certificates tab.
- Enable the CA certificates and upload the ca.crt under the PEM file
- Click Add Certificate.
- Paste the IDCS host URL of the
secure_token_endpointunder the Host column - Upload the cert and key file downloaded from openSSL.
- Click the Add button to add the certificates and close the dialog box.
- Select No Auth for Authorization.
- Click the Send button to get the token,
- Paste the endpoint in the address bar with appropriate method type.
- On the Authorization tab, select Auth type as "Bearer token" and paste the token generated.
- In Headers column, set the header as
X-Forwarded-Tls-Client-Cert: <url_encoded_client_crt>- Only encode the cert part excluding the --Begin – and – end – from the certificate.
- For the cert url, encode - https://www.urlencoder.org/
- Click Send for the response.
Invoke the API through the Access Token using TLS
To invoke the API through the generated Access Token using TLS, refer to the following example executed using cURL Commands in the CLI Tool: