I have a .NET blazor application which uses Azure B2C authenticate users.
Steps:
- Open https://mywebsite.com in Chrome
- Due to network policy it auto switches to Edge browser --> displays login screen ---> User Sign In completed
- Then Azure log says successful user authentication,but no token is received back by the application and the application website fails.
- Error Screen is displayed.
I get the error page with the url : https://mywebsite.com/MicrosoftIdentity/Account/ErrorErrorImage
I'm encountering an issue with cross-browser token handling during Azure authentication. Specifically, when Windows forces a switch from Chrome to Microsoft Edge, my authentication process breaks down. How can I effectively manage tokens across these browsers to ensure a smooth user experience?
Program.CS
builder.Services.AddScoped<HttpContextAccessor>(); builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme) .AddMicrosoftIdentityWebApp(options => { builder.Configuration.Bind("AzureAdB2C", options); options.Events = new OpenIdConnectEvents { OnRedirectToIdentityProvider = async ctxt => { await Task.Yield(); }, OnAuthenticationFailed = async ctxt => { await Task.Yield(); }, OnSignedOutCallbackRedirect = async ctxt => { ctxt.HttpContext.Response.Redirect(ctxt.Options.SignedOutRedirectUri); ctxt.HandleResponse(); await Task.Yield(); }, OnTicketReceived = async ctxt => { if (ctxt.Principal != null) { if (ctxt.Principal.Identity is ClaimsIdentity identity) { var colClaims = await ctxt.Principal.Claims.ToDynamicListAsync(); var IdentityProvider = colClaims.FirstOrDefault( c => c.Type == "http://schemas.microsoft.com/identity/claims/identityprovider")?.Value; var Objectidentifier = colClaims.FirstOrDefault( c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier")?.Value; var EmailAddress = colClaims.FirstOrDefault( c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")?.Value; var FirstName = colClaims.FirstOrDefault( c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname")?.Value; var LastName = colClaims.FirstOrDefault( c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname")?.Value; var AzureB2CFlow = colClaims.FirstOrDefault( c => c.Type == "http://schemas.microsoft.com/claims/authnclassreference")?.Value; var auth_time = colClaims.FirstOrDefault( c => c.Type == "auth_time")?.Value; var DisplayName = colClaims.FirstOrDefault( c => c.Type == "name")?.Value; var idp_access_token = colClaims.FirstOrDefault( c => c.Type == "idp_access_token")?.Value; } } await Task.Yield(); }, }; });Thanks.