Sign-in links and signing a person out
Two things an application can do beyond the standard OpenID Connect flow. Both are off until you use them, and both use the client authentication your application already has.
Every URL on this page is on your tenant's hostname. The examples use the module @claylevering/auth-nuxt; the endpoints are plain HTTP and work from any server.
Sign-in links
A sign-in link is a one-time link sent to the email address on an account. Opening it and pressing Sign in signs that browser in. People still have a password; the link is a second way in for when typing it is the harder option.
Turning it on
In the admin pages, open the application and set:
- Allow sign-in by emailed link: on.
- Sign-in start URL: your application's own sign-in address, for example
https://app.example.com/auth/login.
With the switch on, the sign-in page shows Email me a sign-in link under the password form, and your application may ask for links to be sent.
The start URL matters because a link can be opened in a browser that never visited your application: a phone's mail app, or a dispatcher sending it to someone else. That browser is signed in here and then sent to the start URL, where your application begins its normal sign-in. It completes without a prompt, because the browser is now signed in. With no start URL the person lands on this service's own profile page instead of in your application.
The rules a link follows
| Rule | Detail |
|---|---|
| Once | A link signs in once. A second use is refused. |
| Short-lived | 15 minutes when the person asked for it. When your application sends it: 1 hour unless you ask for another length, from 5 minutes to 24 hours. |
| Newest only | Asking for a new link stops the earlier ones for that person and application. |
| Limited | Five links per person and application in ten minutes. |
| Not a second factor | A link proves control of the mailbox and nothing else. It is not sent to an account that has a second factor enabled, and not offered by an application that requires a second factor or takes no passwords. |
| No hint about accounts | Asking for a link gets the same answer whether or not the address has an account. |
| A press, not a visit | The link opens a page with a Sign in button. Mail systems open links to scan them; a link that signed in on a visit would be spent by the scanner. |
| First proof | On an account whose address was never confirmed (a self-service sign-up), using a link confirms the address and removes the account's other sessions, its passkeys and the password chosen at sign-up: whoever made the account had not proven the address. The person can choose a password from their profile. |
A session opened by a link is accepted only by applications that have links switched on. An application on the same tenant with links off asks that person to sign in again, with reason=email_link_not_allowed on the sign-in page's address. The same check applies each application's other sign-in rules; see clients → sign-in rules.
What your application sees
The ID token says how the person signed in:
| Claim | Value after a sign-in link |
|---|---|
amr | ["otp"] |
acr, auth_assurance_level | aal1 |
mfa_satisfied | false |
assurance_source, current_provider | email_link |
If part of your application needs a password or a second factor, check these claims there and send the person through a fresh sign-in with prompt=login.
People who have no password yet
An imported account is told to choose a password at its first sign-in. When that first sign-in is by link, the person is asked for a new password only; there is no current password to type. This is the intended first sign-in for people moved from another system: send them a link, they choose a password, and they are in.
Sending a link from your application
POST /api/oidc/sign-in-link
Authenticate as you do at the token endpoint. For private_key_jwt the assertion's aud is this endpoint's URL.
| Field | Required | Notes |
|---|---|---|
email | yes | The address on the account. |
expires_in | no | Seconds the link works: 900 (fifteen minutes) to 86400. Default 3600. |
The answer is 202 {"accepted": true, "expires_in": 3600} whether or not the address has an account. Accounts are shared by every application on this service, so an application is not told which addresses have one. Your own records say who your users are.
A link is emailed only to an account of your application's tenant: one that has signed in on the tenant's sign-in page, was imported or invited for one of its applications, or is one of its admins. For any other address nothing is sent, with the same answer. To bring a new person in, send an invitation.
An account is sent at most one link a minute and three per link lifetime on your tenant (with fifteen-minute links, the shortest you may ask for, three per fifteen minutes); a request past that sends nothing, with the same answer, and the newest link already sent still works. Once a link is used, the next request sends at once. Another tenant's traffic never uses up yours.
| Status | error | Meaning |
|---|---|---|
| 401 | invalid_client | Client authentication failed. |
| 400 | unauthorized_client | Sign-in links are not switched on for this application. |
| 400 | invalid_request | email is not an email address. |
| 429 | slow_down | Too many links for that address. Retry-After says when to try again. |
With the module:
// server/api/admin/users/[id]/send-sign-in-link.post.ts
export default defineEventHandler(async (event) => {
const admin = await requireAuthSession(event);
// Your own check that `admin` may do this goes here.
const user = await findUser(getRouterParam(event, 'id'));
return sendSignInLink(event, { email: user.email, expiresIn: 4 * 60 * 60 });
});
Who may send a link is your application's decision. The endpoint trusts whoever holds your client key.
Signing a person out of your application
"Log this person out" for a lost phone or a laptop left signed in. It has to do more than end your application's session: the browser is still signed in here, so it would walk straight back in.
A revocation is a moment recorded for one person at one application. Every sign-in that person made before it stops counting for that application:
- The next time their browser comes here for your application, they are asked to sign in again, although they are still signed in here and at other applications.
- An authorization code issued from an earlier sign-in is refused at the token endpoint.
- Your application is told the next time it asks, and drops its own session.
Revoking
POST /api/oidc/session/revoke
Authenticate as at the token endpoint; the assertion's aud is this endpoint's URL.
| Field | Required | Notes |
|---|---|---|
sub | yes | The person, as the sub of your ID tokens. |
Answer: 200 {"revoked": true, "revoked_before": 1794823200}.
A tenant admin can do the same in the admin pages: open the application, Sign a person out, and give the email address.
Checking a session
POST /api/oidc/session/check
| Field | Required | Notes |
|---|---|---|
sub | yes | The sub of the ID token the session came from. |
auth_time | yes | That ID token's auth_time. |
sid | yes | That ID token's sid: the sign-in, sealed for your application. Opaque: do not parse it. |
Answer: 200 {"active": true} or {"active": false}. false means the sign-in your session came from has ended at Claxx Auth (the person signed out, a password change or reset or an admin ended it, the account was marked to choose a new password, or its time ran out), or the person was signed out of your application after it. A check without sid is 400 sid_required (what @claylevering/auth-nuxt 0.3.x gets: upgrade to 0.4.0, which needs this service at v0.0.38 or later). A sid your application was not given (another application's, or altered) answers {"active": false}.
Ask for each active session about once a minute, and end the session when the answer is false. If this service cannot be reached, keep the session for a limited time and then end it: neither a short outage nor a long one should decide who is signed in.
The module does this for you. Its defaults check once a minute and allow fifteen minutes without an answer:
// nuxt.config.ts
export default defineNuxtConfig({
claxxAuth: { sessionCheckInterval: 60, sessionCheckGrace: 900 }
});
// server/api/admin/users/[id]/sign-out.post.ts
export default defineEventHandler(async (event) => {
const admin = await requireAuthSession(event);
// Your own check that `admin` may do this goes here.
const user = await findUser(getRouterParam(event, 'id'));
return revokeUserSessions(event, { sub: user.claxxAuthSub });
});
What a revocation does not do
- It does not block the person. They can sign in again with their password. To keep someone out, refuse them in your application (the module's
claxx-auth:signed-inhook), or deactivate their account there. - It does not sign them out elsewhere. Other applications, and this service's own pages, are untouched.
- It is not instant. A browser that is already inside your application keeps working until your next check, a minute by default.
- A stolen device may hold the mailbox too. With sign-in links switched on, whoever can read the person's email can ask for a link and sign in again. For a lost device, sign the person out and refuse them in your application until their mailbox is safe again.