Using OAuth 2 to Access the REST API (2024)

The identity domains REST API supports SCIM 2.0 compliant endpoints with standard SCIM 2.0 core schemas and Oracle schema extensions to programmatically manage users, groups, applications, and identity functions, such as password management and administrative tasks. To make REST API calls to your identity domain, you need an OAuth2 access token to use for authorization. The access token provides a session (with scope and expiration), that your client application can use to perform tasks in an identity domain.

The following sections walk you through the steps required to use an OAuth client with an identity domain to access the REST APIs:

  • Step 1: Register a Confidential Application in Identity Domains Using the Console

  • Step 2: Base64 Encode the Client ID and Client Secret

  • Step 3: Obtain an Access Token

  • Step 4: Make a REST Request to the Environment

The following sequence diagram illustrates a basic example of the OAuth 2.0 authorization flow to access the identity domains REST API.

Using OAuth 2 to Access the REST API (1)

Use specific OAuth 2.0 parameters when working with an identity domain. The following table describes the most common parameters.

ParameterValueComments

Authorization Header

Basic <base64_clientid_secret>

Used by the client as a Basic authentication scheme to transmit the access token in a header. The access token value needs to be a base64 UTF-8 encoded value of the Client ID and Client Secret concatenated using a colon as a separator-for example, clientID:clientSecret.

Client ID

<client_id>

Required. A unique "API Key" that's generated when you register your application in the identity domain Console.

Client Secret

<client_secret>

Required. A private key similar to a password that's generated when you register your application in the identity domain Console. Don't share this value.

Access Token URL

/oauth2/v1/token

An endpoint used to obtain an access token from the identity domain.

Auth URL

/oauth2/v1/authorize

An endpoint used to obtain an authorization code from identity domains, and then used during a 3-legged OAuth flow.

Grant Type

client_credentials

Required. It means the REST API that's invoked is owned by the client application.

Scope (required)

urn:opc:idm:__myscopes__

This scope returns all the grants given to your application, other scopes could be used to get specific grants, if necessary.

Step 1: Register a Confidential Application in Identity Domains Using the Console

When you register a confidential application in the identity domain Console, you obtain some of the key parameters that you need to work with OAuth 2.0: Client ID, Client Secret, and Scopes. OAuth 2.0 is a standard for implementing delegated authorization, and authorization is based on the access token required to access a resource. The access token can be issued for a given scope, which defines what the access token can do and what resources it can access. When you register a web application in an identity domain, you add scopes. In the following example, the required scopes to request User searches, edits, creates, and deletes are added. But, if you were to do other things-for example, manage Audit Events, that would require other scopes.

To create and register a confidential application access the OCIConsole and then complete the following steps:

  1. Open the navigation menu and click Identity & Security. Under Identity, click Domains.
  2. Click the name of the identity domain that you want to work in. You might need to change the compartment to find the domain that you want. Then, click Integrated applications.
  3. Click Add application.
  4. In the Add application dialog box, select Confidential Application, and then click Launch workflow.
  5. On the Add application details page, enter an application name and description, and then click Next.
  6. On the Configure OAuth page, under Client configuration, select Configure this application as a client now.
  7. Under Authorization, select only Client Credentials as the Allowed Grant Type.
  8. At the bottom of the page, select Add app roles and then click Add roles.
  9. In the Add app roles panel, select Identity Domain Administrator, and then click Add.
  10. Click Next and then click Finish.
  11. On the application detail page, scroll down to General Information. Copy the Client ID and the Client Secret and store it in a safe place.
  12. After the application is created, click Activate.

Step 2: Base64 Encode the Client ID and Client Secret

You must encode the client ID and client secret when you include it in a request for an access token.

Note

Before base64 encoding, individually URL encode the client ID and the client secret. If your client ID and client secret don't contain special characters, you aren't required to URL encode them first. However, as a best practice, we highly recommend it.

The following sections show you how to base64 encode the client ID and client secret in UTF-8 format using a Windows and a Mac/Linux environment.

Windows

  1. Launch Notepad, and then paste the client ID and client secret into Notepad.

  2. Place the client ID and client secret on the same line and insert a colon between them: clientid:clientsecret

    Note

    Ensure that no spaces are the clientid:clientsecret attribute.

  3. Save the file to C:\temp and name the file appCreds.txt.

  4. In Windows Explorer, right-click C:\temp, and then select CMD Prompt Here from the context menu.

  5. Enter the following command to encode the client ID and client secret:

    certutil -encode appCreds.txt appbase64Creds.txt
  6. In Notepad, open C:\temp\appbase64Creds.txt, copy its contents, and then close the file.

    Note

    For security reasons, delete the appCreds.txt and the appbase64Creds.txt files after you finish.

Mac and Linux

  1. Launch your preferred note utility (for example, Mac Notes, Gedit Linux, or Vi), and then paste the client ID and client secret into the note utility.

  2. Place the client ID and client secret on the same line and insert a colon between them: clientid:clientsecret.

    Note

    Ensure no spaces in the clientid:clientsecret.

    statement.
  3. Copy the clientid:clientsecret line.

  4. Launch a terminal and enter the following command, replacing clientid:clientsecret with the value that you copied to the clipboard.

    echo -n "clientid:clientsecret" | base64 -w 0

    Note

    For Linux, add -w 0 to the command to remove line breaks.

  5. Copy the value that's returned.

    Note

    If the value that's returned is broken into more than one line, return to your text editor and ensure the entire results are on a single line with no text wrapping.

Step 3: Obtain an Access Token

The next step in this process is to request the access token.

  1. Launch a command prompt.

  2. Enter the cURL command below, replacing the text in brackets ( < > ) with the appropriate values:

     curl -i -H "Authorization: Basic <base64encoded clientid:secret>" -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" --request POST https://<domainURL>/oauth2/v1/token -d "grant_type=client_credentials&scope=urn:opc:idm:__myscopes__"

    Note

    If you're using a UNIX OS, you can append | awk -F"\"" '{print $4}' to the end of the cURL command to parse out just the Bearer token. Just remember that the default expiration of the token is 3600 seconds from the time of the request.

    Note

    Optionally, run the following cURL command to have the access token value accessible through a UNIX variable called AccessTokenValue in your environment:

     export AccessTokenValue=`curl -i -H "Authorization: Basic <base64encoded clientid:secret>" -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" --request POST https://<domainURL>/oauth2/v1/token -d "grant_type=client_credentials&scope=urn:opc:idm:__myscopes__" | awk -F"\"" '{print $4}' | tail -n +16`

    You can then run echo $AccessTokenValue command to get the access token value.

    Text in BracketsValue
    base64encoded clientid:secretReplace with the encoded credentials that you generated in the Base64 Encode the client ID and client secret section. Ensure no spaces in the clientid:clientsecret credentials.
    IDCS_Service_InstanceReplace with your identity domain URL (for example, https://<domainURL>/).

    Note

    The urn:opc:idm:__myscopes__ scope in the command is used as a tag by identity domain clients requesting access tokens from the OAuth authorization server. Access tokens are returned that contain all applicable identity domains scopes based on the privileges represented by the identity domains administrator roles granted to the requesting client and the user being specified by the client's request (if present). This scope isn't granted directly to any identity domains administrator role.

  3. Copy the access_token value from the response. Ensure to copy only the actual token, which is the access_token value between the quotation marks:

    Status: 200"access_token":"eyJ4NXQiOiI4Wk. . .""token":"Bearer","expires_in":3600

    Note

    The response includes the expires_in: 3600 parameter. This means that your token is no longer valid after one hour from the time that you generate it. After one hour, you must refresh the token or get a new access token.

Step 4: Make a REST Request to the Environment

After you obtain the OAuth 2.0 access token, you can use the token in a cURL command to send a REST request to the identity domains REST API. The following command returns a list of users in an identity domain.

 curl -X GET -H "Content-Type:application/scim+json" -H "Authorization: Bearer <access_token>" https://<domainURL>admin/v1/Users
ItemValue
Method-X GET
Content Type Header-H "Content-Type:application/scim-json"
Authorization Header-H "Authorization: Bearer <access_token>"
HTTP ProtocolHTTP or HTTPS (HTTP is recommended)
Identity DomainThe identity domain URL (for example, https://<domainURL>).
Identity Domains REST Endpoint/admin/v1/Users

Example JSON Output from the Identity Domains REST API

In the previous step, the REST request sent using cURL returned a response in JSON format. JSON is an open standard that can be formatted or parsed per your needs such as getting specific attributes required by your application.

{ "schemas": [ "urn:scim:api:messages:2.0:ListResponse" ], "totalResults": 1, "Resources": [ { "displayName": "admin opc", "name": { "givenName": "admin", "formatted": "admin opc", "familyName": "opc" }, "urn:ietf:params:scim:schemas:oracle:idcs:extension:userState:User": { "locked": { "on": false } }, "userName": "admin@example.com", "id": "d252a54d83c344eb8f59f7053a0562ce", "urn:ietf:params:scim:schemas:oracle:idcs:extension:user:User": { "isFederatedUser": false }, "active": true, "nickName": "TAS_TENANT_ADMIN_USER", "emails": [ { "verified": false, "value": "admin@example.com", "type": "work", "primary": true }, { "verified": false, "value": "admin@example.com", "primary": false, "type": "recovery" } ], "schemas": [ "urn:ietf:params:scim:schemas:oracle:idcs:extension:user:User", "urn:ietf:params:scim:schemas:oracle:idcs:extension:userState:User", "urn:ietf:params:scim:schemas:core:2.0:User" ], "meta": { "resourceType": "User", "created": "2022-07-22T18:11:08Z", "lastModified": "2022-07-25T21:19:28Z", "location": "https://<domainURL>admin/v1/Users/d252a54d83c344eb8f59f7053a0562ce" }, "idcsLastModifiedBy": { "value": "idcssso", "$ref": "https://<domainURL>admin/v1/Apps/idcssso", "type": "App", "display": "idcssso" } } ], "startIndex": 1, "itemsPerPage": 50}
Using OAuth 2 to Access the REST API (2024)

FAQs

How does OAuth 2.0 work in the rest API? ›

OAuth 2.0 is a standard for implementing delegated authorization, and authorization is based on the access token required to access a resource. The access token can be issued for a given scope, which defines what the access token can do and what resources it can access.

How to consume API with OAuth2? ›

To set the OAuth 2.0 authentication for the REST API you are consuming, open the Headers and Authentication tab and then from the Authentication list, select OAuth 2.0: client credentials. To authenticate the app, enter the client credentials in the Client ID and Client secret fields.

How to implement OAuth2 to an API? ›

Basic steps
  1. Obtain OAuth 2.0 credentials from the Google API Console. ...
  2. Obtain an access token from the Google Authorization Server. ...
  3. Examine scopes of access granted by the user. ...
  4. Send the access token to an API. ...
  5. Refresh the access token, if necessary.
Jul 16, 2024

How do I call REST API with authentication? ›

To access the API endpoint, the user must send a username and password to the API provider in the authentication header of the request. The API provider checks the credentials and, in the case of success, grants access to the user.

Why is it a bad idea to use OAuth 2.0 for authentication? ›

The purpose of OAuth2 Tokens is to authorize requests at a first-party server (or API). If the third party uses the OAuth2 Access Token as proof of authentication, an attacker could easily impersonate a legitimate user.

What is the difference between oauth1 and OAuth2 in REST API? ›

OAuth 1.0 needs to generate a signature on every API call to the server resource and that should be matched with the signature generated at the receiving endpoint in order to have access for the client. OAuth 2.0 do not need to generate signatures. It uses TLS/SSL (HTTPS) for communication.

How to use OAuth 2.0 in Postman? ›

To use OAuth 2.0, do the following:
  1. In the Authorization tab for a collection or request, select OAuth 2.0 from the Auth Type dropdown list. ...
  2. To request an access token, fill out the fields in the Configure New Token section, and select Get New Access Token.
Jul 23, 2024

Why is OAuth better than basic authentication? ›

Enhanced Security: OAuth does not require users to provide their credentials directly to third parties, significantly reducing the risk of credential exposure. Delegated Access: Users can grant limited access to their data without sharing their full access rights, maintaining greater control over their information.

What is the difference between API and OAuth2? ›

API keys can be an easy way to enforce some authentication, while OAuth is more sophisticated with more options. Here are some of the benefits of OAuth2 over the API key: Access token is tied to a specific user, not an app.

How to use OAuth2 for authentication? ›

Authenticate using OAuth 2.0
  1. An application requests authorization on a user's behalf.
  2. The application obtains a Grant Token.
  3. The client requests an access token by using the Grant Token.
  4. The authorization server validates the Grant Token and issues an Access Token and a Refresh Token.

What is the difference between OAuth and JWT? ›

JWT token vs oauth token: JWT defines a token format while OAuth deals in defining authorization protocols. JWT is simple and easy to learn from the initial stage while OAuth is complex. OAuth uses both client-side and server-side storage while JWT must use only client-side storage. JWT has limited scope and use cases.

How to use OAuth 2.0 for REST API calls in PHP? ›

Prerequisites
  1. Enable APIs for your project.
  2. Create authorization credentials.
  3. Identify access scopes.
  4. Language-specific requirements.
  5. Step 1: Set authorization parameters.
  6. Step 2: Redirect to Google's OAuth 2.0 server.
  7. Step 3: Google prompts user for consent.
  8. Step 4: Handle the OAuth 2.0 server response.

How does OAuth 2.0 work in Rest API? ›

OAuth 2.0 is the industry-standard protocol for authorization. OAuth 2.0 focuses on client developer simplicity while providing specific authorization flows for web applications, desktop applications, mobile phones, and living room devices.

How do I call REST API? ›

Calling REST APIs
  1. Add a Datasource with OpenAPI specification. Datasource for REST service without OpenAPI specification.
  2. Add a service. Define the methods that map to the operations.
  3. Add a Controller. Inject the Service in the constructor. Add the REST endpoints.
  4. More examples.
  5. Further reading.

How to add Basic Authentication to rest API? ›

Procedure
  1. Concatenate the user name with a colon, and the password. ...
  2. Encode this user name and password string in base64 encoding.
  3. Include this encoded user name and password in an HTTP Authorization: Basic header.

What is OAuth 2.0 authentication and how does it work? ›

OAuth 2.0, which stands for “Open Authorization”, is a standard designed to allow a website or application to access resources hosted by other web apps on behalf of a user. It replaced OAuth 1.0 in 2012 and is now the de facto industry standard for online authorization.

How does token based authentication work in REST API? ›

Token based authentication works by ensuring that each request to a server is accompanied by a signed token which the server verifies for authenticity and only then responds to the request.

How basic authentication works in REST API? ›

Users of the REST API can authenticate by providing their user ID and password within an HTTP header. To use this method of authentication with HTTP methods, such as POST, PATCH, and DELETE, the ibm-mq-rest-csrf-token HTTP header must also be provided, as well as a user ID and password.

Top Articles
7 Smart Stocks to Buy for Your Children's Portfolio
Best Heroes in Lords Mobile - Marks Angry Review
SZA: Weinen und töten und alles dazwischen
Public Opinion Obituaries Chambersburg Pa
The UPS Store | Ship & Print Here > 400 West Broadway
Breaded Mushrooms
Unblocked Games Premium Worlds Hardest Game
Evita Role Wsj Crossword Clue
Joe Gorga Zodiac Sign
Audrey Boustani Age
Breakroom Bw
Hood County Buy Sell And Trade
Craiglist Galveston
Georgia Vehicle Registration Fees Calculator
How Much You Should Be Tipping For Beauty Services - American Beauty Institute
Farmer's Almanac 2 Month Free Forecast
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
Viha Email Login
Blue Rain Lubbock
Tips on How to Make Dutch Friends & Cultural Norms
Wemod Vampire Survivors
Rs3 Ushabti
Yugen Manga Jinx Cap 19
eugene bicycles - craigslist
Bayard Martensen
Gopher Hockey Forum
Select The Best Reagents For The Reaction Below.
Elijah Streams Videos
FSA Award Package
25Cc To Tbsp
Rlcraft Toolbelt
Of An Age Showtimes Near Alamo Drafthouse Sloans Lake
Polk County Released Inmates
2024 Ford Bronco Sport for sale - McDonough, GA - craigslist
Domina Scarlett Ct
Build-A-Team: Putting together the best Cathedral basketball team
Robeson County Mugshots 2022
Academic important dates - University of Victoria
Skill Boss Guru
Ramsey County Recordease
LoL Lore: Die Story von Caitlyn, dem Sheriff von Piltover
Quaally.shop
Tom Kha Gai Soup Near Me
Unblocked Games - Gun Mayhem
Strange World Showtimes Near Marcus La Crosse Cinema
Skyward Login Wylie Isd
Marion City Wide Garage Sale 2023
Tamilblasters.wu
Affidea ExpressCare - Affidea Ireland
Latest Posts
Article information

Author: Duane Harber

Last Updated:

Views: 6500

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Duane Harber

Birthday: 1999-10-17

Address: Apt. 404 9899 Magnolia Roads, Port Royceville, ID 78186

Phone: +186911129794335

Job: Human Hospitality Planner

Hobby: Listening to music, Orienteering, Knapping, Dance, Mountain biking, Fishing, Pottery

Introduction: My name is Duane Harber, I am a modern, clever, handsome, fair, agreeable, inexpensive, beautiful person who loves writing and wants to share my knowledge and understanding with you.