Skip to main content
Once you have created an API Client in Keycloak, use your credentials to obtain an access token.
Best for Automation Use Machine-to-Machine (M2M) authentication for CI/CD pipelines (Jenkins, GitHub Actions) and background services. This method supports zero-downtime credential rotation.

Prerequisites

You need the client_id and client_secret from your API Client Setup.

Request Token

Use the Client Credentials Grant flow to exchange your ID and Secret for a Bearer token.

Response

The API returns a JSON object containing your access_token.

Using the Token

Include the token in the Authorization header when making API requests: Authorization: Bearer <access_token>
Note: Tokens expire after 30 minutes. Your automation should request a fresh token before each job or handle 401 Unauthorized errors by refreshing credentials.