ASP.NET MVC 2 and authentication using WIF (Windows Identity Foundation)

前端 未结 5 2125
梦如初夏
梦如初夏 2020-12-08 00:58

Are there any decent examples of the following available:

Looking through the WIF SDK, there are examples of using WIF in conjunction with ASP.NET u

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 01:43

    What you want to do is an active signin. WIF includes WSTrustChannel(Factory) which allows you to communicate directly with the STS and obtain a security token. If you want your login form to work this way, you can follow the "WSTrustChannel" sample from the WIF 4.0 SDK. Once you have obtained the token, the following code will take that token and call the WIF handler to create a session token and set the appropriate cookie:

    public void EstablishAuthSession(GenericXmlSecurityToken genericToken)
    {
        var handlers = FederatedAuthentication.ServiceConfiguration.SecurityTokenHandlers;            
        var token = handlers.ReadToken(new XmlTextReader(
                                            new StringReader(genericToken.TokenXml.OuterXml)));
    
        var identity = handlers.ValidateToken(token).First();
        // create session token
        var sessionToken = new SessionSecurityToken(
            ClaimsPrincipal.CreateFromIdentity(identity));
        FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(sessionToken);
    }
    

    Once you have done this, your site ought to behave the same as if passive signing had occurred.

提交回复
热议问题