# Special Considerations for User Migrations

Learn how to migrate refresh tokens and SAML configuration, import very large numbers of users, and keep applications working with the old system's tokens.

> For the index of this section of the site, see [llms.txt](https://fusionauth.io/docs/llms.txt)

Some migrations move more than users. This page covers data and dependencies that need extra planning. For the overall process, see [Plan a Migration](https://fusionauth.io/docs/migrate/plan-a-migration.md).

## Migrate Refresh Tokens

Token-based systems often pair short-lived access tokens with long-lived refresh tokens, so users don't log in again for every new access token. Import the old refresh tokens to keep users logged in after the cutover. At the next access token expiry, each client presents its refresh token to FusionAuth, and FusionAuth issues a new access token.

Refresh token import applies only to bulk migrations. A slow migration issues a new refresh token at each user's first login. For more information, see the [Import Refresh Tokens API](https://fusionauth.io/docs/apis/users/import-refresh-tokens.md).

JWTs from the old system can keep working, especially for APIs, when token producers and consumers share the signing keys. Import the old keys with the [Keys API](https://fusionauth.io/docs/apis/keys.md), or let clients look up keys from both systems at a [JSON Web Key Set (JWKS) endpoint](https://fusionauth.io/docs/apis/oauth/jwks.md).

## Migrate SAML Configuration

Your old system may act as a SAML Service Provider (SP) for upstream SAML Identity Providers (IdPs). This setup is common when each customer organization has a SAML IdP that is the system of record for the organization's users. After the migration, FusionAuth becomes the SP, so every upstream IdP configuration that points at the old SP must change.

Choose one of the following approaches.

### Update the Upstream Configuration

Ask each upstream IdP's administrators to point their configuration at FusionAuth instead of the old SP. Load the IdPs' certificates in advance with [Key Master](https://fusionauth.io/docs/security/tokens-and-keys/key-master.md) or the APIs. Configure each [SAMLv2 Identity Provider](https://fusionauth.io/docs/authentication/identity-providers/overview-samlv2.md) in FusionAuth with the same values as the old SP, such as the audience.

FusionAuth recommends this approach. Add time for communication and testing to the migration plan.

### Relax the Destination Assertion

Available since `1.43.0`

Each upstream IdP must change its [Assertion Consumer Service](https://fusionauth.io/docs/authentication/identity-providers/overview-samlv2.md) (ACS) URL to FusionAuth's URL. IdP administrators may not prioritize the change, and your applications can't move to FusionAuth until the IdPs send SAML responses to the new ACS URL. To move sooner, let FusionAuth accept [SAML assertions](https://fusionauth.io/docs/authentication/act-as-an-idp/host-saml-idp.md) addressed to the old SP:

1.  Load the IdPs' certificates in advance, and tell the IdP administrators that they need to update their ACS URLs eventually.
2.  Configure a [SAMLv2 Identity Provider](https://fusionauth.io/docs/authentication/identity-providers/overview-samlv2.md) with the same values as the old SP.
3.  In the Admin UI, navigate to Identity Providers -> Your SAMLv2 Identity Provider -> Options .
4.  Set **Destination assertion policy** to `Allow alternates`, and add the old SP's ACS URL to **Alternate destinations**. FusionAuth then accepts a SAML response whose **Destination** is FusionAuth's ACS URL or one of the alternates.
5.  Redirect the old ACS URL to FusionAuth's ACS URL with a proxy, such as nginx.
6.  Point your applications at the FusionAuth hosted login pages. To skip the login page and send users straight to the IdP, use an `idp_hint`.
7.  Shut down the old SP, since all traffic now goes through FusionAuth.

Caution

`Allow alternates` weakens SAML security. Keep the list of alternate destinations as short as possible, and work with the IdP administrators to point their configuration at FusionAuth's ACS URL soon.

After every upstream IdP points at FusionAuth's ACS URL, set **Destination assertion policy** back to `Enabled`, the most secure setting. For more information, see [SAMLv2 Identity Providers](https://fusionauth.io/docs/authentication/identity-providers/overview-samlv2.md).

## Migrate Large Numbers of Users

Migrating tens or hundreds of millions of users takes more time and planning than migrating a thousand. For guidance on a specific migration, [contact FusionAuth](https://fusionauth.io/contact.md).

Load the data in phases, each with its own goal. Start with a local FusionAuth instance, which iterates fast:

*   Confirm that the hashing scheme, salt, and factor work. Load a test user, and log in with the user's known password.
*   Set **`validateDbConstraints`** to `true`, so the Import Users API reports constraint violations, such as duplicate usernames in one Tenant.
*   Confirm the JSON structure, the profile data, the Group memberships, and the Registrations.
*   Drop the database after each test load. Dropping the database is faster than deleting a Tenant.

When the data loads cleanly, test against production or a production replica. A test environment with less CPU, memory, or network bandwidth gives misleading timings. Load a subset of 100,000 or 1,000,000 users into a separate Tenant to estimate the total time.

Note

Deleting a test Tenant takes at least as long as loading the Tenant. Plan for the deletion in the timeline. For more information, see the [GitHub issue](https://github.com/FusionAuth/fusionauth-issues/issues/2151).

With the estimate, split the users into groups, such as 1, 5, or 10 million users per group. To tune the import, see [Tune Performance](https://fusionauth.io/docs/migrate/bulk-migration.md#tune-performance).

### Import to FusionAuth Cloud

On FusionAuth Cloud, the following also apply:

*   You can't run import code inside the FusionAuth Cloud network. To reduce latency, run the code on an EC2 instance in the same AWS region.
*   Give the FusionAuth team a static IP address to allow-list, so FusionAuth doesn't rate-limit your requests.
*   A `429` status code means FusionAuth rate-limited the request. Confirm that the requests come from the allow-listed IP address.
*   A `504` status code means the import exhausted the deployment's resources. Increase the deployment size, or pause between requests.

### Handle Changes During a Long Import

When a full load takes days, users sign up and change profiles during the load. Split the load by timestamp:

1.  Complete the local tests with most of your users.
2.  Record the current time as `BULK_TIMESTAMP`.
3.  Load every user last modified before `BULK_TIMESTAMP`.
4.  Load every user created after `BULK_TIMESTAMP`.
5.  Process every user created before `BULK_TIMESTAMP` and modified after `BULK_TIMESTAMP`, and update changed profile data. When a password changed, start a password reset for the user, or let the user reset the password.

Depending on the load time, repeat the cycle a few times.

Without timestamps, split users into deterministic groups, track processed users in a separate datastore, or add a `processed_timestamp` column to the old user store.

## Keep Downstream Applications Working

When many applications depend on the old identity provider's token format, switching every application at once can be impractical. Different teams or organizations may own the applications. The following options reduce the effort. The options cover only access token differences. To route clients to FusionAuth's hostname and paths, a proxy usually works.

| Option | Changes to the old identity provider | Extra infrastructure | Token size impact | Complexity |
| --- | --- | --- | --- | --- |
| Customize the FusionAuth token | None | None | None | Low |
| Identity swap | Delegate authentication to FusionAuth | None | None | Medium |
| Wrap the old token | Add a token retrieval endpoint | Possibly a proxy | High | Medium |
| Exchange the token | Add a token exchange endpoint | A proxy | None | Medium |

With most options, you eventually update each application to accept FusionAuth tokens, retire the old identity provider, and remove the temporary changes.

### Customize the FusionAuth Token

A [JWT populate lambda](https://fusionauth.io/docs/lambdas/tokens/jwt-populate.md) adds custom claims, calls APIs, and changes most claims, including `iss` (issuer) and `aud` (audience). When FusionAuth's token matches the old provider's token, applications work without changes.

When applications already use OIDC discovery at `/.well-known/openid-configuration`, importing the old signing keys can make the switch invisible. The old provider must allow exporting private keys.

This option is the simplest, because the other options change the old identity provider or other parts of your system. This option doesn't work when a [reserved claim](https://fusionauth.io/docs/lambdas/tokens/jwt-populate.md#the-jwt-object) has a format that your applications can't accept, or when the migration should change the token's structure or content.

### Identity Swap

Change the old identity provider to authenticate users through the FusionAuth [Login API](https://fusionauth.io/docs/apis/login.md). First, move all identity data into FusionAuth. FusionAuth then holds the user data, while the old identity provider still issues the tokens.

Over the following weeks, months, or years, update each application to accept FusionAuth tokens and to send users to FusionAuth for authentication. After the last application moves, retire the old identity provider.

### Wrap the Old Token

Users authenticate with FusionAuth. FusionAuth requests the user's token from the old identity provider, and a [JWT populate lambda](https://fusionauth.io/docs/lambdas/tokens/jwt-populate.md) adds the old token to a custom claim, such as `legacyToken`.

The old identity provider needs an endpoint that issues the token. Anyone who can call the endpoint can log in as any user, so allow only FusionAuth to call the endpoint. Consider limiting the endpoint to certain applications or users.

Before an application receives the token, a proxy or the client extracts the `legacyToken` claim and forwards the old token. Unwrap at a proxy or the client, so the applications don't change.

Wrapping avoids changes to applications, but adds complexity and enlarges FusionAuth's token. A large old token may slow transmission and storage.

Over time, update each application to accept FusionAuth tokens. Then retire the old identity provider, and remove the code that adds `legacyToken`.

### Exchange the Token

Users authenticate with FusionAuth, and a proxy exchanges the FusionAuth access token for an old token for the same user.

The old identity provider needs an endpoint that takes a FusionAuth access token and returns an old token. Secure the endpoint. Validate both the access token and the caller, and consider limiting the exchange to certain applications or users. Run the exchange at a proxy, because clients shouldn't make complex token exchange requests.

An exchange keeps FusionAuth's token small, unlike wrapping. Getting the old token takes a server-side network call instead of a claim lookup.

Over time, update each application to accept FusionAuth tokens. Then retire the old identity provider, and remove the exchange endpoint.

Related

[Migrate Migrate Users to FusionAuth in Bulk Learn how to import every user into FusionAuth at once with the Import Users API, including password hashes, social logins, and MFA. migrate usersuser migration](https://fusionauth.io/docs/migrate/bulk-migration.md)

[Migrate Migrate Users From a Custom Authentication System Learn how to migrate users and password hashes from a custom authentication system to FusionAuth. user migrationmigrate users](https://fusionauth.io/docs/migrate/genericmigration.md)

[Migrate Migrate Users to FusionAuth Learn how to import users into FusionAuth, move between FusionAuth Cloud and a self-hosted instance, and export data from FusionAuth. migrate usersuser migration](https://fusionauth.io/docs/migrate.md)

[Migrate User Migration Types Learn about bulk, segment-by-segment, and slow user migrations, and how to choose between them. migrate usersuser migration](https://fusionauth.io/docs/migrate/migration-types.md)
---

## Other pages in Migrate

> For the full index of this section, see [Migrate](https://fusionauth.io/docs/llms-migrate.txt).

- [Migrate Users to FusionAuth in Bulk](https://fusionauth.io/docs/migrate/bulk-migration.md): Learn how to import every user into FusionAuth at once with the Import Users API, including password hashes, social logins, and MFA.
- [Export from FusionAuth](https://fusionauth.io/docs/migrate/export.md): Learn how to export your data from FusionAuth to migrate to another authentication service.
- [Migrate Users From a Custom Authentication System](https://fusionauth.io/docs/migrate/genericmigration.md): Learn how to migrate users and password hashes from a custom authentication system to FusionAuth.
- [User Migration Types](https://fusionauth.io/docs/migrate/migration-types.md): Learn about bulk, segment-by-segment, and slow user migrations, and how to choose between them.
- [Password Hashing Plugins](https://fusionauth.io/docs/migrate/password-hashes.md): Learn about password hashing plugins, which let FusionAuth check passwords that use an unsupported scheme.
- [Plan a User Migration to FusionAuth](https://fusionauth.io/docs/migrate/plan-a-migration.md): Learn how to plan a user migration, map user data to FusionAuth, and set up FusionAuth before you import users.
- [Migrate Users to FusionAuth Gradually With Connectors](https://fusionauth.io/docs/migrate/slow-migration.md): Learn how to move users into FusionAuth one at a time, as each user logs in, with an LDAP or Generic Connector.
