如何使用业务标识提供程序(例如ADFS2)

Pet*_*ter 4 ws-federation asp.net-mvc-4

我正在运行Win 7,IIS 7.0,VS2012我已经创建了asp.mvc4 web应用程序我在单独的VM上有ADFS2.0

使用VS 2012中的Identity and Access工具

我选择使用业务标识提供程序(例如ADFS2)并键入STS元数据文档的URL.

HTTPS://server.local/federationmetadata/2007-06/federationmetadata.xml

编辑了Web配置

<system.web>
...
<httpModules>
...
    <remove name="FormsAuthentication" />
</httpModules>
</system.web>
Run Code Online (Sandbox Code Playgroud)

还有这个

<system.webServer>
...
   <modules>
   ...
      <remove name="FormsAuthentication" />
   </modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

还检查了为项目禁用了Windows身份验证

该网站重定向到这样的URL http:// localhost /WebSite/login.aspx?ReturnUrl=%2fWebSite%2f,其中包含"无法找到资源"错误.

我还有什么可以帮助你做这项工作?

Microsoft doco是轻量级的http://blogs.msdn.com/b/vbertocci/archive/2012/03/15/windows-identity-foundation-tools-for-visual-studio-11-part-iii-connecting-with -a-企业STS-EG-adfs2.aspx

我已经遇到过与本地开发STS MS Identity and Access Tool MVC 4类似的问题

Pet*_*ter 6

好的,这花了我几天的时间来解决,但这些是我为了让它运行而做的事情.还有很多工作要做.

先决条件:

  • 在您的域上的某个位置运行的ADFS 2.0服务.
  • IIS 7具有自签名证书或可在您的域中使用的证书.
  • 安装了Identity and Access(版本1.0.2)扩展的Visual Studio 2012.
  • 设置为在IIS上运行的MVC4 Web应用程序.
  • 确保将自签名证书添加到站点,以便您可以通过https访问它.
  • 您可能必须调整计算机的防火墙设置以允许访问ADFS 2.0服务.

论发展工作站

在你的MVC4项目中

  • 右键单击Web项目,打开"身份和访问"对话框.
  • 选择使用业务标识提供程序(例如ADFS2)
  • 输入STS元数据文档的路径,例如https:// {PATH TO ADFS SERVER} /FederationMetadata/2007-06/FederationMetadata.xml
  • 输入您的应用领域,例如https:// {WEB APPLICATION URL} /
  • 尾随斜线有所不同.
  • 通过接受这些更改退出对话框.

将以下代码添加到项目中

using System;
using System.IdentityModel.Services;

namespace NAMESPACE
{
    public class FixedWsFederationAuthenticationModule : WSFederationAuthenticationModule
    {
        public override void RedirectToIdentityProvider(string uniqueId, string returnUrl, bool persist)
    {
        //This corrects WIF error ID3206 "A SignInResponse message may only redirect within the current web application:"
        //First Check if the request url doesn't end with a "/"
        if (!returnUrl.EndsWith("/"))
        {
            //Compare if Request Url +"/" is equal to the Realm, so only root access is corrected
            //https://localhost/AppName plus "/" is equal to https://localhost/AppName/
            //This is to avoid MVC urls
            if (String.Compare(System.Web.HttpContext.Current.Request.Url.AbsoluteUri + "/", base.Realm, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                //Add the trailing slash
                returnUrl += "/";
            }
        }
        base.RedirectToIdentityProvider(uniqueId, returnUrl, persist);
    }
}
}
Run Code Online (Sandbox Code Playgroud)

在ADFS 2.0服务器上

  • 如果您使用自签名证书,请导航到您的Web应用程序https:// {WEB APPLICATION URL} /并将区域更改为可信站点.
  • 在浏览器的地址栏中,您应该能够右键单击证书并安装(您只能从受信任的站点安装证书)证书需要安装在受信任的根权限 - >注册表中,
  • 打开ADFS控制台,添加信赖方信任,使用联合元数据地址https:// {WEB APPLICATION URL} /FederationMetadata/2007-06/FederationMetadata.xml

添加一些自定义规则

MVC4需要这些规则才能生成可用的ClaimsPrincipal

在Name属性上添加传递规则.

而这两个自定义规则

=> issue(Type = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", Value = "true");

=> issue(Type = "http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", Value = "true");
Run Code Online (Sandbox Code Playgroud)