Migrate From Microsoft Azure AD B2C
On this page
This guide moves your users and their profile data from Microsoft Azure AD B2C to FusionAuth.
Azure AD B2C closed to new customers on May 1, 2025. Microsoft offers Microsoft Entra External ID as the successor. Microsoft supports existing Azure AD B2C customers until at least May 2030, and discontinued the B2C P2 tier in March 2026. This guide serves existing Azure AD B2C customers who want to migrate to FusionAuth.
Azure AD B2C doesn't export password hashes. To keep each user's password, run a slow migration, which moves each user at the user's first login. When password resets are acceptable, run a bulk migration, which moves every user at once.
Prerequisites#
- Know Microsoft Azure, in particular Azure AD B2C, at an intermediate level.
- Install FusionAuth. For more information, see Install FusionAuth.
- For a slow migration, get a license for the Starter plan or higher. Slow migrations use Connectors, a paid feature.
- Install a current Node.js LTS version for the Azure Function and the export tool.
- Install Ruby for the import script.
Planning Considerations#
Plan the migration before you move any users. For the general planning steps, see Plan a Migration. The following sections cover what differs for Azure AD B2C.
Slow Migration Or Bulk Migration#
A slow migration keeps each user's password. Users log in to FusionAuth with their Azure AD B2C credentials, and FusionAuth moves each user through a Connector.
When password resets are acceptable, a bulk migration moves every user at once. You can also run a bulk migration after a slow migration has run for a while. The bulk migration then moves the users who haven't logged in.
For more information, see Migration Types.
Mapping User Attributes#
Map each Azure AD B2C user attribute to a field of the FusionAuth User. Azure AD B2C configures custom attributes at the directory level. Store custom attributes and other attributes without a FusionAuth field in user.data, which accepts any valid JSON value. For more information, see Map User Data.
Azure AD B2C user Ids are UUIDs. The sample Azure Function and the import script keep each user's Azure AD B2C Id as the FusionAuth user Id. For more information, see Preserve User Ids.
One Tenant or Many#
Azure AD B2C places users in tenants. A FusionAuth TenantA logical container for Users, Applications, and settings that is isolated from other Tenants. also holds users, applications, and other configuration. Each FusionAuth Tenant is a separate user space. You can merge several Azure AD B2C tenants into one FusionAuth Tenant, or create a FusionAuth Tenant for each Azure AD B2C tenant. For more information, see Multi-tenancy.
Identity Providers#
Azure AD B2C manages external identity providers as Identity Providers. FusionAuth also calls these providers Identity Providers.
When AD B2C users log in with social login providers, such as Google, Facebook, or Twitter, confirm that FusionAuth supports each provider. For the supported providers, see Identity Providers.
When FusionAuth doesn't support a provider directly, the provider may work through an OIDC or SAML connection. Otherwise, open a feature request.
To migrate social logins, you may need to change the options of the AD B2C import script. For more information, see Use the Script.Users who log in through an external identity provider authenticate with that provider. Import these users with the Import Users API instead of a slow migration. To export the users, see Export User Data From Azure AD B2C. To link the imported users to FusionAuth Identity Providers, see Users With Social Logins.
Other Entities#
Migrate configuration other than users, such as app clients and password policies, by hand or with a script. The following Azure AD B2C concepts map to FusionAuth features:
- User Flows and Custom Policies customize authentication and authorization workflows in Azure AD B2C. FusionAuth customizes these workflows with Lambdas and webhooks. Some webhook configurations can stop an authentication flow.
- Azure AD B2C has no standard roles and permissions. Azure AD B2C applications usually handle roles with custom attributes or a separate datastore. FusionAuth configures roles for each Application, and puts a user's roles in the token after login.
- Users log in and register on Azure AD B2C User Flow Page Layouts. FusionAuth offers hosted login pages, which cover the functionality of Azure AD B2C User Flows. You customize the hosted login pages with themes.
- Users log in to Azure AD B2C App Registrations. FusionAuth Applications are similar. Azure AD B2C gives users access to every application in a tenant by default. FusionAuth connects each user to an Application with a Registration. You can migrate the Client Id and Client Secret of each app client from Azure AD B2C to FusionAuth.
- Azure AD B2C sends emails, such as forgot password notifications. FusionAuth also sends emails from customizable templates.
- Azure AD B2C offers the Client Credentials grantAn OAuth 2.0 grant type in which a client uses its own credentials to obtain an access token for itself.. FusionAuth offers a constrained version of the grant with Entity Management, which requires the Starter plan or higher.
- Refresh tokensA credential that an application exchanges for a new access token without asking the user to log in again. let applications refresh JWTs without a new login. Migrate refresh tokens from Azure AD B2C with the Import Refresh Tokens API.
- Azure AD B2C supports multi-factor authentication (MFA). FusionAuth also supports MFA. You can enable MFA for a Tenant and configure MFA for a user at any time.
Azure AD B2C uses a pricing model based on monthly active usersThe number of unique users who are active in a month, for example by logging in or refreshing a token. FusionAuth bills paid plans by monthly active users. (MAUs). FusionAuth has no user limit. The resources of the FusionAuth instance, such as memory, CPU, and database capacity, set the limit instead.
Slow Migration#
Test the slow migration in a test environment before you deploy the configuration to production. The slow migration has the following steps:
- Set up FusionAuth.
- Set up Azure AD B2C.
- Set up the Connector.
- Log in as a test user.
- Move to production.
Set Up FusionAuth#
Create a test Tenant and a test Application for the migration.
Create a Test Tenant#
It is best to create a separate tenant for migration testing. Tenants logically isolate configuration settings and users. If a migration goes awry or you need to redo it after tweaking settings, you can delete the test tenant and start with a clean system. To add a tenant, navigate to Tenants and click the Add button.

Give it a descriptive Name like AD B2C import test. You shouldn't need to modify any of the other configuration options to test importing users.
Save the tenant.

Record the Id of the tenant, which will be a UUID. It will look something like 25c9d123-8a79-4edd-9f76-8dd9c806b0f3. You'll use this later.

Create a Test Application#
Applications are anything a user can log in to. In FusionAuth there's no differentiation between web applications, SaaS applications, APIs and native apps. To add an application, navigate to Applications and click on the Add button. Give the application a descriptive name like AD B2C application.
Select your new tenant, created above, in the dropdown for the Tenant field.
Navigate to the OAuth tab and add an entry to Authorized redirect URLs. Use a dummy value such as https://example.com. Later, you'll need to update this to be a valid redirect URL that can take the authorization code and exchange it for a token. Learn more about this in the FusionAuth OAuth documentation.
You shouldn't need to modify any of the other configuration options to test importing users. Save the application.

Next, view the application by clicking the Select dropdown and choosing View , then note the OAuth IdP login URL. You'll be using it to test that users can log in.

Set Up Azure AD B2C#
The slow migration needs the following components in Azure:
- An App Registration with an ROPC flow, which checks user credentials.
- A Microsoft Graph application, which reads the user's profile.
- An Azure Function, which receives login requests from FusionAuth over TLS. The Function logs the user in with the ROPC flow, reads the user's profile from Microsoft Graph, and returns the user to FusionAuth.
FusionAuth Connectors send user credentials to Azure AD B2C through the Azure Function. Secure the data in transit and the Azure Function endpoint. In this guide, all traffic uses TLS, and the Azure Function requires a unique query string code. For other security features, see Securing Azure Functions.
Rate limitingLimiting how many times a user or client can perform an action in a period of time, to slow down attacks and abuse. and identity protection systems monitor the Azure AD B2C ROPC endpoint. When failed logins exceed a dynamic threshold, the identity protection system may flag a repeated IP address, such as the Azure Function's address, as an attacker. To reduce the risk, deploy the Function to several regions, or self-host the Function on a known IP address.
Configure the App Registrations#
Create one App Registration for the ROPC flow and another for Microsoft Graph. The following steps use the Azure Portal and the newer App Registrations experience, not the legacy Applications experience.
-
Open Azure AD B2C App Registrations. Register an application and create an ROPC flow, as described in Register an application.

-
Save the configuration. The new app client appears in the list of app clients.
-
Record the Application (client) ID, a UUID such as
022c5902-d8ee-43b0-ac1f-c2719b799657. Also record the name of the ROPC flow. The Azure Function settings need both values.
-
Create an App Registration for Microsoft Graph API access, as described in Register a Microsoft Graph application. Include the Create Client Secret section.
-
Record the client secret and the Application (client) ID of the Microsoft Graph App Registration.
Configuring the Azure Function#
The Azure Function receives a login request from FusionAuth and logs the user in with the ROPC flow. On success, the Function reads the user from the Microsoft Graph Users API. The Function then converts the user to a FusionAuth User. When the login fails, the Function returns a 404 status code.
The following code is the sample Azure Function:
const graph = require("./graph");
require("isomorphic-fetch");
const querystring = require("querystring");
const jwt = require("jsonwebtoken");
module.exports = async function (context, req) {
context.log("JavaScript HTTP trigger function processed a request.");
const tenantName = process.env.TENANT_NAME;
const tenantId = process.env.TENANT_ID;
const ropcFlow = process.env.ROPC_FLOW_NAME;
const tokenUrl = `https://${tenantName}.b2clogin.com/${tenantName}.onmicrosoft.com/${ropcFlow}/oauth2/v2.0/token`;
const tokenRequest = {
username: req.body.loginId,
password: req.body.password,
grant_type: "password",
scope: `openid ${process.env.ROPC_CLIENT_ID}`,
client_id: process.env.ROPC_CLIENT_ID,
response_type: "token",
};
let tokenResponse = await fetch(tokenUrl, {
method: "POST",
body: querystring.stringify(tokenRequest),
headers: {
"Content-type": "application/x-www-form-urlencoded",
},
});
if (tokenResponse.ok) {
let body = await tokenResponse.json();
const decodedToken = jwt.decode(body.access_token);
let user = await graph.getUser(decodedToken.oid);
let fusionUser = transformToFusionUserObject(user);
context.res = {
status: 200,
body: {user: fusionUser},
};
} else {
// Something not great with username
context.res = {
status: 404,
body: await tokenResponse.text(),
};
}
context.log(JSON.stringify(context.res));
};
function transformToFusionUserObject(azureUser) {
let localIdentity = azureUser.identities.find(i=>i.signInType==="emailAddress"); //{|i|i["signInType"]==="emailAddress"}
let epochTime = new Date(azureUser.createdDateTime);
epochTime = epochTime.getTime();
let fusionUser = {
id: azureUser.id,
active: azureUser.accountEnabled,
firstName: azureUser.givenName,
fullName: azureUser.displayName,
lastName: azureUser.surname,
username: azureUser.userPrincipalName,
email: localIdentity.issuerAssignedId,
verified: true,
insertInstant: epochTime,
data :{
azure:{
identities: azureUser.identities
}
}
}
return fusionUser;
}Change the transformToFusionUserObject function to match the attributes you want to import. To change the code, clone or fork the repo for the full Function project, and edit your local copy.
The exact changes depend on your custom attributes and business logic. For example, the function can assign FusionAuth roles, register users for more than one Application, or add users to an existing FusionAuth Group. The sample Function doesn't add Registrations. To register migrated users for an Application, add a registrations array to the returned user.
Microsoft Graph returns a user like the following:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
"value": [
{
"id": "2e255143-5592-4233-a5b9-15e4ba56dfbe",
"deletedDateTime": null,
"accountEnabled": true,
"ageGroup": null,
"businessPhones": [],
"city": null,
"createdDateTime": "2022-08-05T21:05:58Z",
"creationType": null,
"companyName": null,
"consentProvidedForMinor": null,
"country": null,
"department": null,
"displayName": "Erlich Bachman",
"employeeId": null,
"employeeHireDate": null,
"employeeLeaveDateTime": null,
"employeeType": null,
"faxNumber": null,
"givenName": "Erlich",
"imAddresses": [],
"infoCatalogs": [],
"isManagementRestricted": null,
"isResourceAccount": null,
"jobTitle": null,
"legalAgeGroupClassification": null,
"mail": null,
"mailNickname": "erlich_bachman.com#EXT#",
"mobilePhone": null,
"onPremisesDistinguishedName": null,
"officeLocation": null,
"onPremisesDomainName": null,
"onPremisesImmutableId": null,
"onPremisesLastSyncDateTime": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSamAccountName": null,
"onPremisesSyncEnabled": null,
"onPremisesUserPrincipalName": null,
"otherMails": [
"erlich@aviato.com"
],
"passwordPolicies": null,
"postalCode": null,
"preferredDataLocation": null,
"preferredLanguage": null,
"proxyAddresses": [],
"refreshTokensValidFromDateTime": "2022-08-05T21:05:58Z",
"securityIdentifier": "S-1-12-1-774197571-1110660498-3826629029-3202307770",
"showInAddressList": null,
"signInSessionsValidFromDateTime": "2022-08-05T21:05:58Z",
"state": null,
"streetAddress": null,
"surname": "Bachman",
"usageLocation": null,
"userPrincipalName": "erlich_bachman.com#EXT#@fusiontut.onmicrosoft.com",
"externalUserConvertedOn": null,
"externalUserState": null,
"externalUserStateChangeDateTime": null,
"userType": "Member",
"employeeOrgData": null,
"passwordProfile": null,
"assignedLicenses": [],
"assignedPlans": [],
"authorizationInfo": {
"certificateUserIds": []
},
"deviceKeys": [],
"identities": [
{
"signInType": "federated",
"issuer": "MicrosoftAccount",
"issuerAssignedId": null
},
{
"signInType": "userPrincipalName",
"issuer": "fusiontut.onmicrosoft.com",
"issuerAssignedId": "erlich_bachman.com#EXT#@fusiontut.onmicrosoft.com"
}
],
"onPremisesExtensionAttributes": {
"extensionAttribute1": null,
"extensionAttribute2": null,
"extensionAttribute3": null,
"extensionAttribute4": null,
"extensionAttribute5": null,
"extensionAttribute6": null,
"extensionAttribute7": null,
"extensionAttribute8": null,
"extensionAttribute9": null,
"extensionAttribute10": null,
"extensionAttribute11": null,
"extensionAttribute12": null,
"extensionAttribute13": null,
"extensionAttribute14": null,
"extensionAttribute15": null
},
"onPremisesProvisioningErrors": [],
"provisionedPlans": []
}
]
}
The transformToFusionUserObject function converts the user to the FusionAuth format:
{
"user": {
"id": "702eebc9-ef84-489f-b7d3-6f67388ffdd3",
"active": true,
"firstName": "Erlich",
"fullName": "Erlich Bachman",
"lastName": "Bachman",
"username": "702eebc9-ef84-489f-b7d3-6f67388ffdd3@fusiontut.onmicrosoft.com",
"email": "erlich.bachman@piedpiper.com",
"verified": true,
"insertInstant": 1661188751000,
"data": {
"azure": {
"identities": [
{
"signInType": "emailAddress",
"issuer": "fusiontut.onmicrosoft.com",
"issuerAssignedId": "erlich.bachman@piedpiper.com"
},
{
"signInType": "userPrincipalName",
"issuer": "fusiontut.onmicrosoft.com",
"issuerAssignedId": "702eebc9-ef84-489f-b7d3-6f67388ffdd3@fusiontut.onmicrosoft.com"
}
]
}
}
}
}
Deploy the Azure Function#
You can write an Azure Function in the Azure Portal, or write the Function locally and deploy the Function as a package. The sample Function depends on other modules, so deploy the sample as a package. To deploy the Function:
-
Clone the function GitHub repo.
-
Deploy the project to an Azure Function with Visual Studio Code and the Azure extensions.
-
Set the following Function environment variables, also called Application Settings, to the values you recorded:
Azure Connector Function environment variables to set TENANT_NAME: // The name of your Azure AD B2C tenant ROPC_FLOW_NAME: // The name of the ROPC flow ROPC_CLIENT_ID: // The Application (client) Id of the ROPC App Registration GRAPH_CLIENT_ID: // The Application (client) Id of the Microsoft Graph API App Registration GRAPH_CLIENT_SECRET: // The client secret of the Microsoft Graph API App Registration
Test the Deployed API#
In the Azure Portal, open the Function overview page and click Get Function URL on the top bar. Copy the URL, including the access code. The URL looks like https://fusionAuth.azurewebsites.net/api/RopcProxy?code=s0ndU863xdbXsFO4dLZAJQXLzyTU789iaUJ43uLAtIkXm_AzFuFWP1zg==.
Test the login with curl and an account whose username and password you know:
$ curl -X POST 'https://fusionAuth.azurewebsites.net/api/RopcProxy?code=s0ndU863xdbXsFO4dLZAJQXLzyTU789iaUJ43uLAtIkXm_AzFuFWP1zg==' \
-H 'Content-type: application/json' \
-d '{
"loginId": "test@example.com",
"password": "password"
}'
When the login succeeds, the Function returns a FusionAuth User like the sample in Configuring the Azure Function. The exact response depends on your changes to the Function code. When the credentials are wrong, the Function returns a 404 status code with a message in the body. To see the status code, run curl with the -v option.
Set Up the Connector#
This feature requires at least a Starter plan.
A Generic Connector sends each login to the Azure Function. Create a separate Connector for each Azure AD B2C tenant. Connectors require a valid ReactorThe FusionAuth system that manages licenses and paid features. license. For more information, see Licensing.
To set up the Connector:
-
In the Admin UI, navigate to Settings -> Connectors . Open the add menu at the top right and select Add Generic connector .
-
Configure the Connector:
- Set Name to a value such as
Azure AD B2C migration. - Set Authentication URL to the Function URL.
- Leave the headers empty. Azure Functions read the code from the query string.

- Set Name to a value such as
-
Save the Connector.
-
Navigate to Tenants , edit the test Tenant, and open the Connectors tab.
-
Click Add policy .

-
Set Connector to the Connector you created, and turn on Migrate user. Keep Domains set to
*, which applies the Connector to every user.
-
Submit the policy.
-
Move the new policy to the top of the list with the arrow buttons.

-
Save the Tenant.
FusionAuth now checks each user against the Connector the first time FusionAuth sees the user. When the login succeeds, FusionAuth moves the user into the FusionAuth database.
Log In as a Test User#
To confirm that users move into FusionAuth:
-
Copy the OAuth IdP login URL that you recorded in Create a Test Application.
-
Open the URL in a private browser window. A private window keeps your Admin UI session out of the test.

-
Log in with the credentials of an Azure AD B2C user, such as the user from the curl test.
-
In the Admin UI, navigate to Users and confirm that the user exists. To review the user's profile, click Select -> Manage in the user's row.

After the login, FusionAuth redirects to a URL such as https://example.com/?code=FlZF97WIYLNxt4SGD_22qvpRh4fZ6kg_N89ZbBAy1E4&locale=fr&userState=Authenticated. No web application handles the authorization code redirect yet. To build one, follow a quickstart.
When the login fails or the user doesn't move, turn on Enable debug logging in the Generic Connector at Settings -> Connectors . Log in again, and look for errors in System -> Event Log .
After a user moves, FusionAuth handles every profile and password change for the user.
Move to Production#
After testing, apply the same configuration to production. Migrate users into the default tenantThe Tenant that FusionAuth creates during installation. You can't delete the Default Tenant, which hosts the FusionAuth Admin UI Application. or a new Tenant, and add the Connector policy to that Tenant.
When you don't keep users in the test Tenant, delete the test Tenant. Deleting a Tenant also deletes the Tenant's users and configuration, so you can start over after you change a setting. To delete a Tenant, navigate to Tenants , click Select in the Tenant's row, and choose Delete . Deleting a Tenant with many users takes time. To remove only a few users, delete the users one at a time in the Admin UI instead.

End the Slow Migration#
To estimate how long the slow migration takes, see Migration Timeline. At the end of the migration period, bulk migrate the remaining users, or treat the remaining users as inactive. Then remove the Connector policy from the Tenant. For more information, see End the Migration.
Bulk Migration#
Azure AD B2C password hashes are inaccessible, so a bulk migration requires every imported user to reset a password. The resets affect every user, so prefer a slow migration when you can. When a slow migration doesn't work because of timing or other reasons, a bulk migration moves all user data except passwords, and then sends password reset emails. For the tradeoffs, see Bulk Migration in Migration Types.
Set Up FusionAuth for a Bulk Migration#
Import the users into the test Tenant from Create a Test Tenant. When you skipped the slow migration, create the test Tenant first.
Create an API key for the import script. In the Admin UI, navigate to Settings -> API Keys and add a key.

Following the principle of least privilege, give the key only the following permissions:
POSTon the/api/user/importendpoint, for the import.POSTon the/api/user/forgot-passwordendpoint, for the password reset script.

When you link social accounts with the -l or -o options of the import script, also allow POST on the /api/user/search and /api/identity-provider/link endpoints. Record the API key.
Export User Data From Azure AD B2C#
The Azure AD B2C UI can bulk export users, but the bulk export leaves out user email addresses. This guide exports users with the Graph API, which includes email addresses. The export tool authenticates with the Graph API and calls the List method. To export users:
-
Register an application with Azure AD B2C, as described in Register a Microsoft Graph application. Record the application Id and secret.
-
Clone or fork the export tool repository, and install the dependencies.
$ npm install -
Create a
.envfile in the repository directory with your Azure AD B2C tenant, application Id, and secret:Bulk Export tool environment variables to set CLIENT_ID // The client Id TENANT_ID // The tenant Id, such as guide.onmicrosoft.com CLIENT_SECRET // The client secret -
Run the tool.
$ node index.js
The tool exports every user in the tenant to a users.json file:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
"value": [
{
"id": "862caa6a-86a6-4f3c-a0c0-8fc5d817fc56",
"deletedDateTime": null,
"accountEnabled": true,
"ageGroup": null,
"businessPhones": [],
"city": null,
"createdDateTime": "2022-08-05T21:40:48Z",
"creationType": "LocalAccount",
"companyName": null,
"consentProvidedForMinor": null,
"country": "South Africa",
"department": null,
"displayName": "Erlich Bachman",
"employeeId": null,
"employeeHireDate": null,
"employeeLeaveDateTime": null,
"employeeType": null,
"faxNumber": null,
"givenName": "Erlich",
"imAddresses": [],
"infoCatalogs": [],
"isManagementRestricted": null,
"isResourceAccount": null,
"jobTitle": null,
"legalAgeGroupClassification": null,
"mail": null,
"mailNickname": "862caa6a-86a6-4f3c-a0c0-8fc5d817fc56",
"mobilePhone": null,
"onPremisesDistinguishedName": null,
"officeLocation": null,
"onPremisesDomainName": null,
"onPremisesImmutableId": null,
"onPremisesLastSyncDateTime": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSamAccountName": null,
"onPremisesSyncEnabled": null,
"onPremisesUserPrincipalName": null,
"otherMails": [],
"passwordPolicies": "DisablePasswordExpiration",
"postalCode": "2109",
"preferredDataLocation": null,
"preferredLanguage": null,
"proxyAddresses": [],
"refreshTokensValidFromDateTime": "2022-08-05T21:40:46Z",
"securityIdentifier": "S-1-12-1-1680648810-1329366694-3314532512-1258035160",
"showInAddressList": null,
"signInSessionsValidFromDateTime": "2022-08-05T21:40:46Z",
"state": null,
"streetAddress": null,
"surname": "Bachman",
"usageLocation": null,
"userPrincipalName": "862caa6a-86a6-4f3c-a0c0-8fc5d817fc56@fusiontut.onmicrosoft.com",
"externalUserConvertedOn": null,
"externalUserState": null,
"externalUserStateChangeDateTime": null,
"userType": "Member",
"employeeOrgData": null,
"passwordProfile": null,
"assignedLicenses": [],
"assignedPlans": [],
"authorizationInfo": {
"certificateUserIds": []
},
"deviceKeys": [],
"identities": [
{
"signInType": "emailAddress",
"issuer": "fusiontut.onmicrosoft.com",
"issuerAssignedId": "erlich_bachman@fusiontut.onmicrosoft.com"
},
{
"signInType": "userPrincipalName",
"issuer": "fusiontut.onmicrosoft.com",
"issuerAssignedId": "862caa6a-86a6-4f3c-a0c0-8fc5d817fc56@fusiontut.onmicrosoft.com"
}
],
"onPremisesExtensionAttributes": {
"extensionAttribute1": null,
"extensionAttribute2": null,
"extensionAttribute3": null,
"extensionAttribute4": null,
"extensionAttribute5": null,
"extensionAttribute6": null,
"extensionAttribute7": null,
"extensionAttribute8": null,
"extensionAttribute9": null,
"extensionAttribute10": null,
"extensionAttribute11": null,
"extensionAttribute12": null,
"extensionAttribute13": null,
"extensionAttribute14": null,
"extensionAttribute15": null
},
"onPremisesProvisioningErrors": [],
"provisionedPlans": []
}
]
}
The export tool sends one request to the Graph API, and doesn't follow the @odata.nextLink pagination link. When the response doesn't hold every user, add pagination to the tool.
Get the Script#
FusionAuth provides an import script under a permissive open-source license. It requires Ruby 3.0 or later. To get the script, clone the Git repository:
git clone https://github.com/FusionAuth/fusionauth-import-scripts
Navigate to the azureadb2c directory:
cd fusionauth-import-scripts/azureadb2c
The script needs the date, json, optparse, securerandom, and fusionauth_client gems. Your Ruby installation likely includes every gem except fusionauth_client. When you have Bundler, run bundle install in the azureadb2c directory.
Use the Script#
To see the script's options, run the script with -h:
$ ruby ./import.rb -h
The script prints the following help:
Usage: import.rb [options]
-l, --link-social-accounts Link social accounts, if present, after import. This operation is slower than an import.
-r APPLICATION_IDS, A comma separated list of existing applications Ids. All users will be registered for these applications.
--register-users
-o, --only-link-social-accounts Link social accounts with no import.
-u, --users-file USERS_FILE The exported JSON user data file from Azure AD B2C. Defaults to users.json.
-f FUSIONAUTH_URL, The location of the FusionAuth instance. Defaults to http://localhost:9011.
--fusionauth-url
-k, --fusionauth-api-key API_KEY The FusionAuth API key.
-t TENANT_ID, The FusionAuth tenant id. Required if more than one tenant exists.
--fusionauth-tenant-id
-h, --help Prints this help.
Set the following options, unless the defaults work for you:
-u: the path of theusers.jsonfile from the export tool.-f: the URL of your FusionAuth instance, such ashttp://localhost:9011for a local test.-k: the API key.-t: the Id of the test Tenant.
The -l and -o options link social users, who authenticated through Google or another social provider, to FusionAuth Identity Providers. Create the Identity Providers in FusionAuth first, or the links fail. Linking runs slower than the import. To save time, import the users without -l, and then run the script again with -o to create only the links. Social account linkingConnecting a user's account at an external Identity Provider to a FusionAuth User, so both accounts log in as the same User. The Identity Provider's linking strategy decides how FusionAuth matches the accounts. requires FusionAuth 1.28.0 or later and version 1.28.0 or later of the fusionauth_client gem.
Run the import:
$ ruby ./import.rb -f http://localhost:9011 -k '...' -t '...'
The script prints output similar to the following:
FusionAuth Importer : Azure AD B2C
> User file: users.json
> Call FusionAuth to import users
> Import success
Duplicate users 0
Import complete. 2 users imported.
The script's map_user method sets the following User fields: id, active, firstName, lastName, fullName, username, email, verified, and insertInstant. The -r option adds Registrations. The script stores the user's original Azure AD B2C identities in user.data.azure.identities.
The script sets insertInstant in seconds, but FusionAuth expects milliseconds. To keep the original creation dates, multiply the value by 1000 in map_user.
To import other attributes, roles, or Group memberships, change map_user to build the matching JSON. For more information, see the Import Users API.
Verify the Import#
In the Admin UI, navigate to Users and review the imported users.
Before the final import, set -t to the Id of the production Tenant. To start over, delete the test Tenant as described in Move to Production.
Reset Passwords#
The import script gives each user a random password, so every user must reset the password. Users can use the forgot password link on the login page. You can also send every user a reset email with the Forgot Password API.
The script below sends an email to every imported user. Confirm that your SMTP server can handle the volume. Configure the SMTP server in Tenants -> Your Tenant -> Email .
To send the emails:
-
Review the Forgot Password email template. For more information, see Forgot Password.
-
Put the
loginIdof every user in one file, one per line. TheloginIdis the username or the email address from the Azure AD B2C export. -
Set
API_KEY,LOGIN_ID_FILE, andFA_HOSTin the following script. Use the API key from Set Up FusionAuth for a Bulk Migration.Example User Password Reset #!/bin/bash API_KEY=... LOGIN_ID_FILE=... FA_HOST=... for loginId in `cat $LOGIN_ID_FILE`; do sleep $[( $RANDOM % 10 > 8)] # sleeps 1 second ~10% of the time RES=`curl --max-time 600 \ -s -w "%{http_code}" \ -H "Authorization: $API_KEY" \ -H "Content-type: application/json" \ -XPOST \ $FA_HOST/api/user/forgot-password \ -d '{"loginId": "'$loginId'","sendForgotPasswordEmail": true}'` if [ "$RES" -ne "200" ]; then echo "Error: $RES"; exit 1; fi done -
Run the script. The script calls the Forgot Password API for each user, and sleeps now and then to avoid overloading the SMTP server.
Migrate Everything Else#
After the users move, migrate the other configuration described in Other Entities. The steps vary by configuration, but follow this pattern:
- Find the matching FusionAuth feature.
- Configure the feature in FusionAuth, either in the Admin UI or with a script that uses the client libraries or the APIs.
- Update your application configuration to use the FusionAuth feature.
Register your users with the right FusionAuth Applications in one of the following ways:
- Add Registrations to the users during the import.
- Create Registrations after the import with the Registrations API.
Change and test each application, whether custom, open source, or commercial, and confirm the following:
- Users can log in.
- The application handles the authorization code redirect.
- Users get the right permissions and roles from the JWT.
- The hosted login pages match the look and feel of the application.
When an application talks to AD B2C through a standard OAuth, SAML, or OIDC library, the switch to FusionAuth usually takes few changes.
When you use the Azure Client Credentials Flow, you can migrate Client Credentials grants. Create an Entity in FusionAuth for each Azure AD B2C app client that uses the Client Credentials grant. FusionAuth constrains scopes to a certain format. For the open request to change the format, see GitHub issue 1481. For more information, see Entity Management.
Migrate each of your Azure AD B2C app clients to a FusionAuth application with the Application API. The Application API lets you keep the Client Id and Client Secret from Azure AD B2C. Maintaining these values will minimize the impact on any applications using the OAuth Authorization Code grant or Implicit grant. Ensure you add the application to the correct tenant and allow the required grants.
Additional Support#
If you need support in your migration beyond that provided in this guide, you may:
- Post in our forums and get support from the community.
- Purchase a support plan and get expert help from the Engineering Team.
Related
API documentation for the FusionAuth Import Users API.
API documentation for the FusionAuth Import Refresh Tokens API.
Reference for the Connector policy fields on the Connectors tab of the Tenant form in the Admin UI.
Learn how to import every user into FusionAuth at once with the Import Users API, including password hashes, social logins, and MFA.