Token Endpoint
The token endpoint issues tokens to authorized applications and services.
Applications use this endpoint to exchange authorization codes, refresh existing access tokens, or obtain machine-to-machine access where explicitly enabled.
Endpoint
POST
https://auth.zanthem.cloud/realms/{realm}/protocol/openid-connect/token
Request Content Type
Content-Type: application/x-www-form-urlencoded
Token requests must use form-encoded request bodies rather than JSON.
Client Authentication
The required client authentication method depends on the application configuration provided by Zanthem.
| Client Type | Authentication |
|---|---|
| Public client | Client identifier without a client secret. |
| Confidential client | Approved client authentication method. |
| Service client | Approved credentials for machine-to-machine access. |
Confidential clients may be configured to authenticate using a client secret or another approved mechanism.
The following confidential client examples use HTTP Basic authentication with a client identifier and secret.
:::warning Client secrets
Client secrets must never be embedded in browser-based applications, mobile applications, or publicly distributed source code.
:::
Authorization Code Exchange
Applications exchange the authorization code received from the authorization endpoint for tokens.
Request Parameters
| Parameter | Required | Description |
|---|---|---|
grant_type | Yes | Set to authorization_code. |
client_id | Conditional | Required when not supplied through client authentication. |
code | Yes | Authorization code received during authentication. |
redirect_uri | Yes | Callback URI used in the authorization request. |
code_verifier | Yes for PKCE | Original PKCE verifier. |
Confidential clients must also authenticate using their assigned client authentication method.
Public Client Example
curl --request POST \
"https://auth.zanthem.cloud/realms/example-company/protocol/openid-connect/token" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "client_id=example-app" \
--data-urlencode "code=${AUTHORIZATION_CODE}" \
--data-urlencode "redirect_uri=https://app.example.com/callback" \
--data-urlencode "code_verifier=${CODE_VERIFIER}"
Confidential Client Example
curl --request POST \
"https://auth.zanthem.cloud/realms/example-company/protocol/openid-connect/token" \
--header "Content-Type: application/x-www-form-urlencoded" \
--user "${CLIENT_ID}:${CLIENT_SECRET}" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "code=${AUTHORIZATION_CODE}" \
--data-urlencode "redirect_uri=https://app.example.com/callback" \
--data-urlencode "code_verifier=${CODE_VERIFIER}"
Token Response
Example Response
{
"access_token": "ACCESS_TOKEN",
"expires_in": 300,
"refresh_expires_in": 1800,
"refresh_token": "REFRESH_TOKEN",
"token_type": "Bearer",
"id_token": "ID_TOKEN",
"scope": "openid profile email"
}
The example expiration values are illustrative. Actual token lifetimes depend on the policies configured for your assigned application.
Response Fields
| Field | Description |
|---|---|
access_token | Token used to access authorized resources. |
expires_in | Access token lifetime in seconds. |
refresh_token | Token used to request additional access tokens, when issued. |
refresh_expires_in | Refresh token lifetime in seconds, when included. |
token_type | Type of access token issued. |
id_token | OpenID Connect identity token, when issued. |
scope | Scopes granted to the application. |
Token Types
Access Token
Access tokens authorize requests to protected resources.
Authorization: Bearer ACCESS_TOKEN
Access tokens must only be transmitted to their intended resource servers over HTTPS.
ID Token
ID tokens provide information about the authentication transaction and authenticated user.
Applications must validate the ID token before using its contents to establish an authenticated session.
ID tokens must not be substituted for access tokens when calling protected APIs.
Refresh Token
Refresh tokens allow applications to request new access tokens without requiring immediate user interaction.
Refresh tokens must be stored securely and must not be transmitted to application resource APIs.
Refreshing an Access Token
Applications can request a new access token using a valid refresh token.
Request Parameters
| Parameter | Required | Description |
|---|---|---|
grant_type | Yes | Set to refresh_token. |
client_id | Conditional | Required when not supplied through client authentication. |
refresh_token | Yes | Previously issued refresh token. |
scope | No | Requested scope, which cannot exceed the original authorization. |
Example Request
curl --request POST \
"https://auth.zanthem.cloud/realms/example-company/protocol/openid-connect/token" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=refresh_token" \
--data-urlencode "client_id=example-app" \
--data-urlencode "refresh_token=${REFRESH_TOKEN}"
Confidential clients must additionally authenticate using their approved authentication method.
If a new refresh token is returned, replace the previous refresh token with the new value.
Applications must be prepared to initiate a new authentication transaction when refresh tokens expire, are revoked, or otherwise become invalid.
Machine-to-Machine Authentication
The Client Credentials flow allows authorized services to obtain access tokens without an interactive user session.
This flow must be explicitly enabled for the assigned service client.
Request Parameters
| Parameter | Required | Description |
|---|---|---|
grant_type | Yes | Set to client_credentials. |
scope | No | Requested service scopes. |
Client authentication is required.
Example Request
curl --request POST \
"https://auth.zanthem.cloud/realms/example-company/protocol/openid-connect/token" \
--header "Content-Type: application/x-www-form-urlencoded" \
--user "${CLIENT_ID}:${CLIENT_SECRET}" \
--data-urlencode "grant_type=client_credentials"
Example Response
{
"access_token": "SERVICE_ACCESS_TOKEN",
"expires_in": 300,
"token_type": "Bearer",
"scope": "example-service"
}
The Client Credentials flow represents the service client rather than an authenticated human user.
Applications should request a new service access token when the existing token expires.
Token Validation
Applications and resource servers must validate tokens according to their intended purpose.
Validation requirements include:
- Cryptographic signature
- Expected issuer (
iss) - Expected audience (
aud) - Expiration time (
exp) - Not-before time (
nbf), when present - Approved signing algorithm
- Required scopes and permissions
ID token validation must additionally include the expected client audience, nonce validation when used, and authorized-party validation where applicable.
Use an established OIDC or JWT validation library rather than implementing cryptographic validation manually.
Unsupported Authentication Methods
Applications should not collect user passwords and submit them directly to the token endpoint.
Password-based token grants and implicit authentication flows are outside the integration methods described in this documentation.