IdentityServer4 ApiResource가 JwtBearerOption.Audience에서 작동하지 않는 이유는 무엇입니까?

Aug 18 2020

IdentityServer에이 구성이 있습니다.

public static IEnumerable<ApiResource> ApiResources =>
        new ApiResource[]
        {
            new ApiResource
            {
                Name = "MyApi"
            }
        };

ASP.NET Core 웹 API의이 jwt 구성 :

 services.AddAuthentication("Bearer")
       .AddJwtBearer("Bearer", options =>
       {
           //identity server
           options.Authority = "https://localhost:5001";

           //access token recepient
           options.Audience = "https://localhost:5001/resources";

           options.TokenValidationParameters = new TokenValidationParameters
           {
               ValidateAudience = true,
               ValidateLifetime = true,
           };
       });

Web API JwtBearerOption.Audience가 "MyApi"와 같지 않기 때문에 Web API 인증이 IdentityServer의 토큰을 수락하지 않을 것으로 예상합니다. 하지만 내 구성에서 대상은 대상이 "https : // localhost : 5001 / resources"로 설정된 경우에만 유효성이 검사되고 "MyApi"로 설정하면 무효화됩니다.

내 질문과 관련된 IdentityServer4 설명서.

답변

1 ToreNestenius Aug 18 2020 at 14:30

MyApi를 대상 목록에 포함하려면 IdentityServer4 (v4.0x)에서와 같이 ApiScope를 정의해야합니다.

자세한 내용은이 기사 를 참조하십시오.