Extending Keyring
On this page
Introduction
Once the package is in laravel.Options.Packages and the migrations have run, Keyring works. Most of what it does is yours to change, through keyring.Config, the hooks on *keyring.Keyring[U], and the code your app owns: your user type, your auth.Users and your actions. Nothing is published, so the package 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 | Config.Features |
Adding Features |
| Any number, lifetime or limit | keyring.Config |
Configuration |
| How users sign in | Config.Factors (EmailCodes, Passkeys, SingleSignOn and the TOTP settings), Config.WebAuthn, and Keyring.AddCodeFactor |
Factors |
| Primary factors of your own | Keyring.AddPrimaryFactor, with your own IdentifiesUsers |
Primary Factors |
| What they must prove | Keyring.Require |
Policies |
| The steps a verification runs | Keyring.Pipeline |
The Verification Pipeline |
| Signing in with Google, Microsoft, GitHub or OpenID Connect | Config.Factors.SingleSignOn and Config.SSO.Providers |
Single Sign-On |
| An identity provider Keyring has no driver for, or a change to one it has | Config.SSO.Extend, your own IdentityProvider |
Custom Drivers |
| Signing in from a route of your own | Keyring.Attempt, Keyring.AttemptSSO and Keyring.SignInAs |
Starting a Sign In Yourself |
| How a user is found | Your auth.Users given to Keyring.FindUsersWith, and its FindForLogin |
Finding the User |
| The field users sign in with, and the one holding their address | Config.Username and Config.Email |
Guard and Users |
| Creating users, resetting and changing passwords, changing the address | Your CreatesNewUsers, ResetsUserPasswords, UpdatesUserPasswords and ValidatesEmailChanges, given with CreateUsersWith, ResetPasswordsWith, UpdatePasswordsWith and ValidateEmailChangesWith |
Protected Changes |
| Every email: wording, template, or whether it's sent | Config.Notifications: Off, Mail and AccountMail, and Factors.EmailCodes.Mail |
Security Emails |
| What a page renders | Not available: your Inertia components, under auth/ |
Pages |
| What Keyring answers with | Not available | Responses |
| Validation and status messages | Not available: English only | Messages and Translations |
| The route prefix | Config.Prefix |
Routes |
| What account changes ask for first | Config.ChangesMiddleware |
Account Changes and Enrollment |
| Starting an impersonation: what it takes, how long it lasts, whether the user sees it | Config.Impersonation |
Impersonation |
| The form rate limits | Config.Limits |
Rate Limits |
| Who may sign in at all | Keyring.AllowSignInWhen |
Who May Sign In |
| Who may add a sign-in method | Keyring.AllowEnrollmentWhen |
Who May Enroll |
| Who may impersonate whom | Keyring.AllowImpersonationWhen |
Who May Impersonate Whom |
| Whether registration says when an address is taken | Config.Registration.RevealTaken |
Registration |
| Risk signals and what they do | Keyring.RiskSignals, Keyring.RespondToRisk, your own Signal |
Risk |
| Where a request is located | Config.Devices.Locator, your own LocatesIPs |
Locations |
| How a browser is described | Config.Devices.Describe |
Device Names |
Whether Keyring checks sessions on the web group |
Config.Sessions.Middleware |
The Session Middleware |
| Routes of your own that take the session lock | keyring.BlockSession on the route |
Requests That Overlap a Sign In |
| Where emailed links start | Config.LinkRoot |
Emailed Links |
| Which attributes are protected | Config.Protected, Keyring.GuardChanges and Keyring.WithoutProtection |
Protected Changes |
A few rows of the PHP table have no Go counterpart yet: whose key attestation is trusted (only none attestation is checked), where sessions are registered (always the database), and what's stored as an IP address (always r.IP()). See Differences From PHP.
The account features start off, and Keyring.RiskSignals starts with none. Features.SecurityLog and Factors.Passkeys start on. The security emails are Keyring's own, and are sent from the start.
Replacing a Controller or Service
Not available: Keyring's handlers and services aren't values you can swap. Use the settings and hooks above, and the methods on *keyring.Keyring[U] for your own routes, such as SignInMethods, RequirePasswordChange, PendingEmailChange, Record, PullAlerts, Unlock, Impersonate and WithoutProtection. Reach it from a request with keyring.From[models.User](r). For a route that should work differently, register your own at another path and call those, or turn Config.Routes off and register Keyring's with Keyring.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
Config.Prefix covers most changes. To register the routes inside a group of your own, for middleware, set Config.Routes to false and call k.Routes(route) inside that group. Keep it in the web group, since several routes take the session lock, which needs it. Keyring adds the prefix itself, so set it in the config, not on the group. There's no domain setting and 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. EnsureNotThrottled, VerifyFactor and CompleteAttempt can't be changed even dangerously, and your steps only go between the last two.
Keyring also needs a user type with an integer ID, an Email, a Password and a RememberToken, which Register checks, Laravel Go's session guard, and one user type per application. The form field names, the paths, the route names and the status slugs are fixed, as the browser package relies on them.