/// <summary>
 /// Creates an artifact for the LogoutRequest and redirects the user to the IdP.
 /// </summary>
 /// <param name="destination">The destination of the request.</param>
 /// <param name="request">The logout request.</param>
 /// <param name="relayState">The query string relay state value to add to the communication</param>
 public void RedirectFromLogout(IdentityProviderEndpointElement destination, Saml20LogoutRequest request, string relayState)
 {
     var config = Saml2Config.GetConfig();
     var index = (short)config.ServiceProvider.Endpoints.LogoutEndpoint.Index;
     var doc = request.GetXml();
     XmlSignatureUtils.SignDocument(doc, request.Request.Id);
     ArtifactRedirect(destination, index, doc, relayState);
 }
 /// <summary>
 /// Creates an artifact and redirects the user to the IdP
 /// </summary>
 /// <param name="destination">The destination of the request.</param>
 /// <param name="request">The authentication request.</param>
 public void RedirectFromLogin(IdentityProviderEndpointElement destination, Saml20AuthnRequest request)
 {
     var config = Saml2Config.GetConfig();
     var index = (short)config.ServiceProvider.Endpoints.SignOnEndpoint.Index;
     var doc = request.GetXml();
     XmlSignatureUtils.SignDocument(doc, request.Request.Id);
     ArtifactRedirect(destination, index, doc, Context.Request.Params["relayState"]);
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpPostBindingBuilder"/> class.
 /// </summary>
 /// <param name="endpoint">The IdP endpoint that messages will be sent to.</param>
 public HttpPostBindingBuilder(IdentityProviderEndpointElement endpoint)
 {
     _destinationEndpoint = endpoint;
     Action = SamlActionType.SAMLRequest;
     RelayState = string.Empty;
 }
 /// <summary>
 /// Creates an artifact for the LogoutRequest and redirects the user to the IdP.
 /// </summary>
 /// <param name="destination">The destination of the request.</param>
 /// <param name="request">The logout request.</param>
 public void RedirectFromLogout(IdentityProviderEndpointElement destination, Saml20LogoutRequest request)
 {
     RedirectFromLogout(destination, request, Context.Request.Params["relayState"]);
 }
        /// <summary>
        /// Handles all artifact creations and redirects.
        /// </summary>
        /// <param name="destination">The destination.</param>
        /// <param name="localEndpointIndex">Index of the local endpoint.</param>
        /// <param name="signedSamlMessage">The signed SAML message.</param>
        /// <param name="relayState">The query string relay state value to add to the communication</param>
        private void ArtifactRedirect(IdentityProviderEndpointElement destination, short localEndpointIndex, XmlDocument signedSamlMessage, string relayState)
        {
            Logger.DebugFormat(TraceMessages.ArtifactRedirectReceived, signedSamlMessage.OuterXml);

            var config = Saml2Config.GetConfig();
            var sourceId = config.ServiceProvider.Id;
            var sourceIdHash = ArtifactUtil.GenerateSourceIdHash(sourceId);
            var messageHandle = ArtifactUtil.GenerateMessageHandle();

            var artifact = ArtifactUtil.CreateArtifact(HttpArtifactBindingConstants.ArtifactTypeCode, localEndpointIndex, sourceIdHash, messageHandle);
            Context.Cache.Insert(artifact, signedSamlMessage, null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration);

            var destinationUrl = destination.Url + "?" + HttpArtifactBindingConstants.ArtifactQueryStringName + "=" + HttpUtility.UrlEncode(artifact);
            if (!string.IsNullOrEmpty(relayState))
            {
                destinationUrl += "&relayState=" + relayState;
            }

            Logger.DebugFormat(TraceMessages.ArtifactCreated, artifact);

            Context.Response.Redirect(destinationUrl);
        }