【问题标题】:How to implement SSO using SAML in the existing ASP.net application如何在现有 ASP.net 应用程序中使用 SAML 实现 SSO
【发布时间】:2016-03-08 00:15:32
【问题描述】:
我需要在我们的一个 ASP.net Web 应用程序中为客户端实现单点登录 (SSO)。为此,我需要使用以下协议之一。
- WS-Fed
- SAML
身份提供者(客户的域)是 Microsoft Azure Active Directory。
我已经搜索了互联网,但找不到任何有用的实现。
如果您有过这种经历,请与我分享您的发现。
【问题讨论】:
标签:
asp.net
single-sign-on
saml
azure-active-directory
ws-federation
【解决方案1】:
最简单的方法是使用 Katana 中间件。将 OWIN Startup 类添加到您的项目中,并将其添加到 Configuration 方法中:
var tenant = "yourdirectory.onmicrosoft.com";
var directory = "https://login.microsoftonline.com";
var metadataAddress = string.Format(
"{0}/{1}/FederationMetadata/2007-06/FederationMetadata.xml",
directory, tenant);
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = metadataAddress
});
您可以找到完整的工作示例on Github。
【解决方案2】:
如果您的 ASP.NET 应用程序是服务提供者 (SP)。然后一个选项是利用 Windows Identity Foundation (WIF) 库。根据您的 ASP.NET Web 应用程序使用的 .NET 版本,将标签添加到 web.config 的方式会略有不同。对于 .NET 4.5,您将引入 system.identity.model,然后通过 <system.identityModel> 配置配置 WS-Federation,并且您需要使用 <wsfederation> 被动重定向设置 <system.identityModel.services> 配置。该配置要求您将颁发者设置为 Microsoft Azure IdP。 WIF 库处理与 IdP 的所有通信和协议,因此通过 WS-Federation 返回的嵌入式 SAML v1.1 令牌的属性可通过 ClaimsIdentity 对象提供给您的应用程序。
【解决方案3】:
如果您追求的是商业产品,我们的 ComponentSpace SAML v2.0 库可让您的 ASP.NET 应用程序充当 SAML SSO 中的身份提供者或服务提供者。只需引用我们的 DLL 并调用我们的 API 即可启用 SAML SSO。更多信息,包括免费评估下载,请访问http://www.componentspace.com。