【问题标题】:What is the expiry date time of the access token?访问令牌的到期日期时间是多少?
【发布时间】:2018-06-17 02:38:22
【问题描述】:

当我们实施客户端凭据授权时 - Protecting an API using Client Credentials 在客户端需要生成新的访问令牌之前,访问令牌可使用多长时间(例如到期日期是什么)?

【问题讨论】:

  • 我认为默认的过期时间是 3600 秒。

标签: .net-core identityserver4 openid-connect


【解决方案1】:

创建客户端时,您可以定义访问令牌的生命周期

   var myClient =  new Client
    {
    ClientId = "testClient",
    AllowedGrantTypes = GrantTypes.ClientCredentials,
    ClientSecrets =
        {
        new Secret("secret".Sha256())
        },
        AllowedScopes = { "api1" },
        AccessTokenLifetime=3600
};

如果您不提供 AccessTokenLifetime,那么它将默认为 3600,即一小时。这意味着它将在创建后一小时过期

【讨论】:

    【解决方案2】:

    仅供参考, JWT 的到期将表示为 Unix 纪元。

    例如

    {
      "exp":1517988642,
       ...
    }
    

    可以在https://www.epochconverter.com/等工具中查看

    【讨论】:

      猜你喜欢
      • 2012-03-12
      • 1970-01-01
      • 2023-02-09
      • 1970-01-01
      • 2022-12-29
      • 2012-07-05
      • 2016-01-04
      • 1970-01-01
      • 2019-01-10
      相关资源
      最近更新 更多