I am unable to understand how to configure Azure AD B2C auth on a .Net Core 3.1 MVC application that has been configured behind an Azure Application Gateway using Back End Pool and Path Based URL mapping.
I have a .Net Core MVC (3.1) app that uses Nuget package (Microsoft.AspNetCore.Authentication.AzureADB2C.UI - v3.1.5).
The appsettings.json file contains:
"AzureAdB2C": {
"Instance": "...://foo.com/tfp/",
"ClientId": "guid",
"CallbackPath": "/Home/Index",
"Domain": "foo.onmicrosoft.com",
"SignUpSignInPolicyId": "do",
"ResetPasswordPolicyId": "re",
"EditProfilePolicyId": "mi"
}
startup.cs (in ConfigureServices method) has:
services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme).AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options));
Azure App Registration: I have created an App Registration with redirect URI:
https://localhost:5555/Home/Index
When working with application locally, everything works without issues / can perform auth.
I deployed the app to an Azure App Service. Thereafter, I updated the App Registration again, this time to include the URI (provisioned by default) of the app service:
https://myapp.azurewebsites.net/Home/Index
When working with application using App Service URL, everything works without issues / can perform auth.
Issue: Trouble happens when I provision a back end pool to point to the app service I just created. The steps I have performed are:
- In Application Gateway, clicked on 'backend pools' to create new one with 'target type' as 'app service' and 'target' as the app service I created.
- In Application Gateway blade, clicked on 'Rules', updated one of the existing 'path-based' rule (we have configured a listener with a specific URL https://ourdomain.com) to include a path based rule for the backend pool (the one I created).
- Then I updated the Azure App registration again, this time to include the backend pool path based URL
ourdomain.com/myapp/Home/Index
When Browsing to https://ourdomain.com/myapp, the path resolves and everything works fine; however auth is broken and does not work.
Upon inspection I have noticed that when I 'sign in' using the app service default URL, the call is:
....://foo.com/foo.onmicrosoft.com/b2c_1a_signup_signin_loa0/oauth2/v2.0/authorize?client_id=guid&redirect_uri=https%3A%2F%2Fmyapp.azurewebsites.net%2FHome%2FIndex&response_type=id_token&scope=openid%20profile&response_mode=form_post....
The parameter 'Redirect URI' is set as myapp.azurewebsites.net
However when I 'sign in' using the back end pool path (ourdomain.com/myapp), the same 'Redirect URI' is being used?
Surely the redirect URI should have been the one of the backend pool path ourdomain.com/myapp
Why is the Redirect URI (in App Registration) not working for backend pool based path despite being added? Is there something more I need to configure (in Azure / Code). Could you point me in the right direction.
Thank you in advance.