.Net Core에서 OAuth2 JWT 토큰 생성 및 검증에 대해 설명 할 수 있습니까?ADFS 및 .Net 코어 용 OAuth2 JWT 토큰
답변
먼저 클라이언트 ID와 리디렉션 URL로 ADFS를 설정 한 다음 ADFS 서버에서 JWT 토큰을 얻어야합니다. 닷넷에서 다음
$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)
: 당신이 JWT 무기명 토큰과 닷넷 코어를 사용하는 경우 다음과 같은 PowerShell을 명령을 사용하여 수출 ADFS 서명 인증서에 필요한이 게시물을 그 후 http://blog.scottlogic.com/2015/03/09/OAUTH2-Authentication-with-ADFS-3.0.html
를 참조하십시오 핵심 응용 프로그램을 시작, 당신은 시작까지 수업 시간에 http://andrewlock.net/a-look-behind-the-jwt-bearer-authentication-middleware-in-asp-net-core/
코드를 패키지 에게 Microsoft.AspNetCore.Authentication.JwtBearer를 사용하고이 게시물을 볼 필요가 : 01,235, 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
});
아래의 링크를 확인하십시오. 도움말은 동일하지만 절차는 동일합니다.
https://www.codeproject.com/Articles/1080899/How-to-get-Jwt-token-for-Logged-On-User-or-Applica
OAuth2를 부여 제공자 1.0.0 nuget 패키지 (ValidateToken)는 토큰 JWT 주어진 검증하는 방법을 가지고 있지만 인증서 의존성 (공급자)를 갖는다.
adfs 인증서 인 로컬 컴퓨터의 신뢰할 수있는 루트에 인증서를 설치하십시오.
Nuget 패키지는 SubjectKeyIdentifier를 기반으로 설치된 인증서를 식별합니다.