Created
April 3, 2021 16:09
-
-
Save rheid/595b9835577cf6c98398f65a63bdc07c to your computer and use it in GitHub Desktop.
PostMan AzureAD Collection Login
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
var client_id = pm.collectionVariables.get("adminClientId"); | |
var client_secret = pm.collectionVariables.get("adminClientSecret"); | |
var tenant = pm.collectionVariables.get("netforcetenantid") | |
var resource = pm.collectionVariables.get("adminRessounce") | |
pm.sendRequest({ | |
url: 'https://login.microsoftonline.com/' + tenant + '/oauth2/token', | |
method: 'POST', | |
header: { | |
'Content-Type': 'multipart/form-data', | |
}, | |
body: { | |
mode: 'formdata', | |
formdata: [ | |
{key: "client_id", value: client_id}, | |
{key: "client_secret", value: client_secret}, | |
{key: "resource", value: resource}, | |
{key: "grant_type", value: "client_credentials"}, | |
] | |
} | |
}, function(err, response) { | |
const jsonResponse = response.json(); | |
pm.request.headers.add(`Authorization: Bearer ${jsonResponse.access_token}`); | |
// or use pm.environment.set("access_token", jsonResponse.access_token); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment