Skip to content
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

Logout Flow #13316

Closed
alfkonee opened this issue Jul 16, 2019 — with docs.microsoft.com · 4 comments · Fixed by #17940
Closed

Logout Flow #13316

alfkonee opened this issue Jul 16, 2019 — with docs.microsoft.com · 4 comments · Fixed by #17940
Assignees
Labels
Blazor doc-enhancement Pri2 Source - Docs.ms Docs Customer feedback via GitHub Issue

Comments

Copy link
Contributor

Please include the Logout Flow for Blazor Authorization using AuthenticationStateProvider


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Copy link

Yes please. Thise code doesn't work:

private async void LogoutUser()
{
    var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
    
    if (SignInManager.IsSignedIn(authState.User)) 
    { 
        await SignInManager.SignOutAsync(); 
    }

    NavigationManager.NavigateTo("~/", true);
}

@guardrex
Copy link
Collaborator

guardrex commented Jan 15, 2020

@VR-Architect Blazor Server app?

If so, can you use the pattern used by a Blazor Server template app with Identity?

Areas > Identity > Pages > Account > Logout.cshtml

@page
@using Microsoft.AspNetCore.Identity
@attribute [IgnoreAntiforgeryToken]
@inject SignInManager<IdentityUser> SignInManager
@functions {
    public async Task<IActionResult> OnPost()
    {
        if (SignInManager.IsSignedIn(User))
        {
            await SignInManager.SignOutAsync();
        }

        return Redirect("~/");
    }
}
<form method="post" action="Identity/Account/LogOut">
    <button type="submit" class="nav-link btn btn-link">Log out</button>
</form>

@guardrex
Copy link
Collaborator

Note that this issue will be addressed with the scaffolding PR that I'm turning in shortly.

btw -- The answer is along those lines ☝️, but you need an XSRF token to submit that form. I plan to have that approach on the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blazor doc-enhancement Pri2 Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
Archived in project
4 participants