I have an asp.netcore 3.1 web application that uses Azure AD B2C for authentication, this works perfectly when running the application locally. When the user clicks on the Sign In link the user is redirected to azure Ad B2C sign in/registration page. After user authenticates they are redirected back the local application.
Here is the code configuration
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
.AddAzureADB2C(options =>
{
Configuration.Bind("AzureAdB2C", options);
})
.AddCookie();
services.Configure<OpenIdConnectOptions>(AzureADB2CDefaults.AuthenticationScheme, opt =>
{
//Configuration.Bind("AzureAdB2C", opt);
opt.Authority = Configuration["OIDC:Authority"];
opt.RequireHttpsMetadata = true;
opt.GetClaimsFromUserInfoEndpoint = true;
opt.ClientId = Configuration["OIDC:ClientId"];
opt.ClientSecret = Configuration["OIDC:Secret"];
opt.ResponseType = "code";
opt.SaveTokens = true;
opt.AuthenticationMethod = OpenIdConnectRedirectBehavior.FormPost;
opt.Events = new OpenIdConnectEvents
{
OnUserInformationReceived = async ctx =>
{
},
OnTokenValidated =async ctx =>
{
//Get user's immutable object id from claims that came from Azure AD
Guid userId = Guid.Empty;
if (ctx.HttpContext.User.Identity.IsAuthenticated)
{
if (!string.IsNullOrWhiteSpace(ctx.HttpContext.User.FindFirstValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")))
userId = Guid.Parse(ctx.HttpContext.User.FindFirstValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"));
//Get EF context
var userRepo = ctx.HttpContext.RequestServices.GetRequiredService<IUserRepository>();
//Check is user a super admin
userRepo.RecordLogin(new Client.Models.EditModel.Account.RecordLoginEditModel()
{
AttemptedAt = DateTimeOffset.UtcNow,
UserId = userId,
LoginResult = "Success",
OnlineState = "Online",
SStGAppId = "CustomerPortal"
});
}
//return Task.CompletedTask();
}
};
});
...
}
public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseLogContextEnrichment();
app.UseCorrelationEnrichment();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
});
}
This is resulting 404 when clicking the sign in link on production site
As shown on the image above, the web app is running on an azure app service and being visited from the live domain, the site attempts to change to the azure AD b2c page, then instantly redirects back to the CustomDomain.com/signin-oidc which is the listed as the redirect uri in the Azure AD B2c Portal.
I am trying to figure out what the problem is. All the sites have SSL certificates too.