2016-12-06 90 views

回答

1

首先您需要使用客户端ID和重定向URL来设置ADFS,然后从ADFS服务器获取JWT令牌。看到这个帖子http://blog.scottlogic.com/2015/03/09/OAUTH2-Authentication-with-ADFS-3.0.html

在此之后,如果你使用的是.NET的核心与JWT承载令牌您使用以下PowerShell命令需要 出口ADFS签名证书:

$certRefs=Get-AdfsCertificate -CertificateType Token-Signing $certBytes=$certRefs[0].Certificate.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert) [System.IO.File]::WriteAllBytes("c:\foo.cer", $certBytes)

然后在你的.Net核心应用程序启动时,您需要使用包装Microsoft.AspNetCore.Authentication.JwtBearer看看这个帖子http://andrewlock.net/a-look-behind-the-jwt-bearer-authentication-middleware-in-asp-net-core/

代码在启动时类: var signingKey = new X509SecurityKey(new System.Security.Cryptography.X509Certificates.X509Certificate2("YOUR-PATH/foo.cer"));

 var tokenValidationParameters = new TokenValidationParameters 
     { 

      // The signing key must match! 
      ValidateIssuerSigningKey = true, 
      IssuerSigningKey = signingKey, 

      // Validate the JWT Issuer (iss) claim 
      ValidateIssuer = true, 
      ValidIssuer = "http://YOUR-ADFS/adfs/services/trust", 

      // Validate the JWT Audience (aud) claim 
      ValidateAudience = true, 
      ValidAudience = "https://YOUR-AUDIENCE/", 

      // Validate the token expiry 
      ValidateLifetime = true, 

      // If you want to allow a certain amount of clock drift, set that here: 
      ClockSkew = TimeSpan.Zero 
     }; 

     app.UseJwtBearerAuthentication(new JwtBearerOptions 
     { 
      AutomaticAuthenticate = true, 
      AutomaticChallenge = true, 
      TokenValidationParameters = tokenValidationParameters 
     });