具有现有 ASP.Net MVC 应用程序的 ADFS
ADFS with existing ASP.Net MVC App
我一直在四处寻找,试图找到一个示例来说明如何将 ADFS 身份验证添加到现有 ASP.Net MVC 应用程序。我找到了很多关于如何在创建新应用程序时使用向导进行操作的示例。
我可以创建一个新的应用程序并复制代码和配置,但这种接缝就像一种奇怪的方法。
有人知道好的指南或资源吗?
我们发现 Cloud Identity 上的这篇博客文章对于开始类似的事情非常有帮助。我们使用的是 Web API,因此并不完全相同。
您需要将此添加到您的 Startup.Auth.cs 文件中:
app.UseActiveDirectoryFederationServicesBearerAuthentication(
new ActiveDirectoryFederationServicesBearerAuthenticationOptions
{
Audience = ConfigurationManager.AppSettings["ida:Audience"],
MetadataEndpoint = ConfigurationManager.AppSettings["ida:MetadataEndpoint"]
});
在您的 web.config 中,您将需要指向这些条目的键:
<add key="ida:AdfsMetadataEndpoint" value="https://adfs.yourdomain.com/federationmetadata/2007-06/federationmetadata.xml" />
<add key="ida:Audience" value="https://yourmvc.yourdomain.com" />
请注意,您使用的 ADFS 版本有很大的不同。我们发现,在尝试让令牌与 ADFS 3.0 版一起工作时,它们目前有些损坏。本地 ADFS 的工作方式也与 Azure 大不相同。
我们需要为我们的实施定制声明,this post 帮了大忙。 Startup.Auth.cs 看起来类似于:
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Audience = ConfigurationManager.AppSettings["ida:Audience"],
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
Provider = new OAuthBearerAuthenticationProvider()
{
OnValidateIdentity = async context =>
{
context.Ticket.Identity.AddClaim(
new Claim(http://mycustomclaims/hairlenght,
RetrieveHairLenght(userID),
ClaimValueTypes.Double,
"LOCAL AUTHORITY");));
}
}
});
我一直在四处寻找,试图找到一个示例来说明如何将 ADFS 身份验证添加到现有 ASP.Net MVC 应用程序。我找到了很多关于如何在创建新应用程序时使用向导进行操作的示例。
我可以创建一个新的应用程序并复制代码和配置,但这种接缝就像一种奇怪的方法。
有人知道好的指南或资源吗?
我们发现 Cloud Identity 上的这篇博客文章对于开始类似的事情非常有帮助。我们使用的是 Web API,因此并不完全相同。
您需要将此添加到您的 Startup.Auth.cs 文件中:
app.UseActiveDirectoryFederationServicesBearerAuthentication(
new ActiveDirectoryFederationServicesBearerAuthenticationOptions
{
Audience = ConfigurationManager.AppSettings["ida:Audience"],
MetadataEndpoint = ConfigurationManager.AppSettings["ida:MetadataEndpoint"]
});
在您的 web.config 中,您将需要指向这些条目的键:
<add key="ida:AdfsMetadataEndpoint" value="https://adfs.yourdomain.com/federationmetadata/2007-06/federationmetadata.xml" />
<add key="ida:Audience" value="https://yourmvc.yourdomain.com" />
请注意,您使用的 ADFS 版本有很大的不同。我们发现,在尝试让令牌与 ADFS 3.0 版一起工作时,它们目前有些损坏。本地 ADFS 的工作方式也与 Azure 大不相同。
我们需要为我们的实施定制声明,this post 帮了大忙。 Startup.Auth.cs 看起来类似于:
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Audience = ConfigurationManager.AppSettings["ida:Audience"],
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
Provider = new OAuthBearerAuthenticationProvider()
{
OnValidateIdentity = async context =>
{
context.Ticket.Identity.AddClaim(
new Claim(http://mycustomclaims/hairlenght,
RetrieveHairLenght(userID),
ClaimValueTypes.Double,
"LOCAL AUTHORITY");));
}
}
});