【问题标题】:Exceptions from JwtSecurityTokenHandlerJwtSecurityTokenHandler 的异常
【发布时间】:2014-08-24 02:43:58
【问题描述】:

我将 Json Web Tokens 用于我的 ASP.NET Web API...和 ​​thinktectures 身份模型。

所以在我的 web api Startup.cs 中,我调用 IdentityModelJwtBearerAuthenticationExtensions 扩展方法,如下所示:

app.UseJsonWebToken(
    issuer: Constants.IssuerName, 
    audience: Constants.Audience, 
    signingKey: Constants.SigningKey
);

然后我用 AuthorizeAttribute 装饰我的 API 控制器。

好的,很好,很好!都很好。

但是当令牌过期时......我得到的只是未经授权的 401。

我想让 JwtSecurityTokenHandler 中的 SecurityTokenValidationException(“生命周期验证失败。令牌已过期”)冒泡并在 Web API 中可见。

我该怎么做?

我环顾四周,找不到正确的方向。

和 JwtBearerAuthenticationOptions 有关系吗?

为任何智慧干杯。

【问题讨论】:

    标签: c# oauth-2.0 jwt thinktecture-ident-server thinktecture-ident-model


    【解决方案1】:

    这不是 Katana 身份验证中间件的工作方式。如果验证失败,则不会填充任何主体,因此授权将失败。

    此外,您的 Web api 对此也无能为力,需要采取适当措施的是客户端。在 OAuth 中,还需要客户端跟踪过期时间。

    【讨论】:

    • 感谢您的回复!所以我应该在 Web API 级别的自定义授权属性中检查令牌是否已过期?
    • 没有。您无法区分无令牌和过期令牌。你为什么在乎?这是客户关心的问题。
    • 客户端是调用 webapi 的人吗?
    猜你喜欢
    • 2014-10-30
    • 2018-05-20
    • 2018-05-01
    • 2014-10-24
    • 2013-08-04
    • 2020-01-10
    • 2013-11-05
    • 1970-01-01
    • 2018-09-09
    相关资源
    最近更新 更多