【问题标题】:converting mvc 5 adfs to .net core adfs将 mvc 5 adfs 转换为 .net core adfs
【发布时间】:2019-05-02 19:03:37
【问题描述】:

我有一个成功使用本地活动目录联合服务的现有 mvc 5 应用程序

相关的网络配置设置

 <appSettings>
    <add key="ida:Issuer" value="https://www.fedsvc3copa.beta.pa.gov/adfs/ls/"/>
  </appSettings>

 <authority name="http://www.fedsvc3copa.beta.pa.gov/adfs/services/trust">
          <keys>
            <add thumbprint="xxxxxxxxxxxxxxx"/>
          </keys>
          <validIssuers>
            <add name="http://www.fedsvc3copa.beta.pa.gov/adfs/services/trust"/>
          </validIssuers>
        </authority>

           <federationConfiguration>
      <cookieHandler requireSsl="true"/>

      <wsFederation passiveRedirectEnabled="true" issuer="https://www.fedsvc3copa.beta.pa.gov/adfs/ls/" realm="https://localhost:44363/" requireHttps="true"/>
    </federationConfiguration>

尝试为 .net 核心 mvc 应用程序做同样的事情。但我有点困惑在startup.cs中放什么

我和https://docs.microsoft.com/en-us/aspnet/core/security/authentication/ws-federation?view=aspnetcore-2.1一起关注

所以我有

 .AddWsFederation(options =>
      {
        // MetadataAddress represents the Active Directory instance used to authenticate users.
        options.MetadataAddress = "https://www.fedsvc3copa.beta.pa.gov/federationmetadata/2007-06/FederationMetadata.xml";

        // Wtrealm is the app's identifier in the Active Directory instance.
        // For ADFS, use the relying party's identifier, its WS-Federation Passive protocol URL:
        options.Wtrealm = "https://localhost:44363/";

        // For AAD, use the App ID URI from the app registration's Properties blade:
        options.Wtrealm = "???????";
      });

我不知道在 AAD 领域中应该放什么,因为我没有使用 azure。我也不需要指纹和发行人吗? http://www.fedsvc3copa.beta.pa.gov/adfs/services/trust

【问题讨论】:

  • 您不需要在最后一个属性中提供任何内容,即您填写的???。文档显示了两种不同的方式,请注意属性名称与上面的相同。第一个 .Wtrealm 示例用于 ADFS,第二个示例用于 AAD。只需删除第二个。我不熟悉这个特定的 Active Directory 设置,只是从文档中注意到。
  • 是的,我试过了,它会将我带到 orgs 登录页面,但我收到错误错误发生错误发生。有关详细信息,请联系您的管理员。错误详细信息 活动 ID:c2667d30-335f-4da5-6b0a-0080010000e4 错误时间:2019 年 5 月 6 日星期一 17:32:05 GMT Cookie:已启用 用户代理字符串:Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36 (KHTML,如 Gecko)Chrome/74.0.3729.131 Safari/537.36

标签: c# asp.net-mvc authentication .net-core adfs


【解决方案1】:

回答你的第一个问题:

如果您不使用 Azure,则无需担心 AAD。实际上,您要确保 .Wtrealm 没有配置两次。所以只需删除第二个。

回答关于指纹和发行人的第二个问题:

我认为您需要这些值,但它们可能会很好地包括查看指纹和颁发者值用于验证令牌。

我已尝试在下面的代码中复制您的所有原始配置设置,这些设置属于 startup.cs 文件。 your x.509 cert string 值可以从位于 MetadataAddress url 的 xml 文件中检索。它将在&lt;X509Certificate&gt; 标签之间。

var rawCertData = Convert.FromBase64String("your x.509 cert string");
X509Certificate2 cert = new X509Certificate2(rawCertData);
SecurityKey signingKey = new X509SecurityKey(cert);
    services.AddAuthentication()
        .AddWsFederation(options => {
            options.MetadataAddress = "https://www.fedsvc3copa.beta.pa.gov/federationmetadata/2007-06/FederationMetadata.xml";
            options.Wtrealm = "https://localhost:44363/";
            options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters {
                ValidateIssuer = true,
                ValidIssuer = "http://www.fedsvc3copa.beta.pa.gov/adfs/services/trust",
                ValidateIssuerSigningKey = true,
                IssuerSigningKey = signingKey
            };
            options.RequireHttpsMetadata = true;
        }).AddCookie(cookieoption => {
            cookieoption.Cookie.SecurePolicy = CookieSecurePolicy.Always;
        });

注意:通过此配置,我可以访问您的 adfs 登录页面。但是,我无法登录,因为我没有权限;所以我不知道你登录后 POST 会发生什么。如果你有问题,请随时告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    • 2018-05-13
    相关资源
    最近更新 更多