Skip to Content
Otoko Identity

Tokens

Checking the tokens your backend is sent, making your user on its first request, and how long things last.

Checking tokens

CheckWhat it means
AlgorithmES256 only.
KeysFrom /.well-known/jwks.json.
aud and azpYour clients, in both.
typBearer.
Presentiss, sub, exp, iat, jti and sid, all of them.
serviceA client credentials token has "service": true and no sid, so the sid check refuses it. Refuse the service claim by name too in a backend that serves people.

Create your user on its first request

This is the recommended place for your backend to make its users, for every app. It runs while your backend is up and serving that person, and needs no event to arrive, so a late or dead account.created costs nothing. The event only makes the user earlier.

When a request comes with an access token that passes the checks, and no user of yours has its sub:

  1. Call GET /oauth/userinfo with that access token, as Authorization: Bearer.
  2. Upsert the user keyed by sub: a unique key on sub, and an insert that ignores a conflict, then read the row. Two first requests at once then make one user.
  3. Carry on with the request.
INSERT INTO users (sub, email, first_name, last_name, language)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (sub) DO NOTHING;
  • /oauth/userinfo answers the claims the token's scopes allow: email and email_verified with email, and given_name, family_name and locale with profile. They are the event's first_name, last_name and language.
  • A token from your backend's own sign-in, such as POST /internal/v1/sessions/password, gets sub, email and locale only. Allow for missing names.
  • Key the user on sub, never on the email, which can change. A person's sub is the same in every client of the app. Each app has its own people, so the same email in another app is another sub.

Lifetimes and rules

WhatHow long, or how
Undelivered session-ends callsTried again for 6 hours from ended_at.
Undelivered account-created callsTried again after 30 seconds, 2 minutes, 10 minutes, 1 hour, 6 hours and 24 hours, then dead, and kept 30 days for a replay.
The sign-in checkOne try, waited for 3 seconds. After 5 failures in a row within 60 seconds, not called for 60 seconds.
A signed webhook-timestampRefuse it more than 5 minutes from your clock.
Required action codeSingle use, good for the app's Required action code lifetime, a minute by default.
Previous client secret after a rotationKeeps working for 24 hours, then is refused.
Previous webhook signing secret after a rotationSigns beside the new one for 7 days. Retire now stops it within about a minute.
A sign-up still waiting for its codeDeleted a day after it was made, on an app with Otoko Identity's own sign-up and Verify email on.
A browser client's refresh tokenNever outlives the sign-in session it came from.
Other lifetimesThe app's own, on its Sessions & tokens tab, and each client's on its Advanced tab.
  • A client secret can be rotated on the client's page. The new one is shown once and the previous one keeps working for 24 hours. For a leaked secret, stop every secret the client has now.
  • Disabling an app stops its sign-ins, API keys and refreshes at once. Access tokens already issued keep verifying in its backend until they expire, because they are checked there.