- 02 May 2024
-
DarkLight
-
PDF
Configuring OAUTH2 Inside of Postman in IAP Service Accounts
- Updated on 02 May 2024
-
DarkLight
-
PDF
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
-
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); });
-
Select Bearer Token as the Auth type and add the variable as shown in Figure 1.
Figure 1
-
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.
-
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'
-
Select
POST
to generate the request, then go to Body and selectx-www-form-urlencoded
. -
Set
"bearer"
as the token_type as shown in Figure 2.Figure 2