2017-02-03 13 views
2

IdentityServer 3 Webアプリケーションをハードウェアでセットアップしようとしていますが、これはソフトウェア開発に関する質問です。私はこの技術を使い、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

アクセストークンの有効期間は、(私はこれがあなたがJWTトークンによって何を意味するかであると仮定)ClientプロパティAccessTokenLifetimeを使用して、クライアント・アプリケーション用に設定することができます。

デフォルトでは、これは3600秒(1時間)に設定されています。

+0

ありがとうございました。私はAccesTokenLifetimeを調べて、ドキュメントに連れて行ってくれました。どうもありがとうございました。 –

関連する問題