Forked from jongio/Postman-Azure-Active-Directory-Bearer-Token-Pre-Request-Script.js
Created
May 16, 2022 09:18
-
-
Save benjaminvanrenterghem/be715ec3140f21496972ed68d0542b2d to your computer and use it in GitHub Desktop.
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
pm.sendRequest({ | |
url: 'https://login.microsoftonline.com/' + pm.environment.get("tenantId") + '/oauth2/token', | |
method: 'POST', | |
header: 'Content-Type: application/x-www-form-urlencoded', | |
body: { | |
mode: 'urlencoded', | |
urlencoded: [ | |
{key: "grant_type", value: "client_credentials", disabled: false}, | |
{key: "client_id", value: pm.environment.get("clientId"), disabled: false}, | |
{key: "client_secret", value: pm.environment.get("clientSecret"), disabled: false}, | |
{key: "resource", value: pm.environment.get("resource"), disabled: false} | |
] | |
} | |
}, function (err, res) { | |
pm.globals.set("bearerToken", res.json().access_token); | |
console.log(pm.globals.get("bearerToken")); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment