Getting StartedUpgrading From Fortify

Upgrading From Fortify

On this page

Introduction

Fortify is a PHP package, so there's no Fortify for Rust to upgrade from. This page is for a Laravel for Rust application that takes over users from a PHP application that used Fortify, sharing its database. The crate's keyring:import fortify reads Fortify's two-factor columns, and laravel/passkeys' passkeys, into Keyring's tables, as the PHP package's does.

Your users keep their passwords, authenticator apps, recovery codes and passkeys, with the PHP package's two caveats (passwords over 72 bytes on a bcrypt hash, and passwords typed in a form other than NFC), and one of the crate's own: an Ed25519 passkey is imported but can't sign in here. See Signature Algorithms.

Steps

  1. Add the crate and its provider, as Installation shows, with the sign-in methods your users already have: authenticator apps and recovery codes for Fortify's two factor, and passkeys for laravel/passkeys. They're all on by default. Use the PHP application's APP_KEY.

  2. Run the migrations, which create Keyring's tables beside Fortify's columns:

    Terminal
    cargo run -- migrate
  3. Import your two-factor data and passkeys. Run a dry run first:

    Terminal
    cargo run -- keyring:import fortify --dry-runcargo run -- keyring:import fortify

    The command exits non-zero if any factor couldn't be imported. Fix those before you go on. See Importing Two-Factor Data.

  4. Move your settings into KeyringConfig and the provider, using the tables below, and turn on the features you used.

  5. Point your frontend at the challenge page and the authenticator routes.

  6. Once everything works, drop Fortify's columns in a migration of your own.

Replacing Fortify in a Starter Kit

Laravel's starter kits are PHP. For a new Laravel for Rust application, start from Keyring's own starter kit instead, which has a page for every page Keyring renders, in React.

Importing Two-Factor Data

keyring:import fortify copies what the PHP package's does, with --dry-run, --unconfirmed and --fortify-confirm: each user's two_factor_secret into a totp authenticator, their two_factor_recovery_codes into a recovery authenticator as keyed hashes of the codes as Fortify showed them, and each laravel/passkeys row into a passkey authenticator. It only fills in users with no sign-in methods in Keyring yet, leaves a stand-in that keeps the user challenged when a secret can't be read, and never touches Fortify's columns or the passkeys table. The PHP docs describe each rule.

The crate's command differs in a few ways:

  • The table. It reads Fortify's columns from the user provider's table, as session_user_type names it, or the one --table names, and warns that it files every row under authenticatable_type when that's another table. It reads passkeys.user_id against the same table.
  • Keys. It decrypts with the application key, where the PHP package asks Fortify for its encrypter. If the PHP application used Fortify::encryptUsing(), import from the PHP side instead.
  • Confirmation. It can't read config/fortify.php, so pass --fortify-confirm=on or off when some users never confirmed their secret, or --unconfirmed to import them anyway.
  • Passkeys. One that can't sign in here, an Ed25519 key say, is still imported, since it may be the user's only method, and listed with the PHP package's warnings, naming KeyringConfig where they say config/keyring.php. It counts as refused when the crate couldn't verify with its key. An AAGUID is taken in its 36-character form alone.
  • Factors. There's no "Register … first" check, as the crate has passkeys unless factors.passkeys is off.

How Fortify Concepts Map

Configuration

Fortify Keyring
fortify.guard guard, and the session guard you register in with_auth
fortify.username username
fortify.lowercase_usernames Always on, unless the provider's normalize_usernames_using() says otherwise.
fortify.home home
fortify.prefix, fortify.domain prefix, domain
fortify.middleware Not available: wrap http::routes() in a group of your own.
fortify.passwords passwords.expire and passwords.throttle
fortify.views pages.enabled
fortify.limiters limits
Features::registration() and the rest features.registration, reset_passwords, email_verification and update_passwords
Features::updateProfileInformation() Not included. Keep your own profile route, and call protection::guard() in it.
Features::twoFactorAuthentication() factors.totp and factors.recovery_codes (on by default), features.manage_authenticators, and a policy.

Actions

Fortify Keyring
CreateNewUser A CreatesNewUsers given to create_users_using(): validation in validate(), without checking whether the address is taken, and saving in create().
ResetUserPassword A ResetsUserPasswords given to reset_user_passwords_using().
UpdateUserPassword An UpdatesUserPasswords given to update_user_passwords_using(). Keyring checks current_password itself.
PasswordValidationRules PasswordRules. See Password Rules.
UpdateUserProfileInformation Your own code, with email changes through a ChangesEmails and Keyring's flow.
Fortify::authenticateUsing() Your provider's find_for_login(). Keyring checks the password itself.
Fortify::confirmPasswordsUsing() Not needed. Step-up accepts any qualifying factor.

Views and Pages

The pages are the PHP package's, as its table maps them: login, register, forgot-password, reset-password, verify-email, email-verification, challenge and confirm. Rename one with pages.page().

Routes

The routes are the PHP package's, as its table maps them. There's no Laravel password.confirm middleware to keep working: use RequireFreshVerification.

Responses

Replace Keyring's responses with responses.respond_with(): Authenticated for Fortify's LoginResponse and TwoFactorLoginResponse, Registered, Logout, Challenge and Status. There's no FailedResponse or LockoutResponse: a refusal is laravel-rust's InvalidInput error. See Responses.

Events

The events map as in the PHP table, in laravel_keyring::events. Laravel's Login, Logout, Registered, Verified, Failed, Lockout and PasswordReset aren't dispatched, as laravel-rust has none of them.

Rate Limiting

Keyring limits every factor per account and per address inside the pipeline, using limits, as in the PHP package. There are no named limiters to define: the keyring limiter is limits.forms and limits.guest_forms. See Rate Limiting.

Things That Behave Differently

As the PHP docs list, plus:

  • A password change signs out every other session, whatever sign_out_others says.
  • Every feature starts off, and each needs its action on the provider.
  • Saving a user doesn't check protected attributes by itself: call protection::guard() where you save users.