cancel
Showing results for 
Search instead for 
Did you mean: 

Oauth Call using Authorization Code Grant type

TusharVarshney
Level 5

Hi Guys, 

Has anyone come across any API integration which uses Oauth2.0 authentication and grant_type = authorization_code. also, how to retrieve Token by on behalf of call. any Postman sample or any BP example would be appreciated. 

Tushar Varshney Senior Consultant - Intelligent Automation Ernst & Young India +91-9880188366
2 REPLIES 2

Good Morning Tushar,

Certainly, OAuth 2.0 with the `authorization_code` grant type is a common authentication mechanism for API integrations. This flow is often used for securely authorizing third-party applications to access a user's data on their behalf.
 
Here's a step-by-step guide on how to perform OAuth 2.0 authorization code flow and retrieve a token using Postman:
 
**Step 1: Set Up Your OAuth 2.0 Application**
 
Before integrating an API with OAuth 2.0, you must set up an OAuth 2.0 application with the provider. This typically involves registering your application and obtaining a client ID and secret.
 
**Step 2: Configure Postman**
 
1. Open Postman and create a new request.
 
2. Go to the "Authorization" tab in the request configuration.
 
3. Select "OAuth 2.0" as the type.
 
4. Click on the "Get New Access Token" button.
 
5. Fill in the OAuth 2.0 details:
 
   - **Token Name**: A name for the token (can be anything).
   - **Grant Type**: Select "Authorization Code" since you want to use the authorization code flow.
   - **Callback URL**: The callback URL you've registered with your OAuth provider.
   - **Auth URL**: The OAuth provider's authorization URL.
   - **Access Token URL**: The OAuth provider's token endpoint URL.
   - **Client ID**: The client ID you obtained during the application setup.
   - **Client Secret**: The client secret you obtained during the application setup.
   - **Scope**: The permissions you request (if applicable).
   - **Client Authentication**: Typically, "Send client credentials in body."
 
6. Click "Request Token" to initiate the OAuth flow.
 
7. Postman will open a web view for you to log in to the OAuth provider and authorize your application.
 
8. Once you've authorized the application, you will be redirected to the callback URL, and Postman will automatically retrieve the authorization code and exchange it for an access token.
 
9. You should now have an access token available in the "Access Token" field in your Postman request.
 
**Step 3: Make API Requests**
 
With the access token obtained in Step 2, you can now make API requests on behalf of the user. Add the access token to the request headers, typically in the "Authorization" header, as "Bearer [access_token]."
 
Here's a basic example of how a Postman request might look after obtaining the access token:
 
Authorization: Bearer [your_access_token]
 
Please note that the specific details, endpoints, and configuration may vary depending on the OAuth provider and the API you are integrating with. Be sure to refer to the documentation provided by your OAuth provider for accurate configuration details.
 
Always handle access tokens securely, and consider implementing token refresh logic, as access tokens may expire after a certain period.

TusharVarshney
Level 5

Thanks @Angelo.Carcagno.  is it also possible to provide Azure user credential in the request itself to avoid the browser login. if yes, How.

Tushar Varshney Senior Consultant - Intelligent Automation Ernst & Young India +91-9880188366