Authgear
Start BuildingHomePortalCommunity
  • Authgear Overview
  • Get Started
    • Start Building
    • 5-Minute Guide
    • Single-Page App
      • JavaScript (Web)
      • React
      • Angular
      • Vue
    • Native/Mobile App
      • iOS SDK
      • Android SDK
        • Android Kotlin coroutine support
        • Android OKHttp Interceptor Extension (Optional)
      • Flutter SDK
      • React Native SDK
      • Ionic SDK
      • Xamarin SDK
      • Using Authgear without SDK (Client side)
    • Regular Web App
      • Express
      • Next.js
      • Python Flask App
      • Java Spring Boot
      • ASP.NET Core MVC
      • Laravel
      • PHP
    • Backend/API Integration
      • Validate JWT in your application server
      • Forward Authentication to Authgear Resolver Endpoint
    • AI Coding tools
      • Cursor/Windsurf
  • How-To Guides
    • Authenticate
      • Add Passkeys Login
      • Add WhatsApp OTP Login
      • Add Email Magic Link Login
      • Add Biometric Login
      • Add Anonymous Users
      • Add authentication to any web page
      • Enable Two-Factor Authentication (2FA)
      • Reauthentication
      • Passwordless Login for Apple App Store Review
      • Change Forgot/Reset Password settings
      • Adjust Phone Number Validation
      • Set Password Expiry
      • Use the OAuth 2.0 State Parameter
      • Setup local development environment for Cookie-based authentication
      • Use Social/Enterprise Login Providers Without AuthUI
    • Single Sign-on
      • App2App Login
      • Pre-authenticated URLs
      • SSO between Mobile Apps / Websites
      • Force Authgear to Show Login Page
      • Single Sign-On with OIDC
      • Single Sign-On with SAML
        • Use Authgear as SAML Identity Provider for Salesforce
        • Use Authgear as SAML Identity Provider for Dropbox
        • SAML Attribute Mapping
    • Social Login / Enterprise Login Providers
      • Social Login Providers
        • Connect Apps to Apple
        • Connect Apps to Google
        • Connect Apps to Facebook
        • Connect Apps to GitHub
        • Connect Apps to LinkedIn
        • Connect Apps to WeChat
      • Enterprise Login Providers
        • Connect Apps to Azure Active Directory
        • Connect Apps to Microsoft AD FS
        • Connect Apps to Azure AD B2C
      • Force Social/Enterprise Login Providers to Show Login Screen
    • Integrate
      • Add custom fields to a JWT Access Token
      • User Analytics by Google Tag Manager
      • Track User Before and After Signup
      • Custom domain
      • Custom Email Provider
      • Custom SMS Provider
        • Twilio
        • Webhook/Custom Script
      • Integrate Authgear with Firebase
    • Monitor
      • Audit Log For Users Activities
      • Audit Log for Admin API and Portal
      • Analytics
    • User Management
      • Account Deletion
      • Import Users using User Import API
      • Export Users using the User Export API
      • Manage Users Roles and Groups
      • How to Handle Password While Creating Accounts for Users
    • User Profiles
      • What is User Profile
      • Access User Profiles
      • Update User Profiles
      • Profile Custom Attributes
      • Update user profile on sign-up using Hooks
    • Events and Hooks
      • Event List
      • Webhooks
      • JavaScript / TypeScript Hooks
      • Only Allow Signups from Inside the Corporate Network using Hooks
    • Mobile Apps
      • Use SDK to make authorized API calls to backend
      • Force authentication on app launch
      • Customize the Login Pop-up / Disable the login alert box
    • Migration
      • Bulk migration
      • Rolling migration
      • Zero-downtime migration
    • Directly accessing Authgear Endpoint
    • Troubleshoot
      • How to Fix SubtleCrypto: digest() undefined Error in Authgear SDK
      • How to Fix CORS Error
  • Design
    • Built-in UI
      • Branding in Auth UI
      • User Settings
      • Privacy Policy & Terms of Service Links
      • Customer Support Link
      • Custom Text
    • Custom UI
      • Authentication Flow API
      • Implement Authentication Flow API using Express
      • Implement Authentication Flow API using PHP
      • Add Custom Login/Signup UI to Native Apps
      • Manually Link OAuth Provider using Account Management API
      • Implement a custom account recovery UI using Authentication Flow API
    • Languages and Localization
    • Custom Email and SMS Templates
  • Concepts
    • Identity Fundamentals
    • Authgear use cases
    • User, Identity and Authenticator
  • Security
    • Brute-force Protection
    • Bot Protection
    • Non-HTTP scheme redirect URI
    • Password Strength
  • Authgear ONCE
    • What is Authgear ONCE
    • Install Authgear ONCE on a VM
    • Install Authgear ONCE on Vultr
    • Install Authgear ONCE on Amazon Web Services (AWS)
  • Reference
    • APIs
      • Admin API
        • Authentication and Security
        • API Schema
        • Admin API Examples
        • Using global node IDs
        • Retrieving users using Admin API
        • User Management Examples
          • Search for users
          • Update user's standard attributes
          • Update user's picture
          • Generate OTP code
      • Authentication Flow API
      • OAuth 2.0 and OpenID Connect (OIDC)
        • UserInfo
        • Supported Scopes
      • User Import API
      • User Export API
    • Tokens
      • JWT Access Token
      • Refresh Token
    • Glossary
    • Billing FAQ
    • Rate Limits
      • Account Lockout
  • Client App SDKs
    • Javascript SDK Reference
    • iOS SDK Reference
    • Android SDK Reference
    • Flutter SDK Reference
    • Xamarin SDK Reference
  • Deploy on your Cloud
    • Running locally with Docker
    • Deploy with Helm chart
    • Authenticating HTTP request with Nginx
    • Configurations
      • Environment Variables
      • authgear.yaml
      • authgear.secrets.yaml
    • Reference Architecture Diagrams
      • Google Cloud Reference Architecture
      • Azure Reference Architecture
      • AWS Reference Architecture
      • Throughput Scaling Reference
Powered by GitBook
On this page
  • When to use Zero-downtime Migration
  • Step 1: Disable Update to User Data on Old Authentication System
  • Step 2: Import User Data to Authgear
  • Step 3: Implement and Deploy Updated Middleware and Server-side Code
  • Step 4: Implement Migration Endpoint

Was this helpful?

Edit on GitHub
Export as PDF
  1. How-To Guides
  2. Migration

Zero-downtime migration

PreviousRolling migrationNextDirectly accessing Authgear Endpoint

Last updated 1 month ago

Was this helpful?

The zero-downtime migration approach is much like bulk migration but without users that are already logged-in via the old authentication system having to log in again. This is made possible by taking the access token from the old system, verifying it, and then exchanging that access token for a new access token from Authgear.

To exchange a valid access token from your old system, implement a migration endpoint that calls the CreateSession mutation of Authgear's Admin API.

When to use Zero-downtime Migration

Zero-downtime migration is ideal in the following scenarios:

  • When it is important to keep users logged in after migration without making them repeat the login process.

  • In an application with a large number of logged-in users that are not usually required to login every time they return to your application.

Pros

Your users are not logged out. Hence, there is no need for them to repeat login.

Cons

It is more complex to set up and deploy.

In this guide, you'll learn how to perform a zero-downtime migration such that users who are currently logged in using your old authentication system are seamlessly moved to Authgear without being logged out at any point during the migration.

For this guide, we'll be referring to the source code for a demo Express.js app. The app will take a verified access token from your existing authentication provider details for the user associated with that access token to create a new Authgear user session (access token).

Step 1: Disable Update to User Data on Old Authentication System

First, temporarily restrict your users from changing their passwords and other profile information on your legacy system to prevent inconsistency in data during migration.

The actual operations required to do this will vary depending on your old authentication provider. You should refer to their official documentation for more details.

Step 2: Import User Data to Authgear

Once you have formatted your user data, send the JSON data in an HTTPS request to the _api/admin/users/import endpoint of the User Import API.

Step 3: Implement and Deploy Updated Middleware and Server-side Code

Implement middleware and server-side code that will recognize sessions from both Authgear and your old authentication provider.

Your implementation should be able to send an access token and a delegated identifier (login ID) from your old system to the migration endpoint that we will implement later in this guide.

const retrieveSessionFromOldSystem = () => {
    // ... implement the logic for retrieving session from old system here.
    // also you can return the user's attribute from the old system that was used as identifier in your import.
    // for example, if "identifier": "email", return the user's email. this will be used as loginID to retrieve the user's ID from Authgear

    return {
        loginID: "user@example.com",
        accessToken: "ey..."
    };
}

Step 4: Implement Migration Endpoint

Now, implement an endpoint in your application that will verify the access token from your old system, and if the access token is valid, proceed.

Our migration endpoint for the demo Express.js app in this guide uses the user's email address as a login ID. This is because we are assuming we have set email as the identifier. This identifier is set during the bulk import of user data to Authgear. If you set phone as the identifier, you can use the user's phone number as login ID instead.

const admin_api_endpoint = appUrl + "/_api/admin/graphql";
    const getUserQuery = await axios.post(
        admin_api_endpoint,
        {
          query: `query {
            getUserByLoginID(loginIDKey: "email", loginIDValue: "user@example.com")
            {
              id
            }
          }`,
        },
        {
          headers: {
            'Content-Type': 'application/json',
            Authorization: "Bearer " + adminJWT,

          }  
        }
      );

      const userID = getUserQuery.data.data.getUserByLoginID.id;

Specify your identifier type and login ID using loginIDKey and loginIDValue respectively in the input for the getUserByLoginID query.

The getUserByLoginID query will return a base64 encoded version of the current user's sub (user ID) in data.getUserByLoginID.id. You will use this user ID in the createSession mutation.

With a valid base64 encoded user ID, call the createSession mutation to generate a new Authgear session (with access token and refresh token).

//now create a new session
const createSessionMutation = await axios.post(
  admin_api_endpoint,
  {
    query: `mutation {
      createSession(input: {userID: "${userID}", clientID: "<YOUR_AUTHGEAR_CLIENT_ID>"})
      {
        accessToken,
        expiresIn,
        refreshToken
      }
    }`,
  },
  {
    headers: {
      'Content-Type': 'application/json',
      Authorization: "Bearer " + adminJWT,

    }  
  }
);

const authgearAccessToken = createSessionMutation.data.data.createSession.accessToken;

You can now use the Authgear access token to protect resources on your application. All users will continue to use your updated app without any interruption, as the migration endpoint will generate new Authgear sessions without prompting your users to log in again.

Note: For security reasons, the CreateSession mutation is disabled by default. Hence, you need to to enable it for your project.

Import the user data you have already exported from your legacy system into Authgear using the .

Your user data must be reformatted using the .

The step for importing users in zero-downtime migration is the same as in .

For the rest of this step, we will be making HTTPS requests to the Admin API GraphQL endpoint. A valid Admin API JWT is required for this. See to learn more.

After you have verified the access token, use the user's login ID to call 's getUserByLoginID query.

contact us
User Import API
bulk migration
Authenticate Admin API
the Admin API
User Import API Schema
flow of zero-downtime migration