Configuring OAUTH2 Inside of Postman in IAP Service Accounts
  • 02 May 2024
  • Dark
    Light
  • PDF

Configuring OAUTH2 Inside of Postman in IAP Service Accounts

  • Dark
    Light
  • PDF

Article Summary

This article gives step-by-step instructions on how to configure OAUTH2 inside of Postman in IAP Service Accounts. This guide is designed to help users wanting to take advantage of OAUTH2 capabilities inside of IAP2023.1 when issuing a client_id and client_secret and then using the returned token, but inside of Postman.

How to Setup OAUTH2 Inside of Postman via Pre-Request Script

  1. Add the pre-request script below into Postman and replace the IAP address, client_id and client_secret with your defined information.

    const postRequest = {
      url: '<https://YOURIAPADDRESS:3443/oauth/token>',
      method: 'POST',
      timeout: 0,
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    body: {
      mode: 'urlencoded',
      urlencoded: [
        {key: 'client_id', value: 'YOURDEFINEDCLIENTID'},
        {key: 'client_secret', value: 'YOURDEFINEDCLIENTSECRET'},
        {key: 'grant_type', value: 'client_credentials'},
      ]}
    };
    pm.sendRequest(postRequest, function (err, res) {
      var responseJson = res.json();
      console.log(responseJson.access_token);
      pm.globals.set('authToken', responseJson.access_token);
    });
    
  2. Select Bearer Token as the Auth type and add the variable as shown in Figure 1.

    Figure 1

    Postman Pre-Request

  3. Once the variable is added you will be able to issue API calls to IAP using OAUTH2, all without username/password.

How to Setup OAUTH2 Inside of Postman Using Curl

You can also setup OAUTH2 inside of Postman using Curl.

  1. Add the following curl command into Postman.

    curl --location 'http://10.91.151.21/oauth/token' \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'client_id=*****' \
    --data-urlencode 'client_secret=*****' \
    --data-urlencode 'grant_type=NexaAuthClient'
    
  2. Select POST to generate the request, then go to Body and select x-www-form-urlencoded.

  3. Set "bearer" as the token_type as shown in Figure 2.

    Figure 2

    Postman Curl Command


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.