2016-10-06 13 views
0

damienbod Ang2 Id Serv 4 OIDC에서 제공하는 예제 (아이덴티티 서버 (수정 된 구현), Resource API 및 ng-2 응용 프로그램)가있는 다음 예제를 따르고 있습니다.Identity Server : 토큰 유형 jwt vs OIDC를 사용한 암시 적 플로우 인증을 사용하는 참조

신원 확인 서버에서 인증을 받고 내 보호 된 API에 액세스하려고하면 오류 401 (인증되지 않음)이 표시됩니다.

참조 서버 대신 참조 대신 jwt의 토큰 유형을 사용하도록 클라이언트를 변경 한 다음 올바르게 작동했습니다. 신원 서버

클라이언트 구성 :

   ClientName = "angular2client", 
       ClientId = "angular2client", 
       AccessTokenType = AccessTokenType.Jwt,    
       AllowedGrantTypes = GrantTypes.Implicit, 
       AllowAccessTokensViaBrowser = true, 
       //redirect urls are ommited 
       AllowedScopes = new List<string> 
       { 
        "openid", 
        "resourceAPIs", 
        "role", 
       } 

자원 API 다음 JWT 토큰 유형을 만든 이유는 신원 확인이

내가 알 필요가
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions 
     { 
      Authority = "http://localhost:44311", 
      ScopeName = "resourceAPIs", 

      RequireHttpsMetadata = false 
     }); 

, 그것은 작동하고 어떤 코드 참조 유형 토큰이 작동하도록 수정하려면?

답변

2

참조 토큰을 사용하려면 범위 비밀을 제공해야합니다. docs

인트로 스페 크션 엔드 포인트를 참조 범위를 비밀을 사용하여 인증이 필요합니다.

신원 서버 :

  ClientName = "angular2client", 
      ClientId = "angular2client", 
      ClientSecrets = new List<Secret> 
      { 
       new Secret("secret".Sha256()) 
      }, 
      AccessTokenType = AccessTokenType.Jwt,    
      AllowedGrantTypes = GrantTypes.Implicit, 
      AllowAccessTokensViaBrowser = true, 
      //redirect urls are ommited 
      AllowedScopes = new List<string> 
      { 
       "openid", 
       "resourceAPIs", 
       "role", 
      } 

자원 서버

app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions 
    { 
     Authority = "http://localhost:44311", 
     ScopeName = "resourceAPIs", 
     ScopeSecret = "secret", 
     RequireHttpsMetadata = false 
    });