Windows identity foundation - sign out or update c

2019-06-02 02:17发布

问题:

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.



标签: c# wif