question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logout does not work when using AddOidcAuthentication

See original GitHub issue

When using AddOidcAuthentication in Blazor WebAssmbly standalone, the logout does not work. After logout the browser navigates to:

https://localhost:44316/authentication/logout-failed?message=The logout was not initiated from within the page.

To Reproduce

Use same example described here. The error happens when BeginLogout is invoked.

@code{
    private async Task BeginLogout(MouseEventArgs args)
    {
        await SignOutManager.SetSignOutState();
        Navigation.NavigateTo("authentication/logout");
    }

    private void BeginLogin(MouseEventArgs args)
    {
        Navigation.NavigateTo("authentication/login");
    }
}

Authentication registration

   builder.Services.AddOidcAuthentication(options =>
            {
                builder.Configuration.Bind("Google", options.ProviderOptions);               
            });

App Settings

“Google”: { “Authority”: “https://accounts.google.com/”, “ClientId”: “****u.apps.googleusercontent.com”, “ClientSecret”: "“Not needed”, “PostLogoutRedirectUri”: “https://localhost:44316/authentication/logout-callback”, “RedirectUri”: “https://localhost:44316/authentication/login-callback”, “ResponseType”: “id_token” },

Error rendered in browser

There was an error trying to log you out: ‘’

Error shown in address bar

The%20logout%20was%20not%20initiated%20from%20within%20the%20page.

image

Further technical details

Project details

<PropertyGroup> <TargetFramework>net5.0</TargetFramework> <RuntimeIdentifier>browser-wasm</RuntimeIdentifier> <UseBlazorWebAssembly>true</UseBlazorWebAssembly> <RazorLangVersion>3.0</RazorLangVersion> </PropertyGroup>

Referenced packages.


 <ItemGroup Condition="'$(TargetFramework)' == 'net5.0' ">
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.4" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.4" PrivateAssets="all" />
    <PackageReference Include="Microsoft.AspNetCore.Localization" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Localization" Version="5.0.4" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />

  </ItemGroup>

 <ItemGroup>
    <!--<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
    <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />-->
    
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.4" />
    <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
    <PackageReference Include="Microsoft.Authentication.WebAssembly.Msal" Version="5.0.4" />
    <PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="3.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="NSwag.ApiDescription.Client" Version="13.0.5">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ChristianWeyercommented, Mar 21, 2021

Hey Damir!

I tried to repro your observation. Please see my small sample here: https://github.com/ChristianWeyer/blazor-wasm-oidc-google-repro

I was not able to obey the same error you are seeing. (Please make sure the redirect URLs in your Google app are configured correctly). Could you take a look and let me know whether I missed a scenario in my code @ddobric ? Thanks!

0reactions
msftbot[bot]commented, Apr 2, 2021

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logout does not work when using AddOidcAuthentication ...
The logout works fine when I'm on the root page, however, if I'm on any other page it won't work and I get...
Read more >
Login prompt after logout using Auth0 in ASP.NET Blazor ...
I managed to get it working but when I log out and go to log in again the app automatically authenticates without taking...
Read more >
How do I add authentication to a Blazor WebAssembly app?
To support the authenticating service, add the AddOidcAuthentication service configuration to the Program.cs file. [Program.cs] using Microsoft.Extensions.
Read more >
there's a bug where the logout link stops working if you ...
The issue is that when you click logout, you get a 400 error. This is due to the original LogOut page that came...
Read more >
Blazor WASM auth
Currently trying to get Blazor WASM (Web Assembly) to work with Fusion Auth. My initial issue was to get to fusion auth at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found