Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4845

How to effectively manage tokens across the browsers to ensure a smooth user experience

$
0
0

I have a .NET blazor application which uses Azure B2C authenticate users.

Steps:

  1. Open https://mywebsite.com in Chrome
  2. Due to network policy it auto switches to Edge browser --> displays login screen ---> User Sign In completed
  3. Then Azure log says successful user authentication,but no token is received back by the application and the application website fails.
  4. 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.


Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>