编程语言
首页 > 编程语言> > c#-将mvc 5 adfs转换为.net core adfs

c#-将mvc 5 adfs转换为.net core adfs

作者:互联网

我有一个现有的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

解决方法:

要回答您的第一个问题:

如果您不使用Azure,则无需担心AAD.实际上,您要确保未对.Wtrealm进行两次配置.因此,只需删除第二个.

要回答有关指纹和发行者的第二个问题:

我认为您不需要这些值,但是将它们包括在内似乎很有用,因为指纹和发行者值用于验证令牌.

我尝试在下面的代码中复制您的所有原始配置设置,这些代码属于startup.cs文件.您的x.509证书字符串值可以从MetadataAddress URL的xml文件中检索.它将在< X509Certificate>与标签.

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上发生什么.如果遇到问题,请随时告诉我.

标签:net-core,authentication,adfs,c,asp-net-mvc
来源: https://codeday.me/bug/20191108/2005518.html