Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
The app registration and token flow must match the component redeeming the authorization code: a browser SPA must use the Single-page application platform with PKCE, while an App Service backend must use the Web platform and redeem the code as a confidential client.
If browser JavaScript redeems the code
This applies to Angular, React, Blazor WebAssembly, or other client-side applications making the token request from the browser.
- Open Microsoft Entra admin center → Entra ID → App registrations → your application → Authentication.
- Under Platform configurations, add Single-page application.
- Register the exact callback URL used by the application, including scheme, host, path, port, and casing.
- Remove that same callback URL from the Web platform if it belongs only to the SPA.
- Use authorization code flow with PKCE:
- The authorization request must contain
code_challengeandcode_challenge_method=S256. - The token request must contain the matching
code_verifier.
- The authorization request must contain
- Prefer MSAL.js rather than manually constructing these requests. Do not put a client secret in browser code.
Microsoft Entra requires PKCE for SPAs, and the spa redirect type enables the required cross-origin token redemption and CORS behavior.^1^ The portal path for assigning the redirect URI to the correct platform is documented here.^2^
A correct low-level request has this relationship:
GET /authorize?
client_id={client-id}
&response_type=code
&redirect_uri={encoded-spa-callback}
&code_challenge={challenge}
&code_challenge_method=S256
POST /token
grant_type=authorization_code
&code={authorization-code}
&redirect_uri={same-callback}
&code_verifier={matching-verifier}
If migrating an older JavaScript application, update it to MSAL.js 2.x and move only its browser callback URIs from Web to Single-page application. The URI should then appear in the SPA platform tile.^3^
If Azure App Service redeems the code on the server
This applies when ASP.NET, Node.js, Java, Python, App Service Authentication, or another server component handles the callback and exchanges the code.
- Open Microsoft Entra admin center → Entra ID → App registrations → your application → Authentication.
- Add the callback under Web, not Single-page application.
- Remove the server callback from the SPA platform if it was incorrectly registered there.
- Under Certificates & secrets, create a client secret or configure an appropriate certificate.
- Configure that credential only in the server-side application; never expose it to browser code.
- Ensure the
redirect_uriin both authorization and token requests exactly matches the registered Web callback. - Restart the App Service and initiate a completely new sign-in so that a new authorization code is issued.
Do not manually add an Origin header to a backend token request. A spa redirect URI is not supported for non-SPA flows, and Entra prevents client credentials from being used when an Origin header is present.^1^
Azure AD B2C with Microsoft Entra ID as an external identity provider
If the App Service or SPA signs in through an Azure AD B2C user flow and B2C redeems the external Entra authorization code, configure the external Entra app registration as a confidential Web application:
- Remove its Single-page application platform.
- Add the B2C callback under Web.
- Create a client secret.
- Enter that secret in the B2C OIDC identity-provider configuration.
- Set Allow public client flows to No.
This specific configuration resolved AADSTS9002325 where B2C was redeeming the external provider’s code as a backend client.^4^
If it still fails, capture the failed /token request and compare its redirect_uri, presence or absence of Origin, and PKCE parameters with the selected platform. Preserve the request ID, correlation ID, and timestamp from the error for Entra sign-in-log investigation.
References