Charlie Joseph
Back to blog

Introducing Keyring

·3 min read

Robert Boes and I have just released Keyring, an open-source authentication package for Laravel. We built it because we were frustrated with Fortify.

Why Not Fortify?

Fortify is great for getting sign in and registration working quickly, but the more we leaned on it, the more we ended up building around it.

Two-factor is the obvious one. It's three two_factor_* columns on your users table, which means one authenticator app per user. Passkeys live in a separate package, and a security key or a backup authenticator app has nowhere to go, so every addition becomes another special case in your sign-in flow.

Then there's everything around signing in. Confirming before a sensitive action only ever asks for the password, even when the user has a passkey or authenticator app set up. Rate limiting is two named limiters you set up yourself. And there's no list of signed-in sessions, no "sign out everywhere else" and no emails telling users something changed on their account - every app ends up building those itself, slightly differently each time.

How Keyring Works

Instead of columns on users, Keyring splits authentication into three ideas. Factors are every way of proving who you are - a password, an authenticator app, a passkey. Authenticators are one user's instance of a factor, so someone can have two authenticator apps and three passkeys. Policies decide what each user has to prove.

Adding passkeys isn't a new flow, it's just another factor:

app/Providers/AppServiceProvider.php
Keyring::factors([
    Factors\Password::class,
    Factors\Totp::class,
    Factors\RecoveryCodes::class,
    Factors\WebAuthn::passkeys(),
]);
 
Keyring::require(
    Requirement::aal2()->ifEnrolled()->noDowngrade()
);

That policy asks for a second factor once a user has set one up, and noDowngrade() stops someone with a passkey being walked back to something weaker.

Out of the box you get sign in, registration, password resets and email verification, with rate limiting, session timeouts, security emails and a security log already switched on. Passkeys, signed-in devices and step-up that accepts a passkey or code rather than just a password are a config line away. It ships no UI - you build the screens with Inertia or Blade and Keyring handles everything behind them.

We built it against OWASP ASVS and NIST's authentication guidelines, and the docs map out each requirement, including the few places we deliberately went a different way.

Moving From Fortify

If you're already on Fortify, your users keep their passwords, authenticator apps, recovery codes and passkeys. One command brings it all across:

php artisan keyring:import fortify

Try It

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

It's early - v0.3.0 hasn't been tested in production yet, and the API may change before 1.0. That's exactly why we'd love people to try it now. The docs cover everything, there's an example app if you'd rather read code, and it's all MIT licensed on GitHub.

If you give it a go, I'd love to know what you think - message me on X at @chazza.