Getting StartedQuick Start

Quick Start

On this page

Introduction

This page takes a Laravel for Go application to a working sign-in: the install, the pages to build, your settings page, and the features and sign-in methods to add next.

Signing in with a password, signing out, challenges and step-up are always on. Unlike the PHP package, registration, resets, password changes, email verification and email changes start off, since they run code of yours or need your user type to verify addresses. The security log is on.

Installing

The quickest way in is the starter kit: a Laravel for Go application with Inertia, React, TypeScript and Tailwind CSS on SQLite, with a page for every page Keyring renders but the sign-in-link page (which only matters with WithLink() on), settings pages for the email address, the password, sign-in methods, and sessions and devices, and a second factor required of everyone. Copy go/starter-kit out and follow its README:

Terminal
go run . key:generatego run . migratebun installbun run buildgo run .

To add Keyring to an application of your own, add the keyringauth.com/go module:

Terminal
go get keyringauth.com/go@latest

Then list Keyring in your packages, with the actions for the features you turn on:

Go
k := keyring.New[models.User](func(cfg *keyring.Config) {	cfg.Features.Registration = true	cfg.Features.ResetPasswords = true	cfg.Features.EmailVerification = true	cfg.Features.UpdatePasswords = true}).	CreateUsersWith(actions.CreateNewUser{}).	ResetPasswordsWith(actions.ResetUserPassword{}).	UpdatePasswordsWith(actions.UpdateUserPassword{}) return laravel.Options{	Packages: []laravel.Package{k},	Middleware: func(m *laravel.Middleware, _ *config.Config) {		m.Web.Append(inertia.Middleware{})	},	// ...}

models.User is your user type, and the three actions are yours: see Installation and Registration. The contract app's actions are the PHP package's stubs written in Go, ready to copy. Keyring brings its migrations, so run go run . migrate.

With Features.EmailVerification on, your user type needs an EmailVerifiedAt field, as a new Laravel for Go application's has. That keeps the registration form from revealing who has an account, since a new user stays signed out until they verify their address.

Note

New users can't sign in until they follow the verification link, so your app must send mail. With MAIL_MAILER=log, the link is written to the log.

Your Pages

Keyring handles the requests, and you build the pages. It renders them as the Inertia components auth/{page}, so they live in resources/js/pages/auth/. For a frontend Laravel for Go doesn't serve, see Headless Frontends. The starter kit has every page in React. Build the pages for the features you turn on:

Page When It's Needed
login Always.
challenge When you add a second sign-in method. It asks for the next factor.
confirm For step-up, which changing the password and adding sign-in methods use. It may render the same component as challenge.
register With Features.Registration. Posts name, email, password and password_confirmation to /register, or whatever your CreatesNewUsers reads.
forgot-password, reset-password With Features.ResetPasswords.
verify-email With Features.EmailVerification, for a signed-in user who hasn't verified. Only needed if you set Registration.RevealTaken.
email-verification With Features.EmailVerification. The verification link opens it, with one button. Only needed if you set Registration.RevealTaken.
email-change With Features.EmailChanges. The confirm and undo links open it.
device-report With Features.Devices. The "this wasn't me" link opens it.
sign-in-link With keyring.EmailCodesAsExtraStep().WithLink(). The link beside the code in the sign-in email opens it. See Signing In From the Email.

The login form posts email, password and an optional remember field to /login. Signed-in users go to Home, which is /dashboard by default (KEYRING_HOME). Every page's props are in Pages, and they're the PHP package's.

Your Settings Page

Users manage their sign-in methods on a settings page you build, at any URL. Keyring doesn't register one. Your handler passes in what the page shows, and the page calls Keyring's routes to make changes. SignInMethods gives what such a page needs:

Go
package routes import (	"go.laravel.com/auth"	"go.laravel.com/config"	"go.laravel.com/inertia"	"go.laravel.com/routing"	"go.laravel.com/web" 	keyring "keyringauth.com/go" 	"app/models") func Web(route *routing.Router, _ *config.Config) {	route.Middleware(keyring.RequireFreshVerification[models.User]{}).Group(func(route *routing.Router) {		route.Get("/settings/security", security)	})} func security(r *web.Request) *web.Response {	user := auth.User[models.User](r)	methods, err := keyring.From[models.User](r).SignInMethods(r, user)	if err != nil {		return web.Fail(err)	} 	return inertia.Render("settings/security", inertia.Props{"methods": methods})}
Prop Contents
methods.authenticators The user's sign-in methods, with factor, id, name, createdAt, lastUsedAt (ISO 8601), isDefault, and frozen when the freeze holds one. Email codes add a masked hint; recovery codes add remaining and replace. The password has no row, so it's left out.
methods.enrollable The factors a user may add, such as totp and passkey. Recovery codes only once the account has a factor for them to stand in for.
methods.passwordToAdd Those that take the current password to add.
methods.frozen, methods.hasSecondFactor The freeze, and whether the account has a second factor.

There's no recent activity to show beside them yet: the PHP package's Keyring::activity() isn't ported. See Differences From PHP.

The page then uses /user/authenticators, /user/devices, /user/sessions, PUT /user/password and POST /user/email. The browser package wraps the authenticator routes. There's no devices list to pass in: the page loads GET /user/devices itself.

Routes that change something need a fresh verification, which lasts 15 minutes by default. Listing doesn't. Put RequireFreshVerification on the page's route, as above, so users confirm once when it opens.

Signing in counts as a verification. If the page stays open longer, the next JSON request gets a 423 response with a redirect to the confirm page. Send the browser there. Once the user confirms, Keyring returns them to the page to try again. The Handling Step-Up in JavaScript section has the code.

Testing

Laravel for Go's laraveltest drives Keyring's routes like any others. The keyringtest package adds the rest: keyringtest.New[models.User](t, client) has refused checks answer at once rather than waiting out Config.Timebox, and gives kt.ActingAs for a session at an assurance level, kt.Fake() to pass or fail factors without real codes, and kt.Add for authenticator rows. keyringtest.Conformance checks that your setup keeps Keyring's guarantees. See Testing.

Adding Features

Features are bools in Config.Features, and each adds its routes only once it's on. Set them one at a time: assigning the whole struct leaves SecurityLog off, which turns the security log's table off.

Go
cfg.Features.Registration = truecfg.Features.ResetPasswords = truecfg.Features.EmailVerification = truecfg.Features.UpdatePasswords = truecfg.Features.ManageAuthenticators = truecfg.Features.Devices = truecfg.Features.EmailChanges = truecfg.Features.Impersonation = true
Feature What It Adds Documentation
Registration /register, through your CreatesNewUsers, given with CreateUsersWith. Needs EmailVerification unless Registration.RevealTaken is on. Registration
ResetPasswords Forgot and reset password, through your ResetsUserPasswords, given with ResetPasswordsWith. Resetting the Password
EmailVerification The verification routes, and the verify-email and email-verification pages. Needs an EmailVerifiedAt field on the user type. Email Verification
UpdatePasswords PUT /user/password, through your UpdatesUserPasswords, given with UpdatePasswordsWith. The password becomes protected. Changing the Password
ManageAuthenticators Adding, renaming and removing sign-in methods. Required for users to set any up. Managing Authenticators
Devices A device cookie, "trust this device", the list of signed-in devices, and "this wasn't me" links. Devices & Sessions
EmailChanges Email changes, confirmed from both addresses, through your ValidatesEmailChanges, given with ValidateEmailChangesWith. The address becomes protected. Protected Changes
Impersonation POST /impersonate/{user} and POST or DELETE /impersonate. Nobody may impersonate until you give Keyring AllowImpersonationWhen. Impersonation
SecurityLog The security log in keyring_events. On by default. Security Log & Emails

Single sign-on is Factors.SingleSignOn, with providers in SSO.Providers. See Single Sign-On.

A few settings live outside the list:

  • Security emails: sent from the start, queued, so run a queue worker or use the sync queue. Notifications.Off lists those to leave out.
  • Risk signals: added with RiskSignals, which starts with none. When you turn on devices, add keyring.NewDevice{} and keyring.InactiveAccount{}.
  • Support contact: SupportContact sets who the security emails tell users to contact.
  • Second factor requirement: the RequireEnrollment middleware, with EnrollmentURL set to your page for adding one.

Adding Sign-In Methods

The password, authenticator apps, recovery codes and passkeys are on by default. The PHP package's Keyring::factors() with nothing listed has the password alone. Email codes are opt in, and security keys aren't ported yet:

Go
k := keyring.New[models.User](func(cfg *keyring.Config) {	cfg.Factors.EmailCodes = keyring.EmailCodesAsExtraStep()}).Require(func(_ context.Context, _ *models.User, _ keyring.Attempt) keyring.Requirement {	return keyring.AAL2.Requirement().IfEnrolled().NoDowngrade()})

Set Factors.Passkeys to false to leave passkeys out. See Registering Factors.

AAL is NIST's authenticator assurance level, a scale for how strongly a session was proved. A password alone is AAL1. A password plus an authenticator app, or a passkey on its own, reaches AAL2. See Assurance Levels.

IfEnrolled() asks for a second factor once a user has one, and is the default policy. NoDowngrade() stops a user with an established passkey, one held for 7 days by default, from being talked into something weaker.

To finish:

  1. Turn on Features.ManageAuthenticators.
  2. Build the challenge and confirm pages, and the part of your settings page that adds and removes methods.
  3. To require a second factor for everyone, append RequireEnrollment to the web group and set EnrollmentURL. See Requiring a Second Factor.

For Google, Microsoft, GitHub or another identity provider, turn on Factors.SingleSignOn and list them in SSO.Providers. See Single Sign-On.

What Keyring Does Without Being Asked

These protections are on by default, as in the PHP package:

Protection Default How to Change It
Sign-in rate limits 5 a minute per account, 20 per IP address. After 100 failures in a row, a method is refused until a password reset, Unlock, or removing and re-adding the second factor. Limits in Configuration
Refused checks take at least 500ms 500ms Timebox in Configuration
Registration answers the same for taken and free addresses Enabled Registration.RevealTaken
Password rules 15 characters without a second factor, 8 with one. Common passwords, and ones built from the user's name or email or your app's name, are refused. Breached passwords are refused in production. Your actions check with PasswordRules. Password Rules
Sessions are recorded with IP address and browser Sessions end after 2 hours idle, or 30 days after sign-in. "Remember me" returns a browser for up to 14 days away. Sessions in Configuration
Assurance levels lapse, as NIST recommends AAL2 lapses after 1 hour idle or 24 hours. AAL3 lapses after 15 minutes idle or 12 hours. Sessions.Levels
Browsers clear cache and storage on sign out Enabled Not changeable in Keyring for Go. See Responses.
Step-up middleware RequireAssurance and RequireFreshVerification Step-Up