Windows identity foundation - sign out or update claims

半世苍凉 提交于 2019-12-08 04:05:41

问题


I am using Windows Identity foundation to manage login to our site.

When a user logs in i am using some information in his request to put into the claims. It is all working fine, but now I need to manage this scenario:

  1. user is already logged in, athenticated and has a valid token.
  2. But user decides to browses in again (via a redirect from another site)
  3. So his information in his request is different.
  4. I want to either
    • Sign him out - so that he naturally creates a new token with his new information
    • OR update his existing token.

So my question is:

  1. How do i Sign out of Windows Identity foundation?
  2. Or How do I update the existing claims?

I have tried this code:

  public void ExpireClaims(HttpContextBase httpContextBase)
    {
        var module =
            httpContextBase.ApplicationInstance.Modules["WSFederationAuthenticationModule"] as
            WSFederationAuthenticationModule;
        if (module == null)
        {
            return;
        }
        module.SignOut(true);
    }

But module is alway null.

and i tried this:

  public void FederatedSignOut(string replyUrl)
    {
        WSFederationAuthenticationModule.FederatedSignOut(null, new Uri(replyUrl));
    }

But i get a null reference execption when i do this.

Thanks very much.


回答1:


Essentially sign-out is just deleting the cookie so:

FormsAuthentication.SignOut

or

FederatedAuthentication.SessionAuthenticationModule.SignOut

or

FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie

will work.

Or use the FederatedPassiveSignInStatus (should be in your Toolbox). Set the property SignOutAction to FederatedSignOut and the control will clear out your STS session as well.



来源:https://stackoverflow.com/questions/8037598/windows-identity-foundation-sign-out-or-update-claims

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!