Skip to content

Instantly share code, notes, and snippets.

@iuricmp
Last active May 3, 2021 13:55
Show Gist options
  • Save iuricmp/78ba4af18888364f8fa02ac32ebf3f6c to your computer and use it in GitHub Desktop.
Save iuricmp/78ba4af18888364f8fa02ac32ebf3f6c to your computer and use it in GitHub Desktop.
Postman OAuth2 script - client_credentials
var clientId = pm.variables.get("clientId");
var clientSecret = pm.variables.get("clientSecret");
var scope = pm.variables.get("scope");
var accessTokenURL = pm.variables.get("accessTokenURL");
pm.sendRequest({
url: accessTokenURL,
method: "POST",
header: [
'Content-Type:application/x-www-form-urlencoded'
],
body: {
mode: "urlencoded",
urlencoded: [
{key: "client_id", value: clientId},
{key: "client_secret", value: clientSecret},
{key: "scope", value: scope},
{key: "grant_type", value: "client_credentials"}
]
},
},
(error, response) => {
pm.variables.set("rawIdToken", response.json().access_token);
pm.variables.set("refresh_token", response.json().refresh_token);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment