Dōrvis

Sign in

User data in the ID token

With scope=openid profile the ID token holds a verified first name, last name and personal code, whichever method the user chose.

ID token contents

JSONid_token payload
{
  "iss": "https://dorvis.eu/oidc",
  "aud": ["your-client-id"],
  "sub": "…",
  "iat": 1759996400,
  "exp": 1760000000,
  "nonce": "9b27e0…",
  "given_name": "Jānis",
  "family_name": "Bērziņš",
  "first_name": "Jānis",
  "last_name": "Bērziņš",
  "person_code": "010101-12345",
  "auth_method": "smartid"
}
FieldContent
given_nameFirst name
family_nameLast name
first_name, last_nameThe same data for older integrations
person_codeLatvian personal code
auth_methodThe method used, for example smartid or swedbank
issMust equal https://dorvis.eu/oidc
audMust contain your client_id
exp, iatExpiry and issue time in Unix seconds
nonceThe value from your authorization request
subOpenID Connect subject identifier

Verifying the ID token

Libraries do this for you. If you handle the token yourself, check the signature against the JWKS keys and the iss, aud, exp and nonce fields.

JavaScriptverify-id-token.mjs
import { createRemoteJWKSet, jwtVerify } from 'jose';

const jwks = createRemoteJWKSet(new URL('https://dorvis.eu/oidc/.well-known/jwks.json'));

export async function verifyIdToken(idToken, expectedNonce) {
  const { payload } = await jwtVerify(idToken, jwks, {
    issuer: 'https://dorvis.eu/oidc',
    audience: process.env.OIDC_CLIENT_ID,
  });
  if (payload.nonce !== expectedNonce) throw new Error('nonce mismatch');
  return payload; // given_name, family_name, person_code, auth_method
}

Userinfo

The same data can be read from the userinfo endpoint with the access token. In most cases the ID token is enough.

Shell
curl https://dorvis.eu/oidc/userinfo \
  -H "Authorization: Bearer $ACCESS_TOKEN"

Personal code

Link the user in your system by person_code. Store and compare it in one form, for example without hyphens and spaces.

JavaScript
// store and compare personal codes in one form
const normalizePersonCode = (code) => code.replace(/[\s-]/g, '');

Did not find the answer?

Write to us and a developer will reply.

Ask a question
Loading complete

We use cookies to make this website easier to use. Read our Privacy and Cookie Policy.