Tokens and claims

A successful sign-in gives your application three tokens:

TokenFormatLastsWho reads it
Access tokenJWT signed with RS2565 minutesYour API, to decide whether to serve a request.
ID tokenJWT signed with RS25630 minutesYour app, to know who signed in.
Refresh tokenOpaque string60 minutes, renewed on every refreshOnly your server, to get new tokens (Refreshing).

Access token

Your app sends the access token to your API in the Authorization: Bearer header. It describes the user as a member of your application:

ClaimValue
isshttps://api.myauths.com
audYour application's client ID.
subThe user's ID for your company (see Users and Access).
rolesThe names of the user's roles in your application. An empty list when they have none.
scopeThe scopes the user granted, such as ["openid", "profile", "email"].
nameThe user's full name. Only with the profile scope.
email, email_verifiedOnly with the email scope.
iat, nbf, expIssued at, not before, and expiry, in seconds since the epoch.
jtiA unique ID for this token.
{
  "iss": "https://api.myauths.com",
  "aud": "4b1f6c2e-8d3a-4f0e-9a51-2c7d8e6b0f13",
  "sub": "b7c9e0a4-1f2d-4c6b-8e3a-5d9f0a1b2c3d",
  "roles": ["editor"],
  "scope": ["openid", "profile", "email"],
  "name": "Ana López",
  "email": "ana@example.com",
  "email_verified": true,
  "iat": 1790000000,
  "nbf": 1790000000,
  "exp": 1790000300,
  "jti": "9f8e7d6c-..."
}

Roles are read when the token is issued. When you change a member's roles or suspend them, the change shows up in the next token, at the latest when the current one expires.

ID token

The ID token is for your app itself, not for your API. It carries:

ClaimValue
iss, aud, sub, iat, expAs in the access token.
azpYour client ID.
nonceThe nonce you sent when the sign-in started. Check that it matches.
auth_timeWhen the user actually entered their credentials.
sidThe user's My Auths session.
name, pictureOnly with the profile scope. picture only when the user has one.
email, email_verifiedOnly with the email scope.

The ID token doesn't carry roles; read them from the access token.

The same profile claims are available from the UserInfo endpoint, called with the access token:

curl https://api.myauths.com/userinfo \
  -H "Authorization: Bearer ACCESS_TOKEN"
{
  "sub": "b7c9e0a4-1f2d-4c6b-8e3a-5d9f0a1b2c3d",
  "name": "Ana López",
  "email": "ana@example.com",
  "email_verified": true
}

Verifying access tokens

Your API should verify every access token itself. Tokens are signed with keys published at https://api.myauths.com/oauth2/jwks, so there's no need to call My Auths for each request. Accept a token only if:

  1. its signature is valid for a key in the JWKS whose kid matches the token's, using RS256,
  2. iss is exactly https://api.myauths.com,
  3. aud contains your application's client ID. If one API serves several of your applications, accept each of their client IDs, and only those,
  4. exp is in the future and nbf is not (allow a minute of clock skew).

Then use sub to identify the user and roles to decide what they may do.

Node.js: jose

import { createRemoteJWKSet, jwtVerify } from "jose";

const jwks = createRemoteJWKSet(new URL("https://api.myauths.com/oauth2/jwks"));

export async function verifyAccessToken(token) {
  const { payload } = await jwtVerify(token, jwks, {
    issuer: "https://api.myauths.com",
    audience: process.env.MY_AUTH_CLIENT_ID,
    algorithms: ["RS256"],
    clockTolerance: 60,
  });
  return payload; // payload.sub, payload.roles
}

Spring Boot: resource server

spring:
  security:
    oauth2:
      resourceserver:
        jwt:
          issuer-uri: https://api.myauths.com
          audiences: ${MY_AUTH_CLIENT_ID}
          authorities-claim-name: roles
          authority-prefix: ROLE_

With this, a member with the role editor passes hasRole("editor") checks.

Python: PyJWT

import jwt

jwks = jwt.PyJWKClient("https://api.myauths.com/oauth2/jwks")

def verify_access_token(token: str) -> dict:
    key = jwks.get_signing_key_from_jwt(token)
    return jwt.decode(
        token,
        key.key,
        algorithms=["RS256"],
        issuer="https://api.myauths.com",
        audience=CLIENT_ID,
        leeway=60,
    )

Signing keys

My Auths signs tokens with RSA keys, each with its own kid. When the key is changed as planned, the new key is published in the JWKS before any token is signed with it, and the old one stays published until the tokens it signed have expired. If a key ever had to be withdrawn at once, tokens it signed would stop verifying; your app then refreshes and gets tokens signed with the new key.

Don't copy a key into your code or configuration. Cache the JWKS and fetch it again when a token has a kid you haven't seen. The libraries above do this for you.

Checking whether a token was revoked

Because APIs verify access tokens locally, a token stays valid until it expires even if your app revoked it, or the user reset their password, in the meantime. With a 5-minute lifetime this is usually fine. If an operation needs to know right now, ask the introspection endpoint:

curl -X POST https://api.myauths.com/oauth2/introspect \
  -u "CLIENT_ID:CLIENT_SECRET" \
  -d token=ACCESS_TOKEN

The answer is {"active": false} for a token that expired or was revoked, or "active": true with the token's claims.