Skip to content

Instantly share code, notes, and snippets.

@alexphelps
Created November 30, 2017 18:45
Show Gist options
  • Save alexphelps/0189442162a969cd6040bdace737d2aa to your computer and use it in GitHub Desktop.
Save alexphelps/0189442162a969cd6040bdace737d2aa to your computer and use it in GitHub Desktop.
Postman Get Oauth Bear Token Prescript with Username & Password
// 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