0

鑑於:AspCore 2.0和IdentityServer v3中,目標對象驗證失敗

  • IdentityServer V3
  • 客戶端Web應用程序與aspcore 2.0

場景:

當使用aspcore 1.1與身份服務器v3我需要設置LegacyAudienceValidation = true(見.net core Client doesn't authenticate with IdentityServer v3 - Offset in Audience

現在我遷移到.NET的核心2.0。並且在這之後guide遷移身份還有其他選項,並在核心1.0

問題: 所以沒有了在LegacyAudienceValidation財產,結果我得到audienace驗證錯誤。

Microsoft.IdentityModel.Tokens.SecurityTokenInvalidAudienceException: IDX10208:無法驗證的觀衆。 validationParameters.ValidAudience爲空或空白和 validationParameters.ValidAudiences爲空。

我的客戶配置的代碼如下所示

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) 
    .AddJwtBearer(options => 
     { 
      options.Authority = Authority; 

我缺少的東西了aspcore API或者有任何提示如何解決這種差距?

+0

設置讓觀衆在API的名字。 options.Audience =「API名稱」 – maxspan

回答

0

您還可以使用IdentityServer4.AccessTokenValidation NuGet包,並設置LegacyAudienceValidation

services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) 
      .AddIdentityServerAuthentication(options => 
      { 
       options.Authority = "identityserver"; 
       options.ApiName = "yourapi"; 
       options.LegacyAudienceValidation = true; // to make core 2.0 work with idsrv3 
      });