一連の Azure 関数として実装された単純な C# Web アプリがあります。ユーザーがアプリのボタンをクリックしたときに SSO を使用してログインし、ユーザーを外部 Web サイトにリダイレクトできるようにしたいと考えています。外部 Web サイトは Absorb のインスタンスです。Absorbは、商用製品であるComponentSpaceライブラリを使用して SSO を介してこれを実現するためのガイドを提供します。
無料でオープン ソースのITfoxtec SAML 2.0ライブラリを使用したいと考えています(ただし、無料のオープン ソース ライブラリであれば何でも構いません)。
私の質問は次のとおりです。
- Saml2Assertion を Saml2AuthnResponse に追加するにはどうすればよいですか?
- redirectBinding を使用して HttpResponseMessage を返すにはどうすればよいですか?
これが私がこれまでに持っているものです:
[FunctionName("GoToAbsorb")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)]HttpRequestMessage request, TraceWriter log)
{
// User is authenticated and here.
// SAML part starts here.
Saml2Configuration configuration = new Saml2Configuration();
configuration.SigningCertificate = GetCertificate(); // Returns an X509 Certificate
configuration.AllowedAudienceUris.Add(configuration.Issuer);
Saml2AuthnResponse samlResponse = new Saml2AuthnResponse(configuration);
samlResponse.Destination = new Uri("https://sample.myabsorb.com/account/saml");
samlResponse.Issuer = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME");
samlResponse.Status = ITfoxtec.Identity.Saml2.Schemas.Saml2StatusCodes.Success;
Saml2Subject subject = new Saml2Subject(new Saml2NameIdentifier("Id"));
subject.SubjectConfirmations.Add(new Saml2SubjectConfirmation(new Uri("https://sample.myabsorb.com/account/saml")));
var assertion = new Saml2Assertion(new Saml2NameIdentifier(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")));
assertion.Conditions = new Saml2Conditions()
{
NotBefore = DateTime.Now,
NotOnOrAfter = DateTime.Now.AddMinutes(3),
};
assertion.Statements.Add(new Saml2AuthenticationStatement(new Saml2AuthenticationContext()
{
// There does not appear to be an equivalent to the following line
// AuthnContextClassRef = new AuthnContextClassRef(SAMLIdentifiers.AuthnContextClasses.Password)
}));
// How do I add the assertion to the response?
Saml2RedirectBinding redirectBinding = new Saml2RedirectBinding();
redirectBinding.Bind(samlResponse);
// What do I return as the response message?
return new HttpResponseMessage(...);
}