Configuring OAUTH2 Inside of Postman in Platform Service Accounts

Prev Next

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

Related Reading:

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

  1. Add the pre-request script below into Postman and replace the Itential Platform 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 the Platform 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