Generate Access Token (Authorization Code)

Generate Access Token (Authorization Code)

Endpoint:
POST /relid/authserver/oauth/token

Description:
Exchanges an authorization code (obtained from the authorization endpoint) for an access token and ID token. This is part of the standard OAuth 2.0 Authorization Code flow with optional OpenID Connect support.


🔐 Authentication

Type: Basic Auth
Header Format: Authorization: Basic <base64(client_id:client_secret)>


📥 Request Headers

HeaderValue
AuthorizationBasic authentication credentials
Content-Typeapplication/x-www-form-urlencoded
Acceptapplication/json

📤 Request Body (Form URL Encoded)

FieldTypeRequiredDescription
grant_typestringYesMust be authorization_code
codestringYesAuthorization code received from /authorize
redirect_uristringYesMust match the one used in the original /authorize request

📥 Query Parameters

No query parameters.


📬 Response Fields

FieldTypeDescription
access_tokenstringOAuth2 access token
token_typestringType of token (typically Bearer)
expires_innumberToken validity duration in seconds
scopestringScopes assigned
refresh_tokenstringToken to refresh the access token
id_tokenstringJWT for OpenID Connect identity

📘 Example Request (cURL)

curl 'https://auth.relid.com:8006/relid/authserver/oauth/token' \
  -u '<client_id>:<client_secret>' \
  -X POST \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Accept: application/json' \
  -d 'grant_type=authorization_code&code=<auth_code>&redirect_uri=https://localhost:8080'

📘 Example Response

{
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVC...",
  "token_type": "Bearer",
  "refresh_token": "ctFLT_4ZI5bcoHxPw8C2lKxMUTdYvsVTktv...",
  "expires_in": 299,
  "scope": "all openid",
  "id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVC..."
}

📝 Notes

  • This flow is used when the user logs in through a browser and grants permission.
  • The redirect_uri must exactly match the URI registered with the client.
  • The id_token can be decoded to extract user identity claims when using OpenID Connect.
  • NOTE: Request parameters are expected in the request body only. Any parameters in the URL will be ignored.