IMPORTANT: USE ONLY ON COMPUTERS THAT ARE NOT SHARED WITH OTHERS AND YOU ARE SURE THAT OTHERS CANNOT ACCESS
I wanted to share this with the community as I find this approach very helpful while using Postman to access various APIs. If you have been copying and pasting the access token after getting a new one every time it expires (like I used to do) this approach could make your life a little easier.
Step 1: Create a Environment, by clicking on the tiny icon to the right of “No Environment” and click on “Add” (screen-snip below)
Step 2: Add details as shown below
Now click on 3 dots to the right of “Current Value” and click on Reset all. This will copy the values you entered under “Initial Value” column to “Current Value” column
Step 3: Create a new “POST” Request, with URL string https://{{tenant}}.api.identitynow.com/oauth/token
Update the Body of this request to as shown below:
And add the below code to “Tests” section
pm.environment.set(
"access_token",
pm.response.json().access_token
);
Step 4: Now update the “Authorization” tab of your collection as below
And “Auth” tab of each request as below to inherit Auth from parent (ie the collection the request is under)
Once this is set up, every time you need a new JWT token, you can send the request created in Step 3 and it will automatically store the access_token under environment variables and directly linked to your collection.
TIP: With this setup, you can create multiple environments for various tenants and easily switch between tenants from the selector on right top (“No Environment” under Step 1)