Created
August 13, 2019 13:11
-
-
Save KerberosMorphy/fd5513a222f67e37a054a021001a6142 to your computer and use it in GitHub Desktop.
Postman Pre-request script Cognito Authentication
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
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