/// <summary> /// Call the STS to get an appropriate token for a request and build a response. /// </summary> /// <param name="requestMessage"></param> /// <returns>The <see cref="SignInResponseMessage"/></returns> private SignInResponseMessage ProcessSignInRequest(SignInRequestMessage requestMessage) { // Ensure that the requestMessage has the required wtrealm parameter if (String.IsNullOrEmpty(requestMessage.Realm)) { throw new InvalidOperationException("Missing realm"); } SecurityTokenServiceConfiguration stsconfig = new SecurityTokenServiceConfiguration("PassiveFlowSTS"); // Create our STS backend SecurityTokenService sts = new CustomSecurityTokenService(stsconfig); // Create the WS-Federation serializer to process the request and create the response WSFederationSerializer federationSerializer = new WSFederationSerializer(); // Create RST from the request RequestSecurityToken request = federationSerializer.CreateRequest(requestMessage, new WSTrustSerializationContext()); // Get RSTR from our STS backend RequestSecurityTokenResponse response = sts.Issue((ClaimsPrincipal)Thread.CurrentPrincipal, request); // Create Response message from the RSTR return(new SignInResponseMessage(new Uri(response.ReplyTo), federationSerializer.GetResponseAsString(response, new WSTrustSerializationContext()))); }
public virtual CookieContainer GetCookieOnPremises([NotNull] string url, [NotNull] RequestSecurityTokenResponse requestSecurityToken) { Assert.ArgumentNotNull(url, "url"); Assert.ArgumentNotNull(requestSecurityToken, "requestSecurityToken"); var serializer = new WSFederationSerializer(); var responseAsString = serializer.GetResponseAsString(requestSecurityToken, new WSTrustSerializationContext()); return(this.GetCookieOnPremises(new Uri(url), responseAsString)); }