Verify the ID token

Check the signature and claims of a onefold ID token with the published JSON Web Key Set, and read the user's sub.

The ID token says who signed in. It is a JSON Web Token signed by onefold, returned from the token exchange when you request the openid scope. Verify it before you trust anything in it.

Discovery

onefold publishes its OpenID Connect configuration at:

https://onefold.eitozx.com/.well-known/openid-configuration

An OpenID Connect library configured with the issuer https://onefold.eitozx.com reads this document and performs every check on this page for you. See Any OpenID Connect library.

The checks

CheckExpected
SignatureRS256, verified with the key from https://onefold.eitozx.com/.well-known/jwks.json whose kid matches the token header
isshttps://onefold.eitozx.com
audYour client ID
expIn the future
nonceThe value you sent in the authorization request, if you sent one

Accept RS256 only. Do not let the token's own header choose the algorithm.

Cache the key set. When a token names a kid you do not have, fetch the key set again before you refuse the token: signing keys rotate.

import { createRemoteJWKSet, jwtVerify } from "jose";

const jwks = createRemoteJWKSet(
  new URL("https://onefold.eitozx.com/.well-known/jwks.json"),
);

const { payload } = await jwtVerify(idToken, jwks, {
  issuer: "https://onefold.eitozx.com",
  audience: process.env.CLIENT_ID,
  algorithms: ["RS256"],
});

if (payload.nonce !== expectedNonce) throw new Error("nonce mismatch");

Leave out the nonce comparison if you did not send a nonce.

What the ID token contains

ClaimPresentValue
issAlwayshttps://onefold.eitozx.com
subAlwaysThe user's ID, as a string
audAlwaysYour client ID
exp, iatAlwaysExpiry and issue time, in seconds since the epoch
auth_timeAlwaysWhen the sign-in behind this authorization happened. An ID token minted on a refresh keeps the same value.
acrAlways"1" for a sign-in with one factor, "2" when the user also verified a second factor. An ID token minted on a refresh keeps the same value.
nonceWhen you sent oneThe value from the authorization request
preferred_usernameWith the identity scopeThe user's username
email, email_verifiedWith the identity scopeThe user's email address and whether it is verified

The ID token never carries profile details or social provider data. Read those from the userinfo endpoint with the access token. Scopes and claims lists what each scope returns there.

Use sub as the user's identifier

sub is stable for the life of the account and is the same in the ID token and in userinfo.

  • Store it as a string, never as a number. See Account.
  • Key the user on sub in your own database, not on email or preferred_username. A user can change both.

Read more claims from userinfo

curl https://onefold.eitozx.com/o/userinfo/ \
  -H "Authorization: Bearer ACCESS_TOKEN"

/o/userinfo/ is the OpenID Connect userinfo endpoint. It requires the openid scope and returns the claims for every scope the user granted.

On this page