Tokens
Checking the tokens your backend is sent, making your user on its first request, and how long things last.
Checking tokens
| Check | What it means |
|---|---|
| Algorithm | ES256 only. |
| Keys | From /.well-known/. |
| aud and azp | Your clients, in both. |
| typ | Bearer. |
| Present | iss, sub, exp, iat, jti and sid, all of them. |
| service | A 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:
- Call
GET /oauth/userinfowith that access token, asAuthorization: Bearer. - Upsert the user keyed by
sub: a unique key onsub, and an insert that ignores a conflict, then read the row. Two first requests at once then make one user. - 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/userinfoanswers the claims the token's scopes allow:emailandemail_verifiedwithemail, andgiven_name,family_nameandlocalewithprofile. They are the event'sfirst_name,last_nameandlanguage.- A token from your backend's own sign-in, such as
POST /internal/v1/sessions/password, getssub,emailandlocaleonly. Allow for missing names. - Key the user on
sub, never on the email, which can change. A person'ssubis the same in every client of the app. Each app has its own people, so the same email in another app is anothersub.
Lifetimes and rules
| What | How long, or how |
|---|---|
| Undelivered session-ends calls | Tried again for 6 hours from ended_at. |
| Undelivered account-created calls | Tried 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 check | One try, waited for 3 seconds. After 5 failures in a row within 60 seconds, not called for 60 seconds. |
| A signed webhook-timestamp | Refuse it more than 5 minutes from your clock. |
| Required action code | Single use, good for the app's Required action code lifetime, a minute by default. |
| Previous client secret after a rotation | Keeps working for 24 hours, then is refused. |
| Previous webhook signing secret after a rotation | Signs beside the new one for 7 days. Retire now stops it within about a minute. |
| A sign-up still waiting for its code | Deleted 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 token | Never outlives the sign-in session it came from. |
| Other lifetimes | The 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.