Exemple #1
0
        private string HandleSignOut(HttpContext context, SamlRequestMessage message,
                                     string issuer,
                                     IDictionary <string, string> parameters,
                                     string logoutUrl)
        {
            var handler = CreateSessionHandler();

            handler.ClearEndpoints(context);

            var samlResponse = new SamlResponseMessage();

            samlResponse.Id           = Guid.NewGuid().ToString();
            samlResponse.InResponseTo = message.Id;
            samlResponse.Issuer       = issuer;
            samlResponse.ReplyTo      = new Uri(logoutUrl);
            samlResponse.ResponseType = "LogoutResponse";

            var sb = new StringBuilder();

            using (var xmlWriter = XmlWriter.Create(new StringWriter(sb)))
            {
                _serializer.Serialize(xmlWriter, samlResponse);
            }

            var form = BuildSignInFormPost(logoutUrl, sb.ToString(), null);

            return(form);
        }
Exemple #2
0
        private async Task <string> HandleSignIn(HttpContext context, SamlRequestMessage message,
                                                 string issuer,
                                                 IDictionary <string, string> parameters,
                                                 string replyUrl)
        {
            var handler = CreateSessionHandler();

            var request = new SignInRequest
            {
                User       = context.User,
                Realm      = message.Issuer,
                Parameters = parameters
            };

            var response = await _responseGenerator.GenerateSignInResponse(request);

            handler.AddRealm(context, message.Issuer);

            var samlResponse = new SamlResponseMessage();

            samlResponse.Token        = response.Token;
            samlResponse.Id           = Guid.NewGuid().ToString();
            samlResponse.InResponseTo = (!string.IsNullOrWhiteSpace(message.Id)) ? message.Id : Guid.NewGuid().ToString();
            samlResponse.ReplyTo      = new Uri(replyUrl);
            samlResponse.Issuer       = issuer;
            samlResponse.ResponseType = "Response";

            var sb = new StringBuilder();

            using (var xmlWriter = XmlWriter.Create(new StringWriter(sb)))
            {
                _serializer.Serialize(xmlWriter, samlResponse);
            }

            var form = BuildSignInFormPost(replyUrl, sb.ToString(), message.RelayState);

            return(form);
        }