Identity & access

Tokens and claims

Access, ID and refresh tokens — lifetimes, claims, verification against the JWKS and the mistakes that cost an afternoon.

The three tokens

Access
FormatJWT, RS256, typ: at+jwt, kid in the header
Lifetime900 seconds
What it is forCalling an API. Exactly one audience.
ID
FormatJWT, RS256
Lifetime3,600 seconds
What it is forTelling your application who signed in.
Refresh
FormatOpaque, rotated on every use
Lifetime30 days
What it is forMinting a new access token without a prompt.

The token endpoint

One endpoint serves all three grants. It takes form-encoded fields, never JSON — a Content-Type: application/json body is refused before anything is parsed.

POST{issuer}/tokenNone — the client credential travels in the body

Exchange a code, refresh a session, or mint a service token. The grant decides which fields apply.

Headers

Content-Type
application/x-www-form-urlencoded
Accept
application/json

Form fields

grant_typestringrequired
authorization_code, refresh_token or client_credentials.
codestring
authorization_code only. Lives 60 seconds and may be exchanged once.
code_verifierstring
authorization_code only, and required: the PKCE verifier whose S256 hash you sent as code_challenge.
redirect_uristring
authorization_code only. Must match the authorize request byte for byte, or the exchange is refused.
client_idstringrequired
The registered client. Public clients send it here; confidential clients may authenticate with HTTP Basic instead.
client_secretstring
Confidential clients only — confidential_web and confidential_service.
refresh_tokenstring
refresh_token grant only. The current one; you receive a replacement.
scopestring
client_credentials only, e.g. appcenter:service.
resourcestring
client_credentials only, e.g. urn:versified:api:appcenter. A resource the client is not assigned fails with invalid_target.
Request — authorization_code
POST /oidc/token HTTP/1.1
Host: apps-api.versified.com.gh
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code
&code=8f2c1e0a…
&redirect_uri=https%3A%2F%2Fapp.example.com%2Fauth%2Fcallback
&code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
&client_id=retill-web
200 OK — code exchange
{
  "access_token": "eyJhbGciOiJSUzI1NiIs…",
  "token_type": "Bearer",
  "expires_in": 900,
  "id_token": "eyJhbGciOiJSUzI1NiIs…",
  "refresh_token": "p9Kx3Lm2…",
  "scope": "openid email profile offline_access appcenter"
}

expires_in is 900. id_token is present because openid was granted.

200 OK — refresh
{
  "access_token": "eyJhbGciOiJSUzI1NiIs…",
  "token_type": "Bearer",
  "expires_in": 900,
  "refresh_token": "Qm7d0Vb4…",
  "scope": "openid email profile offline_access appcenter"
}

refresh_token is a new value; the one you sent is now spent.

400 invalid_grant
{
  "error": "invalid_grant",
  "error_description": "grant request is invalid"
}

Expired code, reused code, wrong verifier, or a spent refresh token. Send the person back through authorize.

Failures to handle

400invalid_request
A required field is missing, PKCE was not used, or the body was not form-encoded.
400invalid_grant
The code or refresh token is expired, already used, or does not match the verifier.
400invalid_target
The requested resource is not in the client's assignment. Widening it needs re-authorization.
401invalid_client
Unknown client, wrong secret, or a public client that tried to authenticate.
  • Refresh tokens live 30 days and rotate on every use. Storing the old one means the next refresh presents a spent token and the grant is refused — that is the reuse-detection signal, not a bug.
  • A client_credentials exchange returns no id_token and no refresh_token: there is no person and no session to renew.

A decoded access token

The header names the algorithm and the key. The payload carries the person, one audience, the granted scopes, and three legacy-compatibility claims (user_id, email, useruuid) that predate this provider.

access token — decoded
{
  "header": {
    "alg": "RS256",
    "typ": "at+jwt",
    "kid": "0X8c2b1e…"
  },
  "payload": {
    "sub": "0d5a7f4e-6c1b-4a3e-9f2d-1c8b5e7a9d31",
    "aud": "urn:versified:api:appcenter",
    "scope": "openid email profile offline_access appcenter",
    "client_id": "retill-web",
    "user_id": 412,
    "email": "ama@example.com",
    "useruuid": "0d5a7f4e-6c1b-4a3e-9f2d-1c8b5e7a9d31",
    "iat": 1794141000,
    "exp": 1794141900,
    "iss": "https://apps-api.versified.com.gh/oidc"
  }
}

user_id is the legacy numeric id. Key on sub — it is the only claim that is stable across products.

A decoded ID token

id token — decoded
{
  "sub": "0d5a7f4e-6c1b-4a3e-9f2d-1c8b5e7a9d31",
  "aud": "retill-web",
  "iss": "https://apps-api.versified.com.gh/oidc",
  "email": "ama@example.com",
  "email_verified": true,
  "name": "Ama Mensah",
  "iat": 1794141000,
  "exp": 1794144600
}

aud is your client id, not a resource audience. name appears only when the profile scope was granted.

An ID token is not an access token

The ID token is 3,600 seconds of proof about who signed in, addressed to your client. Send the access token to an API and the ID token nowhere. Swapping them is the second most common integration bug after skipping the audience check.

The signing keys

GET /oidc/jwks
{
  "keys": [
    {
      "kty": "RSA",
      "use": "sig",
      "alg": "RS256",
      "kid": "0X8c2b1e…",
      "n": "sXchDaQeiM0…",
      "e": "AQAB"
    }
  ]
}

One key today, rotated rarely. Fetch it once, cache it, and refetch when a token names a kid you do not hold.

Never take a key from the token header

jku, jwk and x5u are attacker-controlled. The only trusted source of keys is the JWKS URL from the discovery document, fetched over HTTPS by you.

Access token claims

iss
MeaningThe issuer. Compare it literally with the discovery document.
sub
MeaningThe person (userUuid). Stable, and the only correct primary key.
aud
MeaningOne resource audience, e.g. urn:versified:api:appcenter.
scope
MeaningSpace-separated granted scopes.
client_id
MeaningThe OAuth client the token was minted for.
exp, iat
MeaningExpiry and issue time, in seconds. 30 seconds of clock skew is tolerated.

Verifying

Verify locally. Do not call the provider on every request — fetch the JWKS once, cache it, and refresh when you see a kid you do not hold.

verify.ts
import { createRemoteJWKSet, jwtVerify } from "jose";

const jwks = createRemoteJWKSet(new URL(`${issuer}/jwks`));

const { payload } = await jwtVerify(token, jwks, {
  issuer,
  audience: "urn:versified:api:appcenter",
  clockTolerance: 30,
  algorithms: ["RS256"],
});

const userUuid = payload.sub as string;

Three ways to get this wrong

Decoding without verifying; verifying the signature but not the audience; and treating email as the person's identity. All three end with one customer reading another's data.

Reading the request identity

The person always comes from the token's sub. Headers such as accountid and userid only select which account is being acted on — equal values mean the owner acting on their own account, different values mean staff acting on an owner's. They never establish identity. See Acting on the right account.

Something here out of date or unclear?

The platform team answers integration questions directly.

support@versified.com.gh
32 pages in this documentation