Web API 2 Owin刷新令牌不起作用,并且在其到期时间之前返回invalid_grant

问题描述 投票:3回答:1

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

关于身份验证致电

grant_type = refresh_token

IIS返回带有错误消息的错误请求400

{error:“ invalid_grant”}

临时解决方案>>

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

无法找到IIS或Owin的问题,为什么它在几天后仍能正常工作,而我为刷新令牌设置了30天的到期时间。

这是用于刷新令牌的代码

    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();

我将非常感谢您对此问题的任何帮助。

刷新令牌可在2到3天内正常工作,但几天后它将停止工作。在对Grant_type = refresh_token IIS的身份验证调用上,返回错误消息为{error:“ ...

c# iis asp.net-web-api2 owin
1个回答
0
投票

IIS默认情况下通过每20分钟调用一次垃圾回收器清除内存来回收您的应用程序池,因此,如果将刷新令牌存储在ram中(例如,静态字典或任何数据结构),它们将在回收。因此,即使刷新令牌的寿命更长,也将不再有效。

© www.soinside.com 2019 - 2024. All rights reserved.