Skip to content

State is not preserved after login in .net 8.02 #54514

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
jbppraxis opened this issue Mar 12, 2024 · 3 comments
Closed
1 task done

State is not preserved after login in .net 8.02 #54514

jbppraxis opened this issue Mar 12, 2024 · 3 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved

Comments

@jbppraxis
Copy link

jbppraxis commented Mar 12, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

We are migrating from a .net 7 blazor client side webassembly app to .net 8. But have run into an issue. When doing a successful login, we have som logic that change where the user is redirected. For this we are using the RemoteAuthenticationState.ReturnUrl on the login event.

However, Remoteauthenticationstate is null after successfull login in .net 8.02.
It works on localhost but in staging environment and production it resolves to null.
The staging environment is a azure webapp not a static webapp.

Expected Behavior

State should not be null and contain a returnurl on successful login

Steps To Reproduce

Steps to reproduce.
Create blazor webassembly standalone app template project with authentication.
Change from Microsoft to standard OIDC authentication(we are using identityserver4).
In authentication.razor component add the following eventcallback when login is successful

image

Try to login and get a null exception on state.

We have tried several different implementations but it all resolves to null.

Exceptions (if any)

we get a null exception on the state

.NET Version

8.02 LTS

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Mar 12, 2024
@mkArtakMSFT
Copy link
Member

mkArtakMSFT commented Mar 13, 2024

Thanks for contacting us, @jbppraxis.
This is a known issue that we plan to fix soon. It's tracked as part of #49956

@stian-bay
Copy link

Found this workaround from another issue to preserve return url

In RedirectToLogin.razor

@using Microsoft.Extensions.Options
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication

@inject NavigationManager Navigation

@inject IOptionsSnapshot<RemoteAuthenticationOptions<ApiAuthorizationProviderOptions>> Options

@code {
    protected override void OnInitialized()
    {
        Navigation.NavigateToLogin(Options.Get(Microsoft.Extensions.Options.Options.DefaultName).AuthenticationPaths.LogInPath);
    }
}

@DylanLyon
Copy link

Found this workaround from another issue to preserve return url

In RedirectToLogin.razor

@using Microsoft.Extensions.Options
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication

@inject NavigationManager Navigation

@inject IOptionsSnapshot<RemoteAuthenticationOptions<ApiAuthorizationProviderOptions>> Options

@code {
    protected override void OnInitialized()
    {
        Navigation.NavigateToLogin(Options.Get(Microsoft.Extensions.Options.Options.DefaultName).AuthenticationPaths.LogInPath);
    }
}

Thank you so much! This worked perfectly for me. I had tried implementing this myself but ran into issues in other places. This seems to have done the trick!

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 feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Projects
None yet
Development

No branches or pull requests

5 participants