Created
November 30, 2017 18:45
-
-
Save alexphelps/0189442162a969cd6040bdace737d2aa to your computer and use it in GitHub Desktop.
Postman Get Oauth Bear Token Prescript with Username & Password
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
// grab our env variables for access | |
var domain = pm.environment.get("domain"); | |
var username = pm.environment.get('username'); | |
var password = pm.environment.get('password'); | |
// Send request to get token and set as env variabled {{authorization}} | |
pm.sendRequest({ | |
url: domain + '/api/token', | |
method: 'POST', | |
header: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
}, | |
body: { | |
mode: 'urlencoded', | |
urlencoded: [ | |
{key: "grant_type", value: "password", disabled: false}, | |
{key: "username", value: username, disabled: false}, | |
{key: "password", value: password, disabled: false} | |
] | |
} | |
}, function (err, res) { | |
pm.environment.set("authorization", "Bearer " + res.json().access_token); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment