Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net UseGoogleAuthentication强制登录会话过期?_Asp.net_Asp.net Mvc 5 - Fatal编程技术网

Asp.net UseGoogleAuthentication强制登录会话过期?

Asp.net UseGoogleAuthentication强制登录会话过期?,asp.net,asp.net-mvc-5,Asp.net,Asp.net Mvc 5,我正在使用ASP.NET MVC 5的外部身份验证中间件UseGoogleAuthentication/UseExternalSignInCookie和GoogleOAuth2AuthenticationOptions。有没有办法强迫用户每次访问该网站时都必须重新通过谷歌的身份验证 目前,如果用户已经登录到谷歌,并且他们访问了该网站,那么他们就不必向谷歌重新验证。理想情况下,分配的cookie只能用于站点上的当前会话 app.UseExternalSignInCookie(Default

我正在使用ASP.NET MVC 5的外部身份验证中间件UseGoogleAuthentication/UseExternalSignInCookie和GoogleOAuth2AuthenticationOptions。有没有办法强迫用户每次访问该网站时都必须重新通过谷歌的身份验证

目前,如果用户已经登录到谷歌,并且他们访问了该网站,那么他们就不必向谷歌重新验证。理想情况下,分配的cookie只能用于站点上的当前会话

    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

    var authOptions = new GoogleOAuth2AuthenticationOptions();
    authOptions.ClientId = AppSettingsHelper.GoogleClientId;
    authOptions.ClientSecret = AppSettingsHelper.GoogleClientSecret;
    authOptions.CallbackPath = new PathString("/account/linklogincallback");

    foreach (var scope in AppSettingsHelper.GoogleOAuthScope)
    {
        authOptions.Scope.Add(scope);
    }
    app.UseGoogleAuthentication(authOptions);
替换app.UseExternalSignInCookieDefaultAuthenticationTypes.ExternalCookie;使用app.UseCookieAuthentication。。并指定ExpireTimeSpan。UseExternalSignInCookie只是使用某些默认值的cookie身份验证方法的助手

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
    SlidingExpiration = true,
    ExpireTimeSpan = new System.TimeSpan(0, 5, 0),
    LoginPath = new PathString("/Account/Login")
});

请注意,我们在这里使用的是DefaultAuthenticationTypes.ExternalCookie,而不是ApplicationCookie

,这并不能完全满足我的要求。我需要做的是在浏览器会话结束时使外部身份验证提供程序cookie过期。例如,如果我关闭浏览器并返回该站点,则应要求我重新登录。。。对此有何想法?@Jason在这种情况下,您只需在用户登录时为ispersist指定false。AuthenticationManager.SignenNew AuthenticationProperties{IsPersistent=false},标识;