public SamlResponse Create(ISaml2pServiceProvider partner, Status status, string authnRequestId = null, string relayState = null, Saml2SecurityToken token = null) { var destination = new Uri(partner.BaseUrl, partner.AssertionConsumerServiceEndpoint); if (token != null) { if (authnRequestId != null) { token.SetRecipient(destination, authnRequestId); } else { token.SetRecipient(destination); } token.SetNotOnOrAfter(); } var response = new SamlResponse { Id = $"_{Guid.NewGuid()}", // TODO: create id factory SecurityToken = token, Destination = destination, IssueInstant = token?.Assertion.IssueInstant, Issuer = partner.ExpectedIssuer ?? _options.DefaultIssuer, Status = status, InResponseTo = authnRequestId, RelayState = relayState }; return(response); }
public void ShouldAddSubjectConfirmationData(string recipient) { var assertion = new Saml2Assertion(new Saml2NameIdentifier("__notused__")); assertion.Subject = new Saml2Subject(new Saml2NameIdentifier("__notused__")); var recipientUrl = new Uri(recipient); var token = new Saml2SecurityToken(assertion); token.SetRecipient(recipientUrl); var bearers = token.Assertion.Subject.SubjectConfirmations.Where(c => c.Method == Saml2Constants.ConfirmationMethods.Bearer); Assert.Single(bearers); var data = bearers.Single().SubjectConfirmationData; Assert.NotNull(data); Assert.Equal(recipientUrl, data.Recipient); Assert.Null(data.InResponseTo); }
public void ShouldAddSubjectConfirmationDataWithInResponseTo() { var inResponseTo = $"_{Guid.NewGuid()}"; var assertion = new Saml2Assertion(new Saml2NameIdentifier("__notused__")); assertion.Subject = new Saml2Subject(new Saml2NameIdentifier("__notused__")); var recipientUrl = new Uri("https://notused"); var token = new Saml2SecurityToken(assertion); token.SetRecipient(recipientUrl, inResponseTo); var bearers = token.Assertion.Subject.SubjectConfirmations.Where(c => c.Method == Saml2Constants.ConfirmationMethods.Bearer); Assert.Single(bearers); var data = bearers.Single().SubjectConfirmationData; Assert.NotNull(data); Assert.NotNull(data.InResponseTo); Assert.Equal(inResponseTo, data.InResponseTo.Value); }