【问题标题】:how to use a business identity provider (e.g. ADFS2)如何使用企业身份提供者(例如 ADFS2)
【发布时间】:2012-11-20 12:17:22
【问题描述】:

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

在 VS 2012 中使用身份和访问工具

我选择使用企业身份提供商(例如 ADFS2)并输入 STS 元数据文档的 url。

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

修改了网页配置

<system.web>
...
<httpModules>
...
    <remove name="FormsAuthentication" />
</httpModules>
</system.web>

还有这个

<system.webServer>
...
   <modules>
   ...
      <remove name="FormsAuthentication" />
   </modules>
</system.webServer>

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

网站重定向到类似 http:// localhost /WebSite/login.aspx?ReturnUrl=%2fWebSite%2f 的 URL,其中出现“找不到资源”错误。

我还需要解决什么问题才能完成这项工作?

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-business-sts-e-g-adfs2.aspx

本地开发STSMS Identity and Access Tool MVC 4我已经有类似问题了

【问题讨论】:

    标签: asp.net-mvc-4 ws-federation


    【解决方案1】:

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

    先决条件:

    • 在您的域中某处运行的 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);
        }
    }
    }
    

    在 ADFS 2.0 服务器上

    • 如果您使用自签名证书,请导航到您的 Web 应用程序 https://{WEB APPLICATION URL}/ 并将区域更改为受信任的站点。
    • 在浏览器的地址栏中你应该可以右键点击证书并安装(你只能从受信任的站点安装证书)证书需要安装在 Trusted Root Authorities -> Registry 下,
    • 打开 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");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-28
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 2015-09-14
      • 1970-01-01
      • 2021-09-12
      • 2019-07-20
      相关资源
      最近更新 更多