2017-02-03 5 views
2

IdentityServer 3 웹 응용 프로그램을 하드웨어가 아닌 설치하려고합니다. 이는 소프트웨어 개발과 관련된 질문입니다. 나는 기술을 사용하고 API가 소비 할 수있는 JWT 토큰을 생성하는 방법을 배우려고 노력하고있다. 문제는 내가 토큰 만료를 설정할 위치를 찾을 수 없다는 것입니다. 약 1 시간 후에 항상 401이 생성됩니다. 이상적으로 테스트 목적으로 이것을 아주 오랫동안 연장하고 싶습니다. 그래서 JWT 토큰을 피들러에 복사하고 붙여 넣을 필요가 없으므로 개발과 학습 과정이 크게 저하됩니다. 클라이언트가 특정 주장에 사용IdentityServer 3에서 발행 한 JWT 토큰의 수명을 연장하는 방법

내 고객

new Client 
      { 
       ClientId = "scheduling" 
       ,ClientSecrets = new List<Secret> 
       { 
        new Secret("65A6A6C3-A764-41D9-9D10-FC09E0DBB046".Sha256()) 
       }, 
       ClientName = "Patient Scheduling", 
       Flow = Flows.ResourceOwner, 
       AllowedScopes = new List<string> 
       { 
        Constants.StandardScopes.OpenId, 
        Constants.StandardScopes.Profile, 
        Constants.StandardScopes.OfflineAccess, 
        "read", 
        "adprofile", 
        "scheduling" 
       }, 
       Enabled = true 
      } 

내 범위

new Scope 
      { 
       Name = "scheduling", 
       Claims = new List<ScopeClaim> 
       { 
        new ScopeClaim(Constants.ClaimTypes.Role,true), 
        new ScopeClaim("scheduling_id",true), 
        new ScopeClaim("expires_at",true) //I have tried "expires_in" and [Constants.ClaimTypes.Expiration] also with no luck 
       } 
      } 

방법 :

private IEnumerable<Claim> GetClaimByClientId(string client_id) 
    { 
     List<Claim> claims = new List<Claim>(); 
     switch(client_id.ToLower()) 
     { 
      case "scheduling": 
       claims = new List<Claim>(); 
       claims.Add(new Claim(ClaimTypes.Role,"administrator")); 
       claims.Add(new Claim("scheduling_id", "2")); 
       //claims.Add(new Claim("expires_in", "2082758400")); //01/01/2036 
       //claims.Add(new Claim(Constants.ClaimTypes.Expiration, "2082758400")); //01/01/2036 
       claims.Add(new Claim("expires_at", "2082758400")); //01/01/2036 
       break; 
      default: 
       throw new Exception("Client not found with provided client id."); 
     } 


     return claims; 
    } 

코드 실제로 검증하는 자격 증명 :

  if (ActiveDirectoryHelper.ValidateCredentials(context.UserName, context.Password, adName)) 
      { 

       List<Claim> lstClaims = new List<Claim> 
       { 
        new Claim("obj_id",user.UserID.ToUpper()), 
        new Claim(Constants.ClaimTypes.Email, string.IsNullOrEmpty(user.Email) ? string.Empty : user.Email.ToLower()), 
        new Claim(Constants.ClaimTypes.GivenName,user.FirstName), 
        new Claim(Constants.ClaimTypes.FamilyName,user.LastName), 
        new Claim("EmployeeNumber",user.EmployeeNumber), 


       }; 

       lstClaims.AddRange(GetClaimByClientId("scheduling")); 


       context.AuthenticateResult = new AuthenticateResult(user.UserID,user.Username, lstClaims); 
      } 
      else 
      { 
       context.AuthenticateResult = new AuthenticateResult("Invalid Login."); 
      } 

답변

1

액세스 토큰 수명은 Client 재산 AccessTokenLifetime를 사용하여 클라이언트 응용 프로그램을 설정할 수 있습니다 (I이 당신이 JWT 토큰 무엇을 의미하는 가정).

기본적으로이 값은 3600 초 (1 시간)로 설정됩니다.

+0

감사합니다. AccesTokenLifetime을 조사한 다음 문서로 이동했습니다. 고맙습니다. –