Beispiel #1
0
        private async Task <string> HandleSignIn(WsFederationMessage message, HttpContext context, string replyUrl)
        {
            var handler = CreateSessionHandler();

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

            var response = await _responseGenerator.GenerateSignInResponse(request);

            var wsTrustResponse = new WsTrustRequestSecurityTokenResponse
            {
                AppliesTo = new Uri(request.Realm),
                LifeTime  = new WsTrustLifetime
                {
                    Created = response.Token.ValidFrom,
                    Expires = response.Token.ValidTo
                },
                RequestedSecurityToken = response.Token
            };

            var sb = new StringBuilder();

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

            _logger.LogInformation("Adding realm in session cookie {0}", message.Wtrealm);

            handler.AddRealm(context, message.Wtrealm);

            var wsResponse = new WsFederationMessage();

            wsResponse.Wa            = "wsignin1.0";
            wsResponse.Wresult       = sb.ToString();
            wsResponse.Wctx          = message.Wctx;
            wsResponse.IssuerAddress = replyUrl;

            var form = wsResponse.BuildFormPost();

            return(form);
        }
Beispiel #2
0
        public async Task ShouldSerializeToken()
        {
            var responseGenerator = new SignInResponseGenerator(_logger,
                                                                _relyingPartyStore,
                                                                _profileManager,
                                                                _keyManager,
                                                                _options
                                                                );

            var response = await responseGenerator.GenerateSignInResponse(new SignInRequest
            {
                Realm = "urn:test",
                User  = new ClaimsPrincipal(new List <ClaimsIdentity>
                {
                    new ClaimsIdentity(new List <Claim>
                    {
                        new Claim(ClaimTypes.NameIdentifier, "john foo")
                    })
                }),
                Parameters = new Dictionary <string, string>()
                {
                }
            });

            var sb        = new StringBuilder();
            var xmlWriter = XmlWriter.Create(new StringWriter(sb), new XmlWriterSettings {
                Encoding = Encoding.UTF8
            });
            var serializer = new WsTrustSerializer();

            var wsTrust = new WsTrustRequestSecurityTokenResponse();

            wsTrust.LifeTime = new WsTrustLifetime
            {
                Expires = DateTime.Now.AddHours(8),
                Created = DateTime.Now
            };
            wsTrust.AppliesTo = new Uri("urn:test");
            wsTrust.RequestedSecurityToken = (Saml2SecurityToken)response.Token;

            serializer.Serialize(xmlWriter, wsTrust);

            xmlWriter.Flush();

            Assert.True(sb.ToString().Length > 0);
        }