Skip to content

NavigationManager.NavigateToLogout() stuck on authentication/logout-callback after upgrade to dotnet 8 #53131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
yuominae opened this issue Jan 4, 2024 · 9 comments · Fixed by #54225
Closed
1 task done
Assignees
Labels
area-blazor Includes: Blazor, Razor Components
Milestone

Comments

@yuominae
Copy link

yuominae commented Jan 4, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a dotnet-hosted blazor wasm project that I have been developing since dotnet 6. Auth is done using duende identity server with locally stored user accounts, based on the way it was done at the time I started the project.

The project was migrated to dotnet 7 about a year ago and was running in production without problems until I recently upgraded it to dotnet 8. After upgrading, the logout process gets stuck at authentication/logout-callback page with the message "processing logout callback...". Manually navigating back to "/" gets things unstuck, but previously the redirection to "/" was happening automatically. Getting stuck on logout is not optimal for the users.
The interesting part is that when I run the app in debug mode on my local environment everything works fine. The problem occurs when the app is hosted in the azure app service.

Auth is configured in the api project in the following way

_ = services.AddDefaultIdentity<IdentityUser>(options =>
                {
                    options.SignIn.RequireConfirmedEmail = false;

                    options.SignIn.RequireConfirmedAccount = false;
                }).AddRoles<IdentityRole>()
                .AddRoleManager<RoleManager<IdentityRole>>()
                .AddEntityFrameworkStores<MycoAuthDbContext>();

            services.AddIdentityServer()
                .AddApiAuthorization<IdentityUser, MycoAuthDbContext>();

            services.AddTransient<IProfileService, ProfileService>();

            _ = JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("role");

            services.AddAuthentication()
                    .AddIdentityServerJwt();

            services.AddAuthorization(options =>
            {
                foreach (var policy in Policies.GetAll())
                {
                    if (policy.HasRoles)
                    {
                        options.AddPolicy(policy.Name, apb => apb.RequireRole(policy.Roles));
                    }

                    if (policy.HasRequirements)
                    {
                        options.AddPolicy(policy.Name, abp => abp.AddRequirements(policy.Requirements));
                    }
                }
            });

            foreach (var authorizationHandlerType in Policies.GetAuthorizationHandlerTypes())
            {
                services.AddScoped(typeof(IAuthorizationHandler), authorizationHandlerType);
            }

            return services.Configure<IdentityOptions>(options => options.ClaimsIdentity.UserIdClaimType = ClaimTypes.NameIdentifier);

And in the client the signout code consists of

private void BeginSignOut(MouseEventArgs args)
            => NavigationManager.NavigateToLogout(
                "authentication/logout",
                "/properties");`

Here's what it looks like in the hosted app

image

And here is what it looks like locally

image

Expected Behavior

NavigationManager.NavigateToLogout() should redirect to another url after successful log out.

Steps To Reproduce

Migrate project with identity stores from dotnet 7 to dotnet 8 and host in azure app service?

Exceptions (if any)

None

.NET Version

8

Anything else?

On azure

image

Locally

dotnet 8.0.100 with VS 2022

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Jan 4, 2024
@gfoidl gfoidl added area-blazor Includes: Blazor, Razor Components and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Jan 4, 2024
@brandonseydel
Copy link

brandonseydel commented Jan 8, 2024

Same thing here.

This seems to work OK for now.

if (this.Action == "logout-callback") Task.Delay(1_000).ContinueWith((a) => NavManager.NavigateTo("/"));

@yuominae
Copy link
Author

yuominae commented Jan 9, 2024

@brandonseydel if this fix works I'd like to try it too. Where do you place this code snippet?

@yuominae
Copy link
Author

Migrated back to dotnet 7 and now it works. Also noticed that the nuget Microsoft.AspNetCore.ApiAuthorization.IdenmtityServer has no 8 version, so I assume that there is now something else in place. The documentation on how to secure a web assembly app with identity server also stops at version 7.

What I can't find is any guidance on how to migrate my solution, apart from "start a new app and start copying pages over". Surely there must be a better way than starting over ever few versions?

@javiergardella
Copy link

Same thing here.
Using @brandonseydel WA!

Also, let me add, I'm using KeyCloak, so it isn't a IdentityServer problem!

@louisbouchard
Copy link

Same issue here. Any workaround or solution? Thank a lot.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@MackinnonBuck MackinnonBuck added this to the 8.0.x milestone Feb 7, 2024
@MackinnonBuck MackinnonBuck self-assigned this Feb 7, 2024
@halter73
Copy link
Member

halter73 commented Feb 9, 2024

This also looks similar to #49956.

@mkArtakMSFT mkArtakMSFT assigned halter73 and unassigned MackinnonBuck Feb 9, 2024
@yuominae
Copy link
Author

yuominae commented Feb 9, 2024

Thanks for the pointer @halter73. I haven't had a look at this issue since migrating back to .Net 7.
At first glance the error looks different from #49956, but that doesn't mean it doesn't have the same cause.
I'll make a branch with my project in .Net 8 in the next few days and will report back here if the error still occurs.

@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@fingers10
Copy link

fingers10 commented Mar 19, 2024

I was facing the same problem in dotnet 8 blazor wasm project... I did the following steps..

  1. Deleted bin and obj folder in blazor wasm .csproj.
  2. Added the following code in blazor wasm .csproj
<ItemGroup>
    <TrimmerRootAssembly Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication"/>
</ItemGroup>
  1. Published the project. All worked.

Reference - #49956 (comment)

@yuominae
Copy link
Author

For some reason it was working after I updated nuget packages and switched my app to dotnet 8, but after publishing again today I am getting the issue again.
Stuck on "Processing logout callback...". It's a very annoying issue to have with an app that runs in prod.
I tried the suggestion by @fingers10, but the issue persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
Status: Done
9 participants