【问题标题】:How to avoid session expired cookie for Owin Federation authentication?如何避免 Owin Federation 身份验证的会话过期 cookie?
【发布时间】:2016-08-02 17:30:56
【问题描述】:

我们正在使用 Cookie 和 WsFederation 中间件对 ADFS 服务器进行身份验证。一切正常,除了生成的 cookie 总是会话过期。

当用户关闭并重新打开浏览器时,他们需要重新登录。

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType,
            CookieDomain = "...some domain..."
        });

        app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
        {
            MetadataAddress = ConfigurationManager.AppSettings[AdfsMetadataAddress],
            Wtrealm = ConfigurationManager.AppSettings[AppWtRealm],
            UseTokenLifetime = false
        });

为了让cookie在浏览器端持久化,我们需要做些什么?

先谢谢了~

【问题讨论】:

    标签: asp.net authentication cookies owin federation


    【解决方案1】:

    添加一个可以设置过期时间的CookieAuthenticationProvider

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType,
            CookieDomain = "...some domain...",
            Provider = new CookieAuthenticationProvider
            {
                OnResponseSignIn = context =>
                {
                    context.Properties.ExpiresUtc = DateTimeOffset.UtcNow.AddDays(30);
                    context.Properties.IsPersistent = true;
                }
            }
        });
    

    【讨论】:

    • 我不认为 CookieDomain 是绝对必要的。
    猜你喜欢
    • 2023-04-05
    • 1970-01-01
    • 2017-05-06
    • 2019-10-28
    • 1970-01-01
    • 2012-01-30
    • 2015-10-09
    • 2016-03-24
    • 2023-03-31
    相关资源
    最近更新 更多