itfoxtec-identity-saml2 - 如何从 Azure 函数发出 IdP SAML 请求?
问题描述
我有一个简单的 C# Web 应用程序作为一系列 Azure Functions 实现。我希望能够将用户重定向到外部网站,当他们单击我的应用程序中的按钮时使用 SSO 登录。外部网站是 Absorb 的一个实例。Absorb提供了通过 SSO 使用商业产品ComponentSpace库来完成此操作的指南。
我想使用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(...);
}
解决方案
我认为不可能使用 SAML 2.0 保护 Azure 函数。SAML 2.0 用于 Web 应用程序,而不是 API。您可以通过发送 SAML 2.0 令牌作为 http 标头的一部分来保护 API,并在 API 中验证 SAML 2.0 令牌。
推荐阅读
- javascript - 在单独的文件中创建 TypeScript 类
- c# - 如何在 C# 的创建块内一行中检查变量类型
- java - UDisks2 的 Dbus 自省不完整?
- python - How to change a Global Variable while being in a FOR loop
- python-3.x - 如何获取具有最大行数的数据组 pandas
- azure - 在 Dynamics 365(通过 Azure 数据工厂)到 Azure SQL Server 之间传输数据的时区差异
- python - 如何使用 Python 脚本访问 Google Playstore API 以获取对我们应用程序的评论?
- typescript - 在 Vue 3 的 Jest 测试中模拟 vue-router 的 useRoute()
- java - 条件语句 If-Else Java 中的逻辑错误
- ibm-midrange - 使用电源中心连接到 AS400 上集成文件系统文件夹中的源