azure - 无法在 .Net Core Web 应用程序上使用 Azure AD 身份验证注销

标签 azure asp.net-core azure-active-directory asp.net-core-2.0 logout

使用 Azure AD 登录时,我无法从 .Net core Web 应用程序注销。

当我尝试使用不同的电子邮件登录时,它只是以之前登录的用户身份登录。当新用户尝试登录时,它甚至不会要求输入密码。

我尝试了以下方法,但是 -

// Send an OpenID Connect sign-out request.
        HttpContext.GetOwinContext().Authentication.SignOut(
            OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType);

OR

HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

or 

if (HttpContext.User.Identity.IsAuthenticated)
{
    await HttpContext.Authentication.SignOutAsync(settings.SignInPolicyId);
    await HttpContext.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
}

这些都不适用于 .Net Core。

下面的代码在 .net core 上构建并运行,但它不会完全注销用户。

Request.GetOwinContext().Authentication.SignOut(new AuthenticationProperties { RedirectUri = clsCommonFunction.GetLoginURL() });

请帮忙。

最佳答案

HereASP.NET CoreSignOut 方法。

[HttpGet]
public IActionResult SignOut()
{
    var callbackUrl = Url.Action(nameof(SignedOut), "Account", values: null, protocol: Request.Scheme);
    return SignOut(
        new AuthenticationProperties { RedirectUri = callbackUrl },
        CookieAuthenticationDefaults.AuthenticationScheme,
        OpenIdConnectDefaults.AuthenticationScheme);
}

[HttpGet]
public IActionResult SignedOut()
{
    if (User.Identity.IsAuthenticated)
    {
        // Redirect to home page if the user is authenticated.
        return RedirectToAction(nameof(HomeController.Index), "Home");
    }

    return View();
}

Its not even asking for password when the new user is trying to login.

请清除浏览器缓存Ctrl+F5

关于azure - 无法在 .Net Core Web 应用程序上使用 Azure AD 身份验证注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50630863/

相关文章:

Azure pipeline yml - 更改任务中的值并根据 if else 条件执行

azure - 无法再将 Blazor wasm 发布到 azure

c# - 在 ASP.NET 5 中将声明与 OpenIdConnect.Server 结合使用

azure - 使用 MS Graph API 在 ADB2C 中重置没有 Directory.AccessAsUser.All 权限的用户密码

azure - 如何将日志从 azure 移动服务流式传输到控制台

azure - 如何在Graph API中按lastModifiedDateTime或lastModifiedBy用户displayName进行排序?

Azure 创建具有预定值的客户端 key

azure - 在本地开发时,如何使用 @azure/identity 和来自 'az login' 的 DefaultCredentials 而不是服务帐户?

c# - 通过.NET Core WebAPI的终结点公开TFS内部版本号

asp.net - 有没有办法在 blazor 中查看 razor 文件的 RenderTreeBuilder 版本?