gpt4 book ai didi

c# - Web API 2 Owin 刷新 token 不起作用并在其到期时间之前返回 invalid_grant

转载 作者:行者123 更新时间:2023-11-30 18:16:22 25 4
gpt4 key购买 nike

刷新 token 可以正常工作 2 到 3 天,但几天后它就停止工作了。

身份验证调用

grant_type = refresh_token

IIS 返回 Bad request 400 和错误信息

{error : "invalid_grant"}

临时解决方案

通过在 IIS 上重新启动/回收 API 实例可以正常工作。

无法找到 IIS 或 Owin 的问题是什么,为什么它可以在几天内正常工作,而我已将刷新 token 的到期时间设置为 30 天。

这是用于刷新 token 的代码

    var token = new RefreshToken()
{
RefreshTokenId = refreshTokenId,
ClientId = clientid,
UserEmail = context.Ticket.Identity.Name != clientid ? context.Ticket.Identity.Name : null,
IssuedOn = DateTime.UtcNow,
ExpiresOn = DateTime.UtcNow.AddDays(30)
};

context.Ticket.Properties.IssuedUtc = token.IssuedOn;
context.Ticket.Properties.ExpiresUtc = token.ExpiresOn;

token.ProtectedTicket = context.SerializeTicket();

对于有关此问题的任何帮助,我将不胜感激。

最佳答案

默认情况下,IIS 通过调用垃圾收集器每 20 分钟清除一次内存来回收您的应用程序池,因此如果您将刷新 token 存储在 ram 中(例如:静态字典或任何数据结构),它们将在之后被清理回收。这就是刷新 token 将不再有效的原因,即使它们的生命周期更长。

关于c# - Web API 2 Owin 刷新 token 不起作用并在其到期时间之前返回 invalid_grant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46704838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com