gpt4 book ai didi

c# - 如何注销 Owin 提供商?

转载 作者:可可西里 更新时间:2023-11-01 03:00:10 25 4
gpt4 key购买 nike

我正在关注 this tutorial但它没有告诉您如何注销。我试过了

Request.GetOwinContext().Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);

Request.GetOwinContext().Authentication.SignOut()

Request.GetOwinContext().Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie);

您可以在此处获取示例代码:https://github.com/AndersAbel/SocialLoginWithoutIdentity

只需要再添加一个 Action

public ActionResult SignOut()
{
Request.GetOwinContext().Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);
return RedirectToAction("Index", "Home");
}

这个方法加上我上面贴的3行中的任意一行

我现在的结果是,我登录,我转到安全页面并可以看到它,然后我继续注销,然后在注销后尝试返回安全页面,我被允许返回该安全页面。

所以它实际上并没有真正让我退出。

最佳答案

如教程中所述,使用的中间件使用默认身份验证类型但不要覆盖它。

通过仅使用 externalCookie 作为 Owin 的参数,您将清除 Asp 的 cookie,但不是用于存储 Google 提供商的 cookie

为此,您必须获取所有当前 cookie 的数组。可以像这样简单地完成:

Request.GetOwinContext()
.Authentication
.SignOut(HttpContext.GetOwinContext()
.Authentication.GetAuthenticationTypes()
.Select(o => o.AuthenticationType).ToArray());

这就是 Tutorial 上所说的地方:

The call to UseGoogleAuthentication should be quite obvious why it’s needed.

But the first one toSetDefaultSignInAsAuthenticationType is not asobvious.login middleware normally relies on the external cookie middlewareregistered before the social login middleware.external cookie middleware, it sets itself as the default signin type.That’s how the social login middleware knows that it should use theexternal cookie. In this setup there is no external cookie, so we haveto manually set the main cookie middleware as the default signin type.The cookie middleware will only issue a cookie if theAuthenticationType matches the one in the identity created by thesocial login middleware.Looking at the owin external authentication pipeline a socialIn the setup of the

关于c# - 如何注销 Owin 提供商?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38446789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com