Created
July 20, 2021 19:34
-
-
Save ankona/e64ace14a11a40d214d2637662541a76 to your computer and use it in GitHub Desktop.
postman pre-request script for refreshing auth token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tokenUrl = 'https://signin.XXX.com/connect/token'; | |
const clientId = '<client-id>'; | |
const clientSecret = '<client-pw>'; | |
const username = 'domain\\<your-uid-here>'; // insert | |
const pw = pm.globals.get("mypw"); | |
const grant_type = 'password'; | |
const scopes = 'openid email profile exprofile roles xxx-api'; | |
const getTokenRequest = { | |
method: 'POST', | |
url: tokenUrl, | |
body: { | |
mode: 'formdata', | |
formdata: [ | |
{ key: 'grant_type', value: grant_type }, | |
{ key: 'client_id', value: clientId }, | |
{ key: 'client_secret', value: clientSecret }, | |
{ key: 'scope', value: scopes}, | |
{ key: 'username', value: username }, | |
{ key: 'password', value: pw }, | |
] | |
} | |
}; | |
pm.sendRequest(getTokenRequest, (err, response) => { | |
const jsonResponse = response.json(); | |
const newAccessToken = jsonResponse.access_token; | |
pm.variables.set('access_token', newAccessToken); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment