Skip to content

Instantly share code, notes, and snippets.

@dnno
Last active May 24, 2022 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnno/74f655ee14d3c9d8a4f50d7da1850876 to your computer and use it in GitHub Desktop.
Save dnno/74f655ee14d3c9d8a4f50d7da1850876 to your computer and use it in GitHub Desktop.
Postman pre-request script
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