You are developing a Single Page Application (SPA) using React and MSAL.js to authenticate users and obtain tokens for a downstream Web API. During the application registration in Microsoft Entra ID, you configured the redirect URI as http://localhost:3000/callback. When testing the authentication flow, the user can successfully sign in and the application receives an authorization code. However, when MSAL.js attempts to exchange the authorization code for an access token by sending a POST request to the token endpoint, the browser blocks the request with a Cross-Origin Resource Sharing (CORS) error. Which of the following describes the cause of this issue and the correct action to resolve it?
- AThe React application is a public client and is missing a client secret in its token request. You must generate a client secret in the App Registration and add it to the MSAL.js configuration.
- The redirect URI was registered under the Web platform in the App Registration. You must change the platform type of the redirect URI to Single-page application (SPA).Answer
- CThe application registration is missing a Key Vault access policy. You must create an access policy in Key Vault that grants the application's service principal permissions to sign tokens.
- DThe authentication request is using an over-permissioned Shared Access Signature (SAS) token. You must generate a new SAS token with narrower scopes for the token endpoint.
Answer
The redirect URI must be registered under the Single-page application (SPA) platform in the App Registration to enable CORS support on the token endpoint.
The platform type of the redirect URI dictates how the Microsoft Identity Platform handles token requests. For SPAs, registering the redirect URI under the 'Single-page application' platform enables Cross-Origin Resource Sharing (CORS) on the token endpoint. Without this, the token endpoint does not send the required CORS headers, leading to browser-side errors during the authorization code exchange.
Step-by-Step Solution
Key Concept
Entra ID App Registration Platform Types and CORS
Estimated Time:1m 30s