我们可以设置访问令牌不会过期吗?

时间:2018-01-08 07:19:21

标签: c# .net-core identityserver4

我们使用的是Identity Server4,默认时间是访问令牌过期是3600秒。我们可以将其设置为不过期吗?

public static IEnumerable<Client> GetClients()
    {
        return new List<Client>
         {
         new Client
        {
        ClientId = "client",

        // no interactive user, use the clientid/secret for authentication
            AllowedGrantTypes = GrantTypes.ClientCredentials,

        // secret for authentication
            ClientSecrets =
            {
            new Secret("secret".Sha256())
            },

        // scopes that client has access to
            AllowedScopes = { "api1" },
            AccessTokenLifetime=3600
    }
};

1 个答案:

答案 0 :(得分:3)

从技术上讲,AccessTokenLifetime被声明为int,因此你可以做到

AccessTokenLifetime = Int32.MaxValue;

但这真的不是一个好主意。创建访问令牌后,它将继续工作,我不认为你在支持中过期它将按照你的意愿工作。

为了它的乐趣

TimeSpan t = TimeSpan.FromSeconds(Int32.MaxValue);
Console.WriteLine(t.Days);

导致非常难看的24855天或68年。

相关问题