// Add authentication
services.AddAuthentication();
// Add OpenId Connect/OAuth2
services.AddOpenIddict()
.AddEntityFrameworkCoreStores<ApplicationDbContext>()
.AddMvcBinders()
.EnableTokenEndpoint("/connect/token")
.AllowPasswordFlow()
.AllowRefreshTokenFlow()
.UseJsonWebTokens() // access_token should be jwt
// You can disable the HTTPS requirement during development or if behind a reverse proxy
.DisableHttpsRequirement()
// Register a new ephemeral key, that is discarded when the application
// shuts down. Tokens signed using this key are automatically invalidated.
// To be used during development
.AddEphemeralSigningKey();
나는 다음과 같은 방법으로 JWT 미들웨어로 구성되어 :
// Add Jwt middleware for authentication
var secretKey = Configuration.Get<AppOptions>().Jwt.SecretKey;
app.UseJwtBearerAuthentication(new JwtBearerOptions
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
RequireHttpsMetadata = env.IsProduction(),
Audience = Configuration.Get<AppOptions>().Jwt.Audience,
Authority = Configuration.Get<AppOptions>().Jwt.Authority,
TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secretKey)),
ValidateIssuer = true,
// makes no difference seemingly being ignored
//ValidIssuer = Configuration.Get<AppOptions>().Jwt.Authority,
ValidateAudience = true,
ValidAudience = Configuration.Get<AppOptions>().Jwt.Audience,
ValidateLifetime = true,
}
});
// Add OpedId Connect middleware
app.UseOpenIddict();
당신은 발행자 서명 키는 대칭 키에 설정되어 볼 수 있듯이 :
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secretKey)),
하지만 JWT 작성일 생성 ess_tokens는 alg
주장은 RS256
로 설정, 그래서이 설정이 무시됩니다 보인다 openiddict는되어야한다 대칭 키를 사용하도록 openiddict을 강제하기 위해
.AddEphemeralSigningKey();
는 사실 아니, 당신이 정합 할 필요가 OpenIddict 옵션과 JWT 무기명 미들웨어 옵션 모두에서 서명 키를 입력하십시오. – Pinpoint
@Pinpoint OpenIdDictservice에서 설정 한 것만으로도 문제가 없습니다. –
정말 의심 스럽습니다. JWT 미들웨어 옵션에 대칭 서명 키를 등록하지 않으면 IdentityModel (JWT 미들웨어 뒤에있는 JWT 라이브러리)이'SecurityTokenInvalidSignatureException' ('IDX10500 : 서명 검증에 실패했습니다. 서명 검증을위한 보안 키가 제공되지 않았습니다 .') 사용자가 인증되지 않습니다. – Pinpoint