Created
May 19, 2021 15:45
-
-
Save dcaponi/13b0e7187a6a76e459ee8b1a1675f5a3 to your computer and use it in GitHub Desktop.
Automatically Run Authorization Step for OneLogin API Requests
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
var region = pm.variables.get("region"); | |
var id = pm.variables.get("client_id"); | |
var secret = pm.variables.get("client_secret"); | |
var basicToken = btoa(`${id}:${secret}`); | |
const echoPostRequest = { | |
url: `https://api.${region}.onelogin.com/auth/oauth2/v2/token`, | |
method: 'POST', | |
header: { | |
"Content-Type": "application/json", | |
"Authorization":`Basic ${basicToken}` | |
}, | |
body: { | |
mode: 'application/json', | |
raw: JSON.stringify({"grant_type":"client_credentials"}) | |
} | |
}; | |
pm.sendRequest(echoPostRequest, (err, response) => { | |
const jsonResponse = response.json(); | |
const newAccessToken = jsonResponse.access_token; | |
pm.variables.set('access_token', newAccessToken); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment