This is javascript for use with Postman's pre-request script feature. It makes POST request to Keycloak Token Endpoint to get a valid token and automatically set the token for all requests in Postman collection.
- Create Client on the Keycloak administration console with this attributes :
- CLient Protocol : openid-connect
- Access Type : Confidentials
- Service Account : ON
-
Save
-
Get the secret on the Credentials tabs
-
Click edit on a collection and copy the content of keycloak-fetch-token-postman-pre-request.js into the "Pre-request Script" tab in Postman.
- In the Authorization tab set the Type to Bearer Token and Token to {{token}}. This is the token we created and set via the pre-request script.
- For all API requests: In the Authorization tab select Type - Inherit auth from parent
- ENJOY