Authenticate with OAuth 2.0 authentication in Postman | Postman Learning Center (2024)

With OAuth 2.0, you first retrieve an access token for the API, then use that token to authenticate future requests. Access tokens are typically short-lived, but the authorization server can also provide a long-lived refresh token. A client application can use the refresh token to automatically refresh the access token.

OAuth 2.0 overview

Accessing data with OAuth 2.0 varies greatly between API service providers, but typically involves a few requests back and forth between client application, user, and API. An example OAuth 2.0 flow could run as follows:

  • A client application makes a request for the user to authorize access to their data.
  • If the user grants access, the application then requests an access token from the service provider, passing the access grant from the user and authentication details to identify the client.
  • The service provider validates these details and returns a short-lived access token and a long-lived refresh token.
  • The client uses the access token to request the user data with the service provider.
  • When the access token expires, the client can use the refresh token to automatically request a new access token.

Scheduled runs, monitors, the Postman CLI, and Newman don't support OAuth 2.0 authentication grant types that require user interaction, such as authorization code, to manually generate an access token. These Postman features are automated on the Postman cloud, meaning it isn't possible to manually generate an access token and later refresh it. Check with your API provider whether user interaction is required to generate an access token for your grant type.

Using OAuth 2.0

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. Specify if you want to pass the auth details in the request URL or headers.

    By default, Postman will append the access token to Bearer in the Authorization header for your request, but if your server implementation requires a different prefix, you can specify it in the Header Prefix field.

  2. To request an access token, fill out the fields in the Configure New Token section, and select Get New Access Token. To use the token with your request or collection, select Proceed and then select Use token. The details you used to generate the token are saved with your request or collection. You can also share the token so that others with access to the collection can use the token.

    Once you have a token value generated and added, it will appear in the request Headers.

  3. Enter the details for your client application, and any auth details from the service provider. This allows you to replicate your application auth flow inside Postman to test authenticated requests.

    You can share token credentials with your team. Turn on the Share token toggle and then select Sync Token. By default, Postman won't sync your token in case you don't want to share it.

  4. Postman will prompt you to supply specific details depending on the OAuth 2.0 Grant Type, which can be an authorization code, PKCE, implicit, password credentials, or client credentials.

Specifying an authorization code

Authorization code grant type requires the user to authenticate with the provider—an authorization code is then sent back to the client app, extracted, and exchanged with the provider for an access token to authenticate later requests.

To use authorization code grant type, enter a Callback URL for your client application (which needs to be registered with the API provider), together with various details provided by the API service including Auth URL, Access Token URL, Client ID, and Client Secret.

If you are using the Postman desktop app, you can enter your auth details in your web browser instead of in Postman by selecting Authorize using browser.

Specifying an authorization code with PKCE

You can use Proof Key for Code Exchange (PKCE) with OAuth 2.0. When you select Authorization Code (With PKCE), two more fields will become available for Code Challenge Method and Code Verifier. You can opt to use SHA-256 or Plain algorithms to generate the code challenge. The verifier is an optional 43-128 character string to connect the authorization request to the token request.

Authorization code (With PKCE) grant type coupled with Authorize using browser is recommended to prevent auth code interception attacks.

Using implicit grant type

Implicit grant type returns an access token to the client without requiring the extra auth code step (and is therefore less secure).

To use implicit grant type with your requests in Postman, enter a Callback URL you have registered with the API provider, the provider Auth URL, and a Client ID for the app you have registered.

If you are using the Postman desktop app, you can enter your auth details in your web browser instead of in Postman by selecting Authorize using browser.

Using password credentials

OAuth 2.0 Password grant type involves sending username and password directly from the client and is therefore not recommended if you're dealing with third-party data.

To use password grant type, enter your API provider's Access Token URL, together with the Username and Password. In some cases you will also need to provide a client ID and secret.

Using client credentials

Client credentials grant type is typically not used to access user data but instead for data associated with the client application.

Enter the provider's Access Token URL, together with the Client ID and Client Secret for your registered application.

Requesting an OAuth 2.0 token

The full list of parameters to request a new access token is as follows, depending on your grant type.

Under Configure New Token, enter details about the token:

  • Token Name - The name you want to use for the token.

  • Grant type - A dropdown list of options. This will depend on the API service provider requirements.

  • Callback URL - The client application callback URL to redirect to after auth. This must be registered with the API provider. If not provided, Postman will use a default empty URL and try to extract the code or access token from it. If this doesn't work for your API, you can use the following URL: https://oauth.pstmn.io/v1/browser-callback

    If you are using the Postman desktop app, you can enter your auth details in your web browser instead of in Postman by selecting Authorize using browser. When using the Authorization Code or Implicit grant type, select this checkbox to set the Callback URL to return to Postman. If you opt to authorize using your browser, make sure pop-ups are deactivated for the callback URL, otherwise the option won't work.

  • Auth URL - The endpoint for the API provider authorization server, to retrieve the auth code.

  • Access Token URL - The provider's authentication server, to exchange an authorization code for an access token.

  • Client ID - The ID for your client application registered with the API provider.

  • Client Secret - The client secret given to you by the API provider.

  • Scope - The scope of access you are requesting, which may include multiple space-separated values.

  • State - An opaque value to prevent cross-site request forgery.

  • Client Authentication - Send a Basic Auth request in the header, or client credentials in the request body. After upgrading to a new version, change the value here to avoid problems with client authentication.

To customize the token, select Advanced Options:

  • Refresh Token URL - The endpoint for the refresh server, to exchange the refresh token for an access token. If empty, the refresh token URL will be the same as the access token URL.

  • Auth Request, Token Request, and Refresh Request - Define any custom parameters you want to send with auth requests, token requests, or refresh requests. For each key-value pair you define, select an option to send the parameter in the request body, request URL, or request headers. Keep in mind the following considerations:

    • If you add multiple keys with same key name, they will be sent with the request as an array.
    • If you added resource or audience URIs in an earlier version of Postman, you can import them as custom parameters. Select the Audience and Resource tab to review the resources and audiences, then select Move Audience and Resource. For all grant types except implicit, the parameters are added to the token request. For implicit grant types, the parameters are added to the auth request.

When the configuration is complete, select Get New Access Token. The configuration information is saved along with the access token and will be used every time the token is refreshed.

When you use Authorization Code or Implicit grant type, you will be prompted to supply your credentials to retrieve an access token to use in later requests. By default, Postman will display a pop-up window when you select Request Token. If you are using the Postman desktop app, you can instead choose to authenticate using your system's default web browser. Select Authorize using browser to set the Callback URL to return to Postman after you complete auth in the browser, so that your requests can use the token returned on successful authentication.

A token from the API includes its details, together with the expiration, and optionally a refresh token you can use to retrieve a new access token when your current one expires. Select Proceed and then select Use Token to use the returned token.

Any successfully retrieved tokens will be listed in the request Available Tokens dropdown list. Select one to send with your request. Select Manage Tokens in the dropdown list to view more details or delete your tokens.

If authentication fails or times out, Postman will display an error message. You can check the error details in the Postman Console, Retry to try authentication again, or edit your auth details before continuing.

Deleting a token in Postman doesn't revoke access. Only the server that issues the token can revoke it.

Refreshing an OAuth 2.0 token

Before an OAuth 2.0 token generated in Postman expires, Postman automatically refreshes it in the background before you send a request that uses it. The refreshed access token is updated in any requests that it's used in. If you added any custom parameters when generating the token, those parameters will also be used for the refreshed token.

Auto-refreshing is the default behavior. To turn this feature off or on, select Auto-refresh access token. To manually refresh a token, select Refresh. The token's expiration time displays if the token expires within the next day.

Auto-refresh is available when a refresh token is present. If no refresh token is present, the Auto-refresh access token toggle and the manual Refresh option aren't available. To check if a refresh token is present, select Manage Tokens in the Token dropdown list. If a refresh token is not present, check with the authorization service. Postman can't refresh the access tokens without the refresh token.

Authenticate with OAuth 2.0 authentication in Postman | Postman Learning Center (1)

You can use auto-refresh when manually sending the request. Auto-refresh isn't supported for scheduled runs, monitors, the Postman CLI, or Newman.

Sharing an OAuth 2.0 access token

To enable other Postman users to view and use an OAuth 2.0 access token, select Share access token.

Authenticate with OAuth 2.0 authentication in Postman | Postman Learning Center (2)

To revoke other users' access to a synced token, do the following:

  1. Turn Share access token off.
  2. Select Remove Synced Token.

After you revoke access, other users with access to the request won't be able to see or use the token.

Changing the OAuth 2.0 token type

Postman supports using access tokens or ID tokens for OAuth 2.0 authorization. An access token enables an OAuth client to make calls to an API. An ID token has information about the authenticated user. This information can be used by an OAuth client to customize their experience.

If an ID token is present, you can select the token type (Access token or ID token) in the Use Token Type dropdown list. If no ID token is present, this dropdown list isn't available. To check if an ID token is present, select Manage Tokens in the Token dropdown list.

Authenticate with OAuth 2.0 authentication in Postman | Postman Learning Center (3)

Authenticate with OAuth 2.0 authentication in Postman | Postman Learning Center (2024)

FAQs

How to automate OAuth 2.0 in Postman? ›

How to Set up and Test OAuth2 in Postman?
  1. Select "OAuth 2.0" as the type of authorization.
  2. Click on the "Configure New Token" button.
  3. Click on the "Get New Access Token" button.
  4. If the authorization is successful, the access token will be displayed in the "Access Token" field.
Jun 19, 2024

How to provide authentication credentials in Postman? ›

Basic authentication involves sending a verified username and password with your request. In the request Authorization tab, select Basic Auth from the Auth Type dropdown list. Enter your API username and password in the Username and Password fields. For extra security, store these in variables.

Can OAuth 2.0 be used for authentication? ›

OAuth 2.0 is an authorization protocol and NOT an authentication protocol. As such, it is designed primarily as a means of granting access to a set of resources, for example, remote APIs or user data.

What is the difference between OAuth 1.0 and OAuth 2.0 in Postman? ›

OAuth 1.0 only handled web workflows, but OAuth 2.0 considers non-web clients as well. Better separation of duties. Handling resource requests and handling user authorization can be decoupled in OAuth 2.0. Basic signature workflow.

How do I automatically authenticate in Postman? ›

How to Automate Your Authentication Flow in Postman
  1. Set Collection and Global Variables. ...
  2. Use the Pre-Request Script Tab. ...
  3. Set Your Authentication Headers. ...
  4. Test Your Requests. ...
  5. 17 Mindblowing Python Automation Scripts I Use Everyday.
Feb 11, 2023

How to implement OAuth 2.0 protocol? ›

How To Implement OAUTH2 Protocol Into Your Application? Frontend
  1. Obtain credentials. To begin with OAuth 2.0 implementation, you would need to get some data from your authentication provider. ...
  2. Set up the project for the authentication server. ...
  3. Install dependencies (Passport. ...
  4. Configure Express. ...
  5. Initialize Passport.
Jan 17, 2024

How to pass an auth token in Postman? ›

Here's a step-by-step guide on how to do this:
  1. Create a Request in Postman. Open a new or existing request in Postman. ...
  2. Select Authorization Type. In the request pane, go to the "Authorization" tab. ...
  3. Enter Token. ...
  4. Send the Request: ...
  5. Review the Response:

How to do authentication in rest API? ›

  1. #1 API Key (identification only) One of the easiest ways to identify an API client is by using an API key. ...
  2. #2 OAuth2 token. OAuth2 is a comprehensive industry standard that is widely used across API providers. ...
  3. #3 External token or assertion. ...
  4. #4 Token Exchange. ...
  5. #5 Identity facade for 3 legged OAuth.
Feb 9, 2023

How to call rest API with OAuth token? ›

Using OAuth 2 to Access the REST API
  1. Step 1: Register a Confidential Application in Identity Domains Using the Console.
  2. Step 2: Base64 Encode the Client ID and Client Secret.
  3. Step 3: Obtain an Access Token.
  4. Step 4: Make a REST Request to the Environment.
Aug 30, 2024

How do you use OAuth and OAuth2 authentication mechanisms? ›

For the Authorization Code grant, use response_type=code to include the authorization code. For the Implicit grant, use response_type=token to include an access token. An alternative is to use response_type=id_token token to include both an access token and an ID token .

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

OAuth2 is not an authentication (login) protocol!

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.

How does OAuth 2.0 work in Postman? ›

With OAuth 2.0, you first retrieve an access token for the API, then use that token to authenticate future requests. Access tokens are typically short-lived, but the authorization server can also provide a long-lived refresh token.

What authentication is supported by Postman? ›

In Postman, authorizations authenticate API requests with various methods like API Keys, Basic Authentication (username/password in Base64), Bearer Tokens, and OAuth 1.0/2.0. API Keys are included in headers or parameters, while Basic Authentication encodes credentials.

How to add basic auth in Postman? ›

To set up authentication for your public APIs, go to the API authorization dashboard. Select Team > Team Settings in the Postman header, then select Set up API authorization in the left sidebar. Postman supports Bearer Token, Basic Auth, API Key, and OAuth 2.0 authorization.

How to automate oauth2 token? ›

How to automate OAuth token generation without browser intervention?
  1. You have to generate grant code using /oauth/v2/auth API.
  2. In /oauth/v2/auth by default, access_type will be online. ...
  3. Save the created refresh token in your side. ...
  4. Once the access token expires you can regenerate them using refresh tokens automatically.

Can you automate with Postman? ›

Postman simplifies automated testing

Postman offers a comprehensive API testing tool that makes it easy to set up automated tests. You can aggregate the tests and requests you've created into a single automated test sequence.

How to automate the process of getting an access token? ›

You can automate the whole process:
  1. Make a POST request to get the access token.
  2. Use a Property Transfer test step to assign the token value to a project property (e.g. myProperty).
  3. Use the project property in your requests as: ${#Project#myProperty}
Mar 13, 2017

Top Articles
1984 | Timeline of Computer History
Securities And Futures Commission (SFC) | LeapXpert
Is Paige Vanzant Related To Ronnie Van Zant
Hotels
Dlnet Retiree Login
5 Bijwerkingen van zwemmen in een zwembad met te veel chloor - Bereik uw gezondheidsdoelen met praktische hulpmiddelen voor eten en fitness, deskundige bronnen en een betrokken gemeenschap.
Pike County Buy Sale And Trade
Waive Upgrade Fee
Geometry Escape Challenge A Answer Key
PGA of America leaving Palm Beach Gardens for Frisco, Texas
Myql Loan Login
Qhc Learning
Miami Valley Hospital Central Scheduling
Tracking Your Shipments with Maher Terminal
Mineral Wells Independent School District
Houses and Apartments For Rent in Maastricht
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Commodore Beach Club Live Cam
Air Force Chief Results
The Menu Showtimes Near Regal Edwards Ontario Mountain Village
Tyler Sis University City
Great Clips Grandview Station Marion Reviews
Sam's Club Gas Price Hilliard
480-467-2273
Water Temperature Robert Moses
Cona Physical Therapy
Transformers Movie Wiki
Word Trip Level 359
Appleton Post Crescent Today's Obituaries
Wednesday Morning Gifs
AI-Powered Free Online Flashcards for Studying | Kahoot!
Anya Banerjee Feet
The Holdovers Showtimes Near Regal Huebner Oaks
Miracle Shoes Ff6
Indiana Jones 5 Showtimes Near Cinemark Stroud Mall And Xd
Dee Dee Blanchard Crime Scene Photos
Japanese Big Natural Boobs
Mid America Irish Dance Voy
manhattan cars & trucks - by owner - craigslist
Cuckold Gonewildaudio
boston furniture "patio" - craigslist
Studentvue Calexico
Theater X Orange Heights Florida
Theater X Orange Heights Florida
Okta Login Nordstrom
German American Bank Owenton Ky
Mytmoclaim Tracking
Unpleasant Realities Nyt
Research Tome Neltharus
786 Area Code -Get a Local Phone Number For Miami, Florida
How To Win The Race In Sneaky Sasquatch
Nfl Espn Expert Picks 2023
Latest Posts
Article information

Author: Van Hayes

Last Updated:

Views: 6636

Rating: 4.6 / 5 (46 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Van Hayes

Birthday: 1994-06-07

Address: 2004 Kling Rapid, New Destiny, MT 64658-2367

Phone: +512425013758

Job: National Farming Director

Hobby: Reading, Polo, Genealogy, amateur radio, Scouting, Stand-up comedy, Cryptography

Introduction: My name is Van Hayes, I am a thankful, friendly, smiling, calm, powerful, fine, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.