【问题标题】:ADFS freshness and session slidingADFS 新鲜度和会话滑动
【发布时间】:2015-07-12 12:04:54
【问题描述】:
I have implemented session sliding using in my customehttphandler module.

我正在尝试实现会话滑动以及在共享同一 ADFS 服务器的多个网站上进行身份验证。

 public void SessionAuthenticationModuleSessionSecurityTokenReceived(object sender, SessionSecurityTokenReceivedEventArgs e)
        {
            SessionSecurityToken token = e.SessionToken;
            DateTime nowUtc = DateTime.UtcNow;
            DateTime validFrom = token.ValidFrom;
            DateTime validTo = token.ValidTo;
            double totalMinutes = (validTo - validFrom).TotalMinutes;
            double halfSpan = totalMinutes / 2;

            SessionAuthenticationModule sam = sender as SessionAuthenticationModule;

            if (validTo < nowUtc)
            {
                if (sam != null)
                {
                    sam.DeleteSessionTokenCookie();
                    e.Cancel = true;
                }               
            }
            else if ((nowUtc - validFrom).TotalMinutes >= halfSpan)
            {
                SessionSecurityToken renewToken =             sam.CreateSessionSecurityToken(
                    token.ClaimsPrincipal,
                    token.Context,
                    nowUtc,
                    nowUtc.AddMinutes(totalMinutes),
                    true);
                e.SessionToken = renewToken;

                e.ReissueCookie = true;

//db timestamp update
            }
        }

And SignedIn event

 public void WSFederationAuthenticationModuleSignedIn(object sender, EventArgs e)
        {

             token = gettoken from cookie
            if (token.ValidTo > DateTime.Now.ToUniversalTime())
            {
                     //db insert for new login (assuming this will fire only      once on actual login)
                   reissue token
            }
       }

Session timeout is mentioned in the my relying party application web config

<securityTokenHandlers>
        <add type="Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <sessionTokenRequirement lifetime="0:02" />
        </add>
      </securityTokenHandlers>

Token Life time on ADFS I do not want to change which is greater than 2 minutes.

But issue is, after 2 minutes time out is not happening. It goes to SingedIn event becuase i assume it reissue token and then it calls session token received event so this condition (if (validTo < nowUtc)) never satisfy, how can i achieve timeout here? Freshness="0"achieves it but If i set Freshness="0" then I can not get authenticated by other website which are on same ADFS server. I want to be authenticated on other website as well if i have logged in one.

If I remove freshness="0" I can be authenticated without login on second website which is different application.

Why SignedIn is getting called before session token received and How can i achieve timeout in proper way and get authenticated in multiple website?

注意:我的 customeHttpHanlder 模块中有这些事件。其中还有其他事件,例如 PostAuthenticateRequest。

【问题讨论】:

    标签: c# asp.net session wif adfs2.0


    【解决方案1】:

    当您收到会话令牌时,您从 adfs 收到的令牌开始过期。完全过期后,需要刷新。

    • 这是从 adfs 获得准确信息(每次您想了解有关用户时调用广告)和具有可行情况(签名令牌具有一定的有效性,我们相信信息保持有效)之间的平衡)。

    令牌过期后,您需要返回到 adfs(因此是登录事件)以从 adfs 获取新令牌。这个想法是,在这两个令牌的发行之间,一些信息可能已经发生了变化。

    您可以在客户端(您的依赖方)实现滑动会话,但这没有什么意义(我会回到这个),因为您告诉自己令牌在另一段时间内有效。你相信自己,但令牌中的信息可能会不同步,这就是为什么你总是需要返回到 adfs。

    如果您自己实现令牌的自动刷新,所有这些可能都是有意义的。这意味着您将当前令牌换成具有新有效期的新令牌。我猜 adfs 可以做到这一点(但你需要这个活动场景)。这不是很多代码,但设置正确可能会很麻烦,而且我没有任何示例。

    最后,您需要问自己是否值得麻烦。 WIF 将再次进行自动登录,并且域内的用户将自动登录。域外的用户可能必须再次在此处键入凭据。我不认为这是世界末日。

    • 最后,我看到您使用的是旧实现的 Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler。 .Net 4.5 有一个更新的实现..

    【讨论】:

    • WIF = Windows Identity Foundation,一组支持联合身份验证的类。
    猜你喜欢
    • 2017-07-08
    • 2013-09-09
    • 2018-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多