Last active
May 24, 2022 09:23
-
-
Save dnno/74f655ee14d3c9d8a4f50d7da1850876 to your computer and use it in GitHub Desktop.
Postman pre-request script
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
let url_auth = pm.variables.get("keycloak_url")+"/auth/realms/" + pm.variables.get("keycloak_realm") + "/protocol/openid-connect/token"; | |
let params = "client_id=" + pm.variables.get("keycloak_client_id") | |
+ "&client_secret=" + pm.variables.get("keycloak_client_secret") | |
+ "&grant_type=client_credentials"; | |
pm.sendRequest( | |
{ | |
url: url_auth, | |
method: 'POST', | |
header: 'Content-Type: application/x-www-form-urlencoded', | |
body: { | |
mode: 'raw', | |
raw: params | |
} | |
}, (_, response) => { | |
let access_token = response.json()['access_token'] | |
pm.environment.set("access_token", access_token) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment