3

IS4 Identity 샘플을 기반으로하는 IdentityServer4 앱과 IS4.AccessTokenValidation을 통한 권한 부여를위한 베어러 토큰을 사용하는 API가 있습니다. 이것은 VisualStudio를 통해 localhost에서 잘 작동하고, Windows 2012 VM에 배포하고 IIS를 통해 호스팅 할 때 작동합니다. App Service 웹 사이트로 Identity 서버를 Azure에 배포하면 모두 괜찮습니다. 그러나 API가 VM과 동일한 도메인 및 인증서를 사용하는 App Service로 배포되면 Authorize 속성 (정책이 있거나 전혀 상관 없음)이있는 메소드는 항상 헤더 메시지가있는 401을 반환합니다.IdentityServer4 권한 부여는 Azure AppService에서 "서명 키를 찾을 수 없음"을 항상 얻습니다.

Www-Authenticate: Bearer error="invalid_token", error_description="The signature key was not found" 

우리는 최신 버전의 IdentityServer4 및 IdentityServer4.AccessTokenValidation 패키지와 함께 .NET 4.5.2를 사용하고 있습니다. 또한 GitHub의 최신 패키지를 30/08/16부터 변경없이 가져 왔습니다. 어쨌든 IS4 검사기가 버그라고 생각하지 않지만 무엇이 일지 모르겠다.이 원인이됩니다. 어떤 제안? Azure 호스트 버그입니까?

이 디버깅 할 수 있도록하고 싶지만 원격 디버그를 처음부터 다시 작성한 경우에도이 응용 프로그램에서 작동하지 못하고 응용 프로그램 로그에 아무것도 표시되지 않습니다. ASP.NET Security repo에서 난처한 점이 있었지만, 더 많은 로깅이나 디버그 액세스가 없으면이 문제를 해결하는 방법이 꽤 우둔합니다.

var jwtBearerOptions = new JwtBearerOptions() 
     { 
      Authority = Configuration["Authentication:IdentityServer:Server"], 
      Audience = Configuration["Authentication:IdentityServer:Server"]+"/resources", 
      RequireHttpsMetadata = false, 

      AutomaticAuthenticate = true, 
      AutomaticChallenge = true, 
     }; 
     app.UseJwtBearerAuthentication(jwtBearerOptions); 

과 신원 서버는 바로 샘플의 부족, 서명에 구입 한 인증서를 사용 :

API 구성은 아주 기본적인 것입니다.

누구나이 구성을 2 개의 Azure App Services로 완벽하게 작동 시켰습니까? 또는 VM 호스트 API로 전송 된 동일한 전달자 토큰이 허용되면이 오류가 발생할 수 있습니다.

+0

idsrv3에 대한 비슷한 사례가 https://gitter.im/IdentityServer/IdentityServer3/archives/2015/04/13에서 논의되었습니다. 내가 이해하는 것은 신원 서버 메타 데이터 ('.well-known/opened-configuration')를 얻지 못하면서 발생하는 문제이다. 또한 더 많은 로깅을 위해서,'api'에서 aspnet core logging을 설정하고 (serilog로 텍스트 파일에 로그를 쓸 수 있도록), 에러 로그를 검사하십시오. –

+0

해당 스레드에서 토큰 크기에 대한 흥미로운 가능성. 내 것은 상당히 크지 만 모든 호스트에서 문제가 될 것으로 기대합니다. 그것으로 놀 것입니다. 당신은 로깅에 관해서, 나는 Serilog를 추가 할 것이다. 나오는 내용보기. – user1587195

+0

로깅을 더 많이 얻으려면 보안 레포 코드를 살펴보아야합니다. 어떤 이유로 App App의 SigningKey 유효성 검사 옵션에 차이가 있어야합니다. – user1587195

답변

3

명시 적으로 IssuerSigningKeyTokenValidationParameters에 설정해야합니다. 그래서 App Service 스토어에서 인증서를 받아 JwtBearerOptions.TokenValidationParameters을 통해 추가합니다. 그래서 시작 구성은 다음과 같습니다 :

 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
    { 
     ... 
     JwtSecurityTokenHandler.DefaultInboundClaimTypeMap = new Dictionary<string, string>(); 
     var tokenValidationParameters = new TokenValidationParameters 
     { 
      // The signing key must match! 
      ValidateIssuerSigningKey = true, 
      IssuerSigningKey = new X509SecurityKey(GetSigningCertificate()), 

      // Validate the JWT Issuer (iss) claim 
      ValidateIssuer = false, 
      //ValidIssuer = "local", 

      // Validate the JWT Audience (aud) claim 
      ValidateAudience = false, 
      //ValidAudience = "ExampleAudience", 

      // Validate the token expiry 
      ValidateLifetime = true, 

      // If you want to allow a certain amount of clock drift, set that here: 
      ClockSkew = TimeSpan.Zero 
     }; 
     var jwtBearerOptions = new JwtBearerOptions() 
     { 
      Authority = Configuration["Authentication:IdentityServer:Server"], 
      Audience = Configuration["Authentication:IdentityServer:Server"]+"/resources", 
      RequireHttpsMetadata = false, 

      AutomaticAuthenticate = true, 
      AutomaticChallenge = true, 

      TokenValidationParameters = tokenValidationParameters 
     }; 
     app.UseJwtBearerAuthentication(jwtBearerOptions); 

     app.UseMvc(); 
     ... 
    } 

Azure App 서비스에서만 필요하며 서버 또는 개발 컴퓨터에서는 필요하지 않은 이유는 알 수 없습니다. 다른 사람이 설명 할 수 있습니까? App Service에 대해 ValidateIssuerSigningKey 기본값을 true로 제안하고 다른 곳에서는 false로 지정합니다.