Skip to content

Instantly share code, notes, and snippets.

@rheid
Created April 3, 2021 16:09
Show Gist options
  • Save rheid/595b9835577cf6c98398f65a63bdc07c to your computer and use it in GitHub Desktop.
Save rheid/595b9835577cf6c98398f65a63bdc07c to your computer and use it in GitHub Desktop.
PostMan AzureAD Collection Login
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