Skip to content

Instantly share code, notes, and snippets.

@KerberosMorphy
Created August 13, 2019 13:11
Show Gist options
  • Save KerberosMorphy/fd5513a222f67e37a054a021001a6142 to your computer and use it in GitHub Desktop.
Save KerberosMorphy/fd5513a222f67e37a054a021001a6142 to your computer and use it in GitHub Desktop.
Postman Pre-request script Cognito Authentication
const echoPostRequest = {
url: "< auth_url >",
method: 'POST',
header: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': "Basic < Base64Encore(client_id:client_secret) >"
},
body: {
mode: 'urlencoded',
urlencoded: [
{ key: "client_id", value: "< client_id >"},
{ key: "grant_type", value: "client_credentials" },
{ key: "scope", value: "< scope >" }
]
}
};
pm.sendRequest(echoPostRequest, function (err, res) {
console.log(err ? err : res.json());
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