Extending Keyring
On this page
Introduction
Once the provider is added and the migrations have run, Keyring works. Most of what it does is yours to change, through settings, hooks on the provider, and the code your app owns: your user provider and your actions. Nothing is published, so the crate keeps getting fixes.
Start with the table below. The Recipes page has worked examples of common changes.
What You Can Change
| To Change | Use | See |
|---|---|---|
| Which features are on | features |
Adding Features |
| Any number, lifetime or limit | KeyringConfig |
Configuration |
| How users sign in | factors, email_codes, webauthn, and the provider's code_factor(), second_factor() and primary_factor() |
Factors |
| What they must prove | policy, or the provider's policy() |
Policies |
| The steps a verification runs | The provider's pipeline() |
The Verification Pipeline |
| Signing in with Google, Microsoft, GitHub or OpenID Connect | features.sso and sso.providers |
Single Sign-On |
| An identity provider Keyring has no driver for, or a change to one it has | sso.extend(), your own IdentityProvider |
Custom Drivers |
| Signing in from a route of your own | sign_in::attempt() and sign_in::as_user() |
Starting a Sign In Yourself |
| How a user is found, and how usernames are normalised | Your provider's find_for_login(), and the provider's normalize_usernames_using() |
Finding the User |
| The field users sign in with, and the one holding their address | username and email |
Guard and Users |
| Creating users, resetting and changing passwords, changing the address | Your CreatesNewUsers, ResetsUserPasswords, UpdatesUserPasswords and ChangesEmails |
Protected Changes |
| Every email: wording, template, or whether it's sent | notifications: turn_off(), mail(), mail_using and the flow emails' methods |
Security Emails |
| What a page renders | pages.page() and pages.render_using() |
Pages |
| What Keyring answers with | responses.respond_with() and http::KeyringResponse |
Responses |
| Validation and status messages | Not available: English only | Messages and Translations |
| The route prefix and domain | prefix and domain |
Routes |
| How recent a verification account changes need | changes_fresh_for |
Account Changes and Enrollment |
| Starting an impersonation: what it takes, how long it lasts, whether the user sees it | impersonation |
Impersonation |
| The form rate limits | limits |
Rate Limits |
| Who may sign in at all | The provider's allow_sign_in_when() |
Who May Sign In |
| Who may add a sign-in method | The provider's allow_enrollment_when() |
Who May Enroll |
| Who may impersonate whom | The provider's allow_impersonation_when() |
Who May Impersonate Whom |
| Whether registration says when an address is taken | registration.reveal_taken |
Registration |
| Whether registering signs the user in | The provider's sign_in_after_registering() |
Saying When an Address Is Taken |
| Risk signals and what they do | risk.signals, risk.respond, your own Signal |
Risk |
| Where a request is located | devices.locator, your own LocatesIps |
Locations |
| Whose key attestation is trusted | webauthn.attestation_roots, your own TrustsAuthenticators |
Passkeys & Security Keys |
| How a browser is described | devices.describe_using() |
Device Names |
| Where sessions are registered | sessions.driver, sessions.extend(), your own SessionRegistry |
Writing a Driver |
Whether Keyring checks sessions on the web group |
sessions.middleware |
The Session Middleware |
| Routes of your own that take the session lock | sessions.block |
Requests That Overlap a Sign In |
| What's stored as an IP address | record_ips_using |
What's Stored |
| Where emailed links start | The provider's link_root_using() |
Emailed Links |
| Which attributes are protected | protected, protection::without_protection() |
Protected Changes |
Every feature is off until you turn it on, and risk.signals starts empty. The security emails are Keyring's own, and are sent from the start.
Replacing a Controller or Service
Not available: the crate's handlers and services aren't types you can swap through the container. Use the settings and hooks above, and the services the crate exposes for your own routes: Sessions, StepUp, SessionAssurance, UserKeyring, sign_in, impersonation, sso, security_log and protection. For a route that should work differently, register your own at another path and call those, or turn routes off and register Keyring's with http::routes().
There's no Detours to override: the page a user was going to is saved for a page the browser navigated to, as in the PHP package. See Differences From PHP.
Changing the Routes
prefix and domain cover most changes. To register the routes inside a group of your own, for middleware, set routes to false and call http::routes::<Users>(route, &config) inside that group. Set the prefix and domain in the config, not on the group, as Keyring builds its URLs from them. There's no routes file to copy. See Routes.
What Stays Fixed
As in the PHP docs: email codes are only the extra step, a user can't remove their last way to sign in, an email change is confirmed from the new address and announced to the old one, trusting a device takes a real second factor, the pipeline's mandatory steps can only be changed dangerously, and emailed links are never built from the request's host.
Keyring also needs a user provider with integer IDs and laravel-rust's session guard, and one user type per application. The form field names, the paths and the status slugs are fixed, as the browser package relies on them.