Moving users from Azure AD B2C or Entra External ID to Keycloak
Microsoft stopped selling Azure AD B2C to new customers on May 1, 2025, and points existing tenants to Microsoft Entra External ID. Some teams follow that path; others take the moment to move to Keycloak. Either way, users live in the tenant’s directory and come out through Microsoft Graph.
This converter reads the users JSON Graph returns and writes a Keycloak partial import or realm import file. It reads the sign-in names from identities, strips the extension_<app id>_ prefix from custom attributes, and gives local accounts a set-password step. It runs in your browser.
For the whole move, see moving from Azure AD B2C.
Getting users out with Microsoft Graph
List users with Graph’s users endpoint. Select the properties you need, because identities and extension attributes are not in the default set. Graph returns pages of users with an @odata.nextLink; follow it until it is gone, and put the users of every page into one value array.
GET https://graph.microsoft.com/v1.0/users?$select=id,displayName,givenName,surname,mail,otherMails,identities,accountEnabled,createdDateTime,extension_<app-id>_loyaltyNumber&$top=999In B2C, custom attributes are extension properties on the b2c-extensions-app application. Graph names them extension_<client id without hyphens>_<name>, such as extension_831374b3bd5041bfaa54263ec9e050fc_loyaltyNumber. The tool keeps the part after the id as the Keycloak attribute name.
For groups, add memberOf with an expand, or list group members separately. The tool reads memberOf as a list of objects and uses each displayName as a group name.
Why passwords do not move
Graph lets you set a user’s password when you create or update the user, and never returns it. The B2C attribute reference lists password as an attribute you can write, not one you can read. There is no export of password hashes. Microsoft’s own guidance for moving B2C users to External ID keeps passwords only by checking them against B2C at sign-in, just in time, not by copying hashes.
A just-in-time check needs the old system running beside the new one, and code in the new one’s sign-in path. RealmDeploy clusters run stock Keycloak without custom providers, so we do not offer that. Local B2C accounts set a new password by email link after the move: the tool gives them the UPDATE_PASSWORD required action, and Keycloak sends the link through the realm’s SMTP connection.
Federated identities, such as Google, Facebook or a company’s identity provider, have signInType: federated. They get no password step and link to their account by email at their first sign-in through the same provider in Keycloak.
What the tool does with each field
| Graph property | Keycloak user | Notes |
|---|---|---|
identities with emailAddress | email, and the username by default | The sign-in email of a local account |
identities with userName | username when you choose the id | For username sign-in |
mail, then otherMails | email | When there is no sign-in email |
givenName, surname | firstName, lastName | From displayName when both are empty |
accountEnabled | enabled | |
createdDateTime | createdTimestamp | |
id | The b2c_object_id attribute | The object id your apps saw as oid |
extension_<id>_<name> | The <name> attribute | Prefix removed |
city, country, jobTitle and similar | Attributes of the same name | |
memberOf | groups, when you name it | Display names as paths |
Read and left out: passwordProfile, identities after use, userPrincipalName (kept as b2c_upn only when a user has no other name), and Graph metadata such as @odata fields.
B2C has no per-user verified flag in Graph. Local accounts that sign in with an email usually proved it during sign-up, depending on your user flow; tick “Mark every email as verified” if that holds for your tenant.
The output
{
"users": [
{
"username": "[email protected]",
"email": "[email protected]",
"emailVerified": false,
"firstName": "Sample",
"lastName": "One",
"enabled": true,
"createdTimestamp": 1709370900000,
"attributes": {
"loyaltyNumber": ["1001"],
"b2c_object_id": ["00000000-0000-4000-8000-0000000000a1"]
},
"requiredActions": ["UPDATE_PASSWORD"]
}
]
}The preview shows 20 users; the saved file has every user.
User flows, custom policies and MFA
B2C user flows and custom policies (the Identity Experience Framework XML) do not move. Map each to Keycloak: sign-up and sign-in become the realm’s browser flow and registration settings, profile editing becomes the account console or required actions, and claims you shaped in a policy become protocol mappers on a client scope. REST API calls from custom policies have no direct counterpart in stock Keycloak, so plan where that logic lives after the move.
MFA does not move either. Graph returns the secret of a software OATH (TOTP) method as null, always. Users who used an authenticator app set it up again at their first sign-in; SMS and phone call codes have no built-in Keycloak counterpart, so decide on TOTP or passkeys before the move.
One file from many pages
Graph returns users in pages and puts the address of the next page in @odata.nextLink. Follow it until a page has none, and join the value arrays. With the Microsoft Graph PowerShell module, Get-MgUser -All does the paging for you; with plain HTTP, a short loop does.
URL='https://graph.microsoft.com/v1.0/users?$select=id,displayName,givenName,surname,mail,otherMails,identities,accountEnabled,createdDateTime&$top=999'
: > pages.ndjson
while [ -n "$URL" ] && [ "$URL" != "null" ]; do
curl -s "$URL" -H "Authorization: Bearer <token>" > page.json
jq -c '.value[]' page.json >> pages.ndjson
URL=$(jq -r '."@odata.nextLink"' page.json)
done
jq -s '{value: .}' pages.ndjson > users.jsonB2C tenants can hold many users, and Graph throttles requests per app and tenant. If a page answers with status 429, wait for the number of seconds in its Retry-After header and ask again; the loop above stops at the first error, so check that the last page really had no next link.
Use an app registration made for the move, with read permissions only, and remove its secret when the export is done.
Add your extension attributes to $select by their full name. Graph returns nothing for an extension you do not name, so a missing attribute in the output usually means a missing name in the query.
Keycloak or Entra External ID
Microsoft offers its own path: Entra External ID, with a documented migration from B2C and a just-in-time password migration that keeps passwords. If keeping every password matters more than anything else, or you want to stay inside Microsoft’s identity products, that path fits better.
Both paths need the same groundwork: an inventory of apps and identity providers, a plan for custom policy logic, and a dry run before users notice anything. The export and the converter here work the same whichever you choose, because External ID reads users from Graph too.
Keycloak fits when you want an open-source server you can take anywhere, standard OpenID Connect and SAML without a vendor’s policy language, and a cluster of your own. The cost of that choice in a B2C move is the password: users set a new one by email link.
What your users see
Local accounts get one email from Keycloak with a link to set a new password. Users who signed in with Google, Facebook or a company’s provider see the same provider button on Keycloak’s sign-in page and confirm the link to their account once. Everyone signs in again, because B2C sessions and refresh tokens do not carry over.
The sign-in page looks different. Clusters run Keycloak’s own themes, and custom themes are not supported yet, so the branded B2C pages you built with HTML templates do not come along. Tell users in your announcement that the page will look different and where its address will be.
Mistakes to avoid
- Listing users without
$select=identities, and getting no sign-in names. - Using
userPrincipalNameas the username. In B2C it is a generated value, not what users type. - Stopping at the first page. Follow
@odata.nextLinkto the end. - Forgetting that apps keyed on the B2C object id (
oid) see a new subject in Keycloak tokens. Keepb2c_object_idand map it. - Moving before the realm’s SMTP connection is tested, so set-password emails fail.
Where we come in
On Premium and Enterprise, our team does the move with you within the plan’s 10 service hours a month. On Starter, you use these tools and guides, with written support. Very large tenants are scoped as Custom through the contact form. The readiness checklist has the steps, and the email templates help you tell users.