Forked from jongio/Postman-Azure-Active-Directory-Bearer-Token-Pre-Request-Script.js
Created
October 22, 2020 11:32
-
-
Save ozgurgul/740c03f9eabf85510c03dba466d0f526 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
credit to https://blog.jongallant.com/2019/04/azure-rest-apis-postman-in-no-time-flat/