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-configurationAn 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
| Check | Expected |
|---|---|
| Signature | RS256, verified with the key from https://onefold.eitozx.com/.well-known/jwks.json whose kid matches the token header |
iss | https://onefold.eitozx.com |
aud | Your client ID |
exp | In the future |
nonce | The 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
| Claim | Present | Value |
|---|---|---|
iss | Always | https://onefold.eitozx.com |
sub | Always | The user's ID, as a string |
aud | Always | Your client ID |
exp, iat | Always | Expiry and issue time, in seconds since the epoch |
auth_time | Always | When the sign-in behind this authorization happened. An ID token minted on a refresh keeps the same value. |
acr | Always | "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. |
nonce | When you sent one | The value from the authorization request |
preferred_username | With the identity scope | The user's username |
email, email_verified | With the identity scope | The 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
subin your own database, not onemailorpreferred_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.