Get access token
Obtains a Keycloak OAuth 2.0 access token using the **Client Credentials** grant type. The returned token is automatically saved to the `bearerToken` environment variable by the post-response script, making it available for subsequent authenticated requests.
## Request
**Method:** `POST`
**URL:** `{{KEYCLOAK_URL}}/protocol/openid-connect/token`
### Body Parameters (URL-encoded)
| Parameter | Value | Description |
|---|---|---|
| `grant_type` | `client_credentials` | OAuth 2.0 grant type for machine-to-machine authentication |
| `client_id` | `{{KEYCLOAK_CLIENT_ID}}` | The client identifier registered in Keycloak |
| `client_secret` | `{{KEYCLOAK_CLIENT_SECRET}}` | The client secret associated with the client ID |
## Response
On success, Keycloak returns a JSON object containing:
- `access_token` — The JWT bearer token to use in the `Authorization` header of subsequent API requests
- `expires_in` — Token lifetime in seconds
- `token_type` — Will be `Bearer`
## Post-response Script
After a successful response, the post-response script automatically:
1. Extracts the `access_token` from the response body
2. Saves it to the `bearerToken` environment variable
3. Logs the token expiry time to the console
## Environment Variables Required
| Variable | Description |
|---|---|
| `KEYCLOAK_URL` | Base URL of the Keycloak server (e.g. `https://keycloak-dev.uac.edu.au:8443/realms/advance_reload`) |
| `KEYCLOAK_CLIENT_ID` | Client ID registered in Keycloak |
| `KEYCLOAK_CLIENT_SECRET` | Client secret for the registered client |
Authentication
AuthorizationBearer
Bearer authentication of the form Bearer <token>, where token is your auth token.
Request
This endpoint expects an object.
grant_type
client_id
client_secret
Response headers
:status
cache-control
pragma
referrer-policy
strict-transport-security
x-content-type-options
x-frame-options
x-xss-protection
Response
OK
access_token
expires_in
refresh_expires_in
token_type
not-before-policy
scope

