Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
External tenants (learn more)
Authentication approach: Embedded native authentication.
In this quickstart, you configure a React Next.js sample for Embedded native authentication with Microsoft Authentication Library (MSAL) for JavaScript 5.29.0. The email-and-password journey uses a tenant-verified custom domain with Cross-Origin Resource Sharing (CORS) at the edge.
Important
The Native Authentication API V2 is in preview. The Native Authentication API V1 remains generally available. See the Supplemental Terms of Use for Microsoft Azure Previews for legal terms that apply to preview features.
Prerequisites
- An external tenant and a public client application configured for Embedded native authentication. Complete Configure an application.
- A tenant-verified custom domain, the application ID, and the directory tenant GUID.
- CORS at the custom-domain edge configured for the sample's browser origin,
http://localhost:3000. Apply the shared proxy contract for origins, preflight, SDK headers, and success and error responses. - A customer account with email and password. If tenant policy requires multifactor authentication (MFA), prepare an enabled email or SMS factor for this sample journey.
- Node.js 20.9.0 or later, npm, Git, and a code editor.
- Port 3000 available for the application.
Get the sample
The sample has a unified launcher for V1 and V2. Use the pinned revision and SDK version below to follow this quickstart:
Clone the repository, check out the sample revision, and open its React Next.js application:
git clone https://github.com/Azure-Samples/ms-identity-ciam-native-javascript-samples cd ms-identity-ciam-native-javascript-samples git checkout --detach 49c4e250a1e6eb97e2b813e9fce6670c996a2808 cd typescript/native-auth/react-nextjs-sampleInstall the exact SDK version with the sample dependencies:
npm install --save-exact "@azure/msal-browser@5.29.0"
Configure the application
Use https://<tenant-verified-custom-domain>/<tenant-GUID> for both the service authority and the SDK API transport base in this edge route. Keep opaque absolute HAL links for that authority unchanged. Don't add a client secret to browser configuration.
- Open
src/config/auth-config.ts. - Replace
Enter_the_Application_Id_Herewith the application ID. - Replace the complete
auth.authorityvalue withhttps://<tenant-verified-custom-domain>/<tenant-GUID>, substituting your verified hostname and tenant GUID. - Add
auth.knownAuthoritiesas an array containing the verified hostname, without a scheme or path. - Set the required
customAuth.authApiProxyUrlstring to the same fullhttps://<tenant-verified-custom-domain>/<tenant-GUID>authority. Include the tenant GUID in both SDK URL settings. - Save the configuration file. The V2 sample uses the SDK's default scopes without custom claims. MFA requirements come from your tenant policy, not from selecting V2.
Run the sample
Run the application from the sample directory. This custom-domain edge configuration doesn't use the sample's local CORS proxy:
Start the application:
npm run devOpen
http://localhost:3000in a browser and select V2. Keep the application process running while you test.
Sign in the test customer
Use the sample's unified launcher to test only methods enabled for the current transaction.
- Enter the test customer's email address and select Sign In.
- If the service offers multiple first-factor methods, select the password method. Enter the password when requested and select Sign In.
- If the service requests MFA, select a returned email or SMS method and enter its verification code.
- Confirm that the sample reports completed sign-in. Don't expose tokens in screenshots, logs, or support output.
Email one-time passcode sign-in uses a customer account and user flow configured for that method. This quickstart follows the email-and-password journey.
Clean up the session
End the local test without deleting shared tenant configuration.
Signing out of the sample doesn't terminate other application or browser sessions.
- Sign out of the sample and clear the account-related application UI.
- Stop the application process in its terminal.