v0.1.0Early releaseMIT

Authentication for Laravel that grows with your app.

Sign in, registration, password resets and email verification out of the box, growing into passkeys, authenticator apps, security keys, step-up, devices and sessions.

composer require keyring/keyring

HeadlessBuilt against OWASP ASVS 5.0.0 and NIST SP 800-63B-4See the example app

Sample pages. Keyring ships no UI: you build these with Inertia or Blade, and Keyring handles what happens behind them.

How it works

Every way in is a factor.

In most Laravel apps, two-factor is a few two_factor_* columns on users: one authenticator app per user, anything else bolted on. Keyring splits it into three parts, each a few lines of code.

app/Providers/KeyringServiceProvider.php
Keyring::factors([
    Factors\Password::class,
    Factors\Totp::class,
    Factors\RecoveryCodes::class,
    Factors\WebAuthn::passkeys(),
    // Factors\WebAuthn::securityKeys(),
    // Factors\EmailCode::asExtraStep(),
]);

Factors

Every way of proving who you are, behind one contract. Each line turns one on: passwords, authenticator apps, recovery codes and passkeys here, with security keys and email codes a line away.

Factors
SecurityController
// Signed in as priya@example.com
$user = $request->user();

$user->keyring->all();
Returns Priya's authenticators, default first, then by priority
  • passkeyPasskey MacBookDefault
  • totpAuthenticator app Phonepriority 60
  • passwordPassword kept on userspriority 40
  • recoveryRecovery codes 8 leftpriority 0

Authenticators

One user's instance of a factor. Priya can hold as many as each factor allows, so several apps or passkeys, but one set of recovery codes. The default is offered first, and “try another way” offers the rest that would help.

Authenticators
app/Providers/KeyringServiceProvider.php
Keyring::require(
    Requirement::aal2()
        ->ifEnrolled()
        ->noDowngrade()
);
What that asks of Priya
  • Asked forTheir passkeyAAL2
  • Another wayPassword, then a recovery codeAAL2
  • Not offeredPassword, then a code from the appnoDowngrade()

Policies

What each user has to prove, set once. Keyring works out the rest from their authenticators, with assurance levels AAL1 to AAL3 from NIST SP 800-63B-4. Priya has a passkey, so noDowngrade() keeps them off anything weaker.

Policies

The same line asks other users for other things. Try four of them below

Try the policy

Who gets asked for what

Keyring works out what each user has to show from what they've set up. Pick a user to see how they sign in under the policy from the quick start.

Sample users
Keyring::require(Requirement::aal2() ->ifEnrolled()->noDowngrade());

Reads as: ask for a second factor once a user has set one up, and if they have a passkey, don't let them fall back to something weaker.

Start small

Install it, then turn things on a line at a time.

Every sign-in method is already in your service provider and every feature is in your config, commented out. When you want one, uncomment it and build the page that goes with it.

Terminal
composer require keyring/keyring
php artisan keyring:install
php artisan migrate

A fresh install is password sign in, registration, password resets, email verification and password changes. Rate limits, password rules, session timeouts, a security log and security emails are on from the start.

  • Passkeys

    Users can add, rename and remove sign-in methods, with recovery codes alongside. Passkeys reach AAL2 on their own, and the policy is the one the demo above uses. Build the challenge and confirm pages and the part of your settings page that adds a method.

  • Signed-in devices

    A device cookie, "trust this device", a list of where users are signed in, and "this wasn't me" links. Build the device-report page the link opens.

  • Email changes

    Confirmed by the new address and undoable from the old one. Build the email-change page the emailed links open.

Features

Pages you build. Keyring does the work behind them.

Devices and sessions

Show each user where they're signed in and let them sign out everywhere else, on any session driver. Plus trusted devices, and new-device emails with a "this wasn't me" link.

Devices and sessions

Step-up

keyring:aal2 and keyring.fresh:15m middleware ask a signed-in user to prove themselves again before the pages that matter. A passkey or a code counts as well as the password.

Step-up

Protected account changes

With emailChanges() on, the new address always confirms an email change. The current address confirms too, unless the session proved a possession factor (not a recovery code) the account has had for 7 days. Either way, the old address can undo it.

Protected changes

Security log

A record of every sign in, failure and change, each with a severity: info, notice, warning or critical. Show it on an activity page, and users see a "was this you?" alert for the entries worth asking about.

Security log and emails
Behind the scenes

What Keyring handles

Some of the work has no page to build. Rate limits, session timeouts, risk checks and security emails are on from the first install, and you can change their numbers in config/keyring.php.

config/keyring.php
'timebox' => '500ms',

'limits' => [
    'per_account' => 5,
    'per_ip' => 20,
    'consecutive' => 100,
    'consecutive_elsewhere' => 80,
    'longest_lock' => '24h',
    'longest_ip_lock' => '15m',
    'lock_after' => null,
    'codes' => 3,
    'codes_per' => '10m',
    // ...
],

Limits on guessing, with room for the owner.

Five attempts a minute per account and 20 per IP address. Each lock lasts twice as long as the one before, up to a day. After 100 failures in a row, the most NIST SP 800-63B-4 allows, that authenticator is refused until it's reset or set up again.

With devices on, browsers the account has signed in from before keep their own count, so guesses from elsewhere can't lock the owner out of a browser they already use. Refusals take at least 500ms, so timing doesn't reveal whether an account exists.

Extending

Bring your own factors, change the defaults

Factors are drivers, so SMS codes, push or a hardware token plug in without new routes, controllers or tables.

Extending Keyring\Factors\Factor gives you defaults for everything except key, categories and verify.

Config, migrations, a service provider, actions and notifications are published into your app. The rest stays in the package, so it keeps receiving fixes.

Extending Keyring
class HardwareToken extends Factor
{
    public function key(): string
    {
        return 'hardware-token';
    }

    public function categories(Authenticator $authenticator): array
    {
        return [Category::Possession];
    }

    public function verify(
        Attempt $attempt,
        Authenticator $authenticator,
        Request $request,
    ): ?Verification {
        // check the posted code...
        return $valid ? $this->verified($authenticator) : null;
    }
}
  • Keyring::require()The policy
  • Keyring::pipeline()The steps a verification goes through
  • Keyring::page()What a page renders
  • Keyring::respondWith()Every response
  • Keyring::notifications()Every email
  • Keyring::findUsersUsing()How users are found
  • app/Actions/KeyringPublished actions, yours to edit
  • config/keyring.phpAny number, lifetime or limit
Standards

Mapped to the standards, requirement by requirement.

Written against OWASP ASVS 5.0.0 and NIST SP 800-63B-4. The docs go through every applicable ASVS requirement and mark each one, with the reason. A few of them:

  • 6.2.10No periodic rotationMet
  • 6.3.6Email isn't an authentication factorMet by default
  • 6.2.9Passwords of at least 64 characters are permittedDeviates
  • 6.4.4A lost factor is recovered with identity proofingYours
Read the ASVS mapping
Coming from Fortify

Your users keep what they've set up.

One command copies the two_factor_* columns and the laravel/passkeys table across, so users keep their authenticator apps, recovery codes and passkeys. A few exceptions, like unconfirmed two-factor setups, are listed in the upgrade guide.

php artisan keyring:import fortify
Upgrading from Fortify
v0.1.0, early release

Still early.

v0.1.0 hasn't been tested in production yet. Until 1.0, a minor release can change the API.

Found a security issue? Please follow the security policy rather than opening a public issue.

Security policy

Try it in a side project first.

Start with passwords today. Passkeys, security keys and signed-in devices are a line or two away when your app needs them.