Skip to main content

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 TypeAuthentication
Public clientClient identifier without a client secret.
Confidential clientApproved client authentication method.
Service clientApproved 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​

ParameterRequiredDescription
grant_typeYesSet to authorization_code.
client_idConditionalRequired when not supplied through client authentication.
codeYesAuthorization code received during authentication.
redirect_uriYesCallback URI used in the authorization request.
code_verifierYes for PKCEOriginal 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​

FieldDescription
access_tokenToken used to access authorized resources.
expires_inAccess token lifetime in seconds.
refresh_tokenToken used to request additional access tokens, when issued.
refresh_expires_inRefresh token lifetime in seconds, when included.
token_typeType of access token issued.
id_tokenOpenID Connect identity token, when issued.
scopeScopes 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​

ParameterRequiredDescription
grant_typeYesSet to refresh_token.
client_idConditionalRequired when not supplied through client authentication.
refresh_tokenYesPreviously issued refresh token.
scopeNoRequested 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​

ParameterRequiredDescription
grant_typeYesSet to client_credentials.
scopeNoRequested 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.