Tokens and claims
A successful sign-in gives your application three tokens:
| Token | Format | Lasts | Who reads it |
|---|---|---|---|
| Access token | JWT signed with RS256 | 5 minutes | Your API, to decide whether to serve a request. |
| ID token | JWT signed with RS256 | 30 minutes | Your app, to know who signed in. |
| Refresh token | Opaque string | 60 minutes, renewed on every refresh | Only 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:
| Claim | Value |
|---|---|
iss | https://api.myauths.com |
aud | Your application's client ID. |
sub | The user's ID for your company (see Users and Access). |
roles | The names of the user's roles in your application. An empty list when they have none. |
scope | The scopes the user granted, such as ["openid", "profile", "email"]. |
name | The user's full name. Only with the profile scope. |
email, email_verified | Only with the email scope. |
iat, nbf, exp | Issued at, not before, and expiry, in seconds since the epoch. |
jti | A 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:
| Claim | Value |
|---|---|
iss, aud, sub, iat, exp | As in the access token. |
azp | Your client ID. |
nonce | The nonce you sent when the sign-in started. Check that it matches. |
auth_time | When the user actually entered their credentials. |
sid | The user's My Auths session. |
name, picture | Only with the profile scope. picture only when the user has one. |
email, email_verified | Only 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:
- its signature is valid for a key in the JWKS whose
kidmatches the token's, usingRS256, issis exactlyhttps://api.myauths.com,audcontains your application's client ID. If one API serves several of your applications, accept each of their client IDs, and only those,expis in the future andnbfis 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.