|
| 1 | +# Azure AD B2C Interface for Entra External ID migration |
| 2 | + |
| 3 | +Please log any issues or questions in the repo. |
| 4 | + |
| 5 | +## Summary |
| 6 | + |
| 7 | +This sample will use AAD B2C as the journey orchestrator, whilst creating and authenticating users in the Entra External Id tenant. This makes it easier in the future to move apps to Entra External Id without disruption to your users. This sample performs sign up/in with MFA using Azure AD B2C, whilst maintaining user profiles in the Entra External Id tenant. |
| 8 | + |
| 9 | +This allows you to use B2C custom policies with the user data residing on an Entra External ID tenant |
| 10 | + |
| 11 | +This repo. was cloned from this [sample](https://github.com/azure-ad-b2c/samples/tree/master/policies/migrate-to-entra-external-id-for-customers) |
| 12 | + |
| 13 | +The original sample implemented a subset of the API calls. This repo. implements them all. |
| 14 | + |
| 15 | +This repo. also implements authentication using native auth. rather than ROPC. |
| 16 | + |
| 17 | +The code also includes RP for "Profile Edit" and "Password Reset". |
| 18 | + |
| 19 | +## REST API |
| 20 | + |
| 21 | +There are REST API for: |
| 22 | + |
| 23 | +* "REST-CIAM-UserReadUsingObjectIdOrEmail" |
| 24 | +* "REST-CIAM-UserReadUsingAlternativeSecurityId" |
| 25 | +* "REST-CIAM-UserWriteUsingLogonEmail" |
| 26 | +* "REST-CIAM-UserWriteUsingAlternativeSecurityId" |
| 27 | +* "REST-login-NonInteractive-CIAM" |
| 28 | +* "REST-fetchUserProfile-CIAM" |
| 29 | +* "REST-CIAM-UserUpdateUsingLogonEmail" |
| 30 | + |
| 31 | +The source for the REST AI is an an Azure function but the repo. uses ngrok so those calls |
| 32 | +need to be replaced with the actual function URL. |
| 33 | + |
| 34 | +Use "ngrok http 7257" if you want to use ngrok. (This allows you to run on localhost rather then using an Azure function). |
| 35 | + |
| 36 | +## Functionality |
| 37 | + |
| 38 | +The code handles: |
| 39 | + |
| 40 | +* Local account signup via link on the login page |
| 41 | +* Local account sign-in via login page using native authentication, not ROPC |
| 42 | +* Social account logins via federation buttons on the login page |
| 43 | +* MFA via SMS |
| 44 | +* Password reset via embedded link on the login page |
| 45 | +* Password reset via RP |
| 46 | +* Profile edit via RP |
| 47 | + |
| 48 | +## Setup ## |
| 49 | + |
| 50 | +The “GraphCallsFromB2CTenant” application registration needs the following permissions: |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +## Original set up instructions - How it works |
| 55 | + |
| 56 | +Users are sent to the AAD B2C authentication endpoint. An Azure function orchestrates all Read/Write operations to the Entra External Id directory. |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +## How to set it up |
| 65 | + |
| 66 | +### Create application registrations |
| 67 | +1. Create an Application registration in the Entra External Id tenant, named **RopcFromB2C**. Choose Native App. Copy the AppId/ClientId |
| 68 | +1. In the Authentication menu, enable **Allow public client** |
| 69 | +1. In the manifest, set |
| 70 | + |
| 71 | +1. Create an Application registration in the Entra External Id tenant, named **GraphCallsFromB2CTenant**. Choose Web App. Copy the AppId/ClientId |
| 72 | +1. Under API permissions, add MS Graph API **Application** permissions: `User.ReadWrite.All` and `UserAuthenticationMethod.ReadWrite.All` |
| 73 | +1. Under **Certificates & secrets**, generate a new secret. Copy this secret to be placed in the Azure function code |
| 74 | + |
| 75 | +### Modifications in Azure Function |
| 76 | +1. Change all instances of `your-tenant-id-guid` to your tenant guid or name eg `contoso.onmicrosoft.com` |
| 77 | +1. Change all instances of `your-clientId-RopcFromB2C` to the AppId of the **RopcFromB2C** App registration |
| 78 | +1. Change all instances of `your-client-id-to-call-graph` to the AppId of the **GraphCallsFromB2CTenant** App registration |
| 79 | +1. Change all instances of `your-client-secret` to the secret generated on the **GraphCallsFromB2CTenant** App registration |
| 80 | + |
| 81 | +### Host the Azure function |
| 82 | +1. In any production scenario, enable authentication in the Azure function. Eg, OAuth. |
| 83 | + |
| 84 | +### Quick Deploy |
| 85 | +You can quick deploy the sample into your tenant, and then make the changes in the next section. |
| 86 | +Use this [link to quick deploy](https://b2ciefsetupapp.azurewebsites.net/Home/Experimental?sampleFolderName=migrate-to-entra-external-id-for-customers) into your tenant. |
| 87 | + |
| 88 | + |
| 89 | +#### Required modifications in policy file |
| 90 | +1. Change all instances of `your-tenant` to your tenant name, eg: `contoso.onmicrosoft.com` |
| 91 | +1. Change all instances of `your-api-endpoint` to your Azure function endpoint. |
| 92 | +1. In any production scenario, enable authentication in the REST API technical profiles. |
| 93 | + |
| 94 | +## Testing |
| 95 | +Scenarios to test: |
| 96 | +1. Sign up via this AAD B2C custom policy with an account that does not already exist |
| 97 | +1. Sign in via this AAD B2C custom policy with an account that does exist |
| 98 | +1. Sign up via this AAD B2C custom policy with an account that does already exist |
| 99 | +1. Sign in via this AAD B2C custom policy with an account that does not exist |
| 100 | +1. Assign the user to a group/role in Entra External Id tenant, then perform a sign in |
| 101 | +1. Create a User Flow in Entra External Id tenant, and perform a Sign In via Entra External Id tenant with an account that was created via this AAD B2C custom policy |
| 102 | +1. Sign in via this AAD B2C custom policy with an account that was created using the User Flow from Entra External Id tenant |
| 103 | +1. View the User Profile after Sign Up in the Entra External Id tenant. Ensure the `Authentication Methods` menu is correctly populated with the users phone number visible, after sign up via this AAD B2C custom policy |
0 commit comments