Token Management

Learn about access tokens, refresh tokens, ID tokens, and how to manage them securely.

Access Tokens

Type:JWT (JSON Web Token) signed with HS256

Expiration:30 minutes (1800 seconds) from issuance

Usage:Include the token in the Authorization header as a Bearer token

JWT Claims

ClaimTypeStatusDescription
substringRequiredUser ID (subject identifier)
emailstringRequiredUser's email address
client_idstringRequiredYour application's client ID
scopestringRequiredSpace-separated list of granted scopes
expnumberRequiredExpiration timestamp (Unix time)
iatnumberRequiredIssued at timestamp (Unix time)

Refresh Tokens

Type:JWT (JSON Web Token) signed with HS256

Expiration:7 days from issuance

Usage:Exchange this token for new access and refresh tokens via the token endpoint

JWT Claims

ClaimTypeStatusDescription
substringRequiredUser ID (subject identifier)
expnumberRequiredExpiration timestamp (Unix time)
iatnumberRequiredIssued at timestamp (Unix time)

ID Tokens

Type:JWT (JSON Web Token) signed with HS256

Purpose:Contains user identity information per OpenID Connect specification

JWT Claims (Standard OpenID Connect)

ClaimTypeStatusDescription
substringRequiredUser ID (subject identifier)
namestringRequiredUser's display name
preferred_usernamestringRequiredUser's username
emailstringRequiredUser's email address
email_verifiedbooleanRequiredEmail verification status
picturestringRequiredURL to user's avatar image
avatarUrlstringRequiredAlternative avatar URL field
client_idstringRequiredYour application's client ID
noncestringOptionalNonce value (only if provided in authorization request)
expnumberRequiredExpiration timestamp (Unix time)
iatnumberRequiredIssued at timestamp (Unix time)

Token Refresh Flow

When an access token expires (after 30 minutes), use the refresh token to obtain new tokens without requiring user interaction. Refresh tokens proactively before the access token expires:

POST /api/v2/oauth/token
Content-Type: application/json

{
  "grant_type": "refresh_token",
  "refresh_token": "YOUR_REFRESH_TOKEN",
  "client_id": "YOUR_CLIENT_ID",
  "client_secret": "YOUR_CLIENT_SECRET"
}

Successful response (200 OK):

{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "expires_in": 1800,
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "id_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

Token Revocation & Blacklisting

Users can revoke access to your application at any time through their account settings. When a user revokes access:

  • Cengel ID removes the consent grant from the system
  • We blacklist all existing tokens (access, refresh, ID)
  • The API returns403 Forbiddenfor requests with revoked tokens
  • Token refresh attempts also fail with403 Forbidden

Handle 401/403 responses gracefully:

  • Detect token revocation by checking for 403 responses with "Access revoked by user" error
  • Clear stored tokens from your system
  • Prompt the user to re-authenticate by redirecting to the authorization endpoint
  • Don't automatically retry with the same token

Account Status & Token Validity

Cengel ID invalidates tokens when the user's account status changes:

  • Banned accounts:We immediately invalidate all tokens. The API returns403 Forbiddenwith "Account banned" error.
  • Suspended accounts:We invalidate tokens. The API returns403 Forbiddenwith "Account is suspended" error.
  • Expired bans:If a ban expires, we automatically reactivate the account, but existing tokens remain invalid. The user must re-authenticate.

Handle these error responses gracefully and provide clear feedback to users about why authentication failed.