# Upgrading From Fortify

Source: https://keyringauth.com/docs/0.x/go/upgrading-from-fortify

## Introduction

Fortify is a PHP package, so there's no Fortify for Go to upgrade from. This page is for a Laravel for Go application that takes over users from a PHP application that used Fortify, sharing its database.

Your users keep their passwords, as long as they're bcrypt hashes: Laravel for Go checks no other kind. The PHP package's two caveats still apply (passwords over 72 bytes on a bcrypt hash, and passwords typed in a form other than NFC). Their authenticator apps, recovery codes and passkeys come over too: Keyring for Go's `keyring:import fortify` reads Fortify's two-factor columns, and `laravel/passkeys`' passkeys, into Keyring's tables, as the PHP package's does.

## Steps

1. Add Keyring for Go, as [Installation](https://keyringauth.com/docs/0.x/go/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:

   ```bash
   go run . migrate
   ```

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

   ```bash
   go run . keyring:import fortify --dry-run
   go 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](https://keyringauth.com/docs/0.x/go/upgrading-from-fortify#importing-two-factor-data).

4. Move your settings into `keyring.Config` and the `*Keyring`, using the tables below, and turn on the features you used.

5. Point your frontend at the [challenge page](https://keyringauth.com/docs/0.x/go/sign-in-flow#the-challenge-page) and the [authenticator routes](https://keyringauth.com/docs/0.x/go/authenticators).

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 Go application, start from Keyring's own [starter kit](https://github.com/keyringauth/keyring/blob/main/go/starter-kit/README.md) instead, which has a page for every page Keyring renders but the sign-in-link page (which only matters with `WithLink()` on), 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. It reads from the database's writer, not a read replica. The [PHP docs](https://keyringauth.com/docs/0.x/upgrading-from-fortify#importing-two-factor-data) describe each rule.

The Go command differs in a few ways:

- **The table.** It reads Fortify's columns from the table `SessionUserType` names, or the one `--table` names, and warns that it files every row under `AuthenticatableType` when that's another table. It reads `passkeys.user_id` against the same table. A table without `two_factor_recovery_codes` or `two_factor_confirmed_at` reads them as null.
- **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. Without either, such a user counts as failed.
- **Recovery codes.** They must decrypt to a JSON list of strings. Anything else counts as failed, with a stand-in left in their place.
- **Passkeys.** One that can't sign in here, an RS256 key while `WebAuthn.Algorithms` leaves it out say, is still imported, since it may be the user's only method, and listed with the PHP package's warnings, naming `WebAuthn.Algorithms` and `WebAuthn.MinimumRSABits` where they name `config/keyring.php`. It counts as refused when Keyring for Go couldn't read its key or wouldn't take it.
- **Factors.** With rows in `passkeys`, it refuses to run until `Factors.Passkeys` is on, as the PHP package asks you to register passkeys first. Passkeys are on unless you turned them off.

## How Fortify Concepts Map

### Configuration

| Fortify | Keyring |
|---|---|
| `fortify.guard` | `Guard`, which only names Laravel for Go's one session guard |
| `fortify.username` | `Username` |
| `fortify.lowercase_usernames` | Always on. |
| `fortify.home` | `Home` |
| `fortify.prefix` | `Prefix` |
| `fortify.domain` | Not available. |
| `fortify.middleware` | Not available: turn `Routes` off and call `Routes()` in a group of your own. See [Routes](https://keyringauth.com/docs/0.x/go/configuration#routes). |
| `fortify.passwords` | `Passwords.ResetLinkFor` and `Passwords.ResetThrottle` |
| `fortify.views` | `Pages` |
| `fortify.limiters` | `Limits` |
| `Features::registration()` and the rest | `Features.Registration`, `ResetPasswords`, `EmailVerification` and `UpdatePasswords` |
| `Features::updateProfileInformation()` | Not included. Keep your own profile route, with `GuardChanges` in the user model's `Updating` hook. |
| `Features::twoFactorAuthentication()` | Authenticator apps and recovery codes (on by default), `Features.ManageAuthenticators`, and a [policy](https://keyringauth.com/docs/0.x/go/policies). |

### Actions

| Fortify | Keyring |
|---|---|
| `CreateNewUser` | A `CreatesNewUsers` given to `CreateUsersWith()`: validation in `Validate()`, without checking whether the address is taken, and saving in `Create()`. |
| `ResetUserPassword` | A `ResetsUserPasswords` given to `ResetPasswordsWith()`. |
| `UpdateUserPassword` | An `UpdatesUserPasswords` given to `UpdatePasswordsWith()`. Keyring checks `current_password` itself. |
| `PasswordValidationRules` | `PasswordRules`. See [Password Rules](https://keyringauth.com/docs/0.x/go/protected-changes#password-rules). |
| `UpdateUserProfileInformation` | Your own code, with email changes through a `ValidatesEmailChanges` and Keyring's flow. |
| `Fortify::authenticateUsing()` | Your `auth.Users`, given to `FindUsersWith()`. Keyring checks the password itself. |
| `Fortify::confirmPasswordsUsing()` | Not needed. Step-up accepts any qualifying factor. |

The [contract app's actions](https://github.com/keyringauth/keyring/tree/main/go/contract-app/actions/) are Keyring's PHP stubs written in Go.

### Views and Pages

The pages are the PHP package's, as its [table](https://keyringauth.com/docs/0.x/upgrading-from-fortify#views-and-pages) maps them: `login`, `register`, `forgot-password`, `reset-password`, `verify-email`, `email-verification`, `challenge` and `confirm`. They're always the Inertia components `auth/{page}`.

### Routes

The routes are the PHP package's, with the same names, as its [table](https://keyringauth.com/docs/0.x/upgrading-from-fortify#routes) maps them. There's no Laravel `password.confirm` middleware to keep working: use `RequireFreshVerification`.

### Responses

There's no way to replace Keyring's responses yet, so there's nothing in place of Fortify's `LoginResponse`, `TwoFactorLoginResponse` and the rest. A refusal is Laravel for Go's validation error. See [Responses](https://keyringauth.com/docs/0.x/go/sign-in-flow#responses).

### Events

The events map as in the [PHP table](https://keyringauth.com/docs/0.x/upgrading-from-fortify#events), as Keyring's own event types, such as `keyring.Authenticated[U]`. Laravel for Go dispatches none of Laravel's `Login`, `Logout`, `Failed` or `Lockout`. Keyring dispatches its own `Registered[U]`, `Verified[U]`, `PasswordReset[U]` and `PasswordChanged[U]` in their place. See [Events](https://keyringauth.com/docs/0.x/go/events).

### 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.GuestForms`. See [Rate Limiting](https://keyringauth.com/docs/0.x/go/security#rate-limiting).

## Things That Behave Differently

As the [PHP docs](https://keyringauth.com/docs/0.x/upgrading-from-fortify#things-that-behave-differently) list, plus:

- **A password change ends every other session**, whatever `sign_out_others` says, since Laravel for Go's guard signs out every session made with the old password anyway.
- **Registration, resets, email verification, password changes and email changes start off**, and each needs its action.
- **Saving a user doesn't check protected attributes by itself**: call `GuardChanges` from the user model's `Updating` hook, and before any write that doesn't go through the model.
- **Argon2 passwords can't be checked.** Laravel for Go checks bcrypt alone.
