【问题标题】:AWS Cognito and Lambda: JWT expirationAWS Cognito 和 Lambda:JWT 到期
【发布时间】:2018-08-15 07:21:59
【问题描述】:

我按照无服务器框架中的这个示例创建了一个 Lambda 以用作授权方:

https://github.com/serverless/examples/blob/master/aws-node-auth0-cognito-custom-authorizers-api/auth.js

我可以从我的客户那里获得令牌,但时区存在问题,当我尝试提出一些请求时,它不断返回“未经授权”。

我的 Lambda 托管在 eu-west-1 中,Cognito iss 生成一个令牌,该令牌的过期日期与 lambda 区域的时间相比为 -1 小时(有效期为 3600秒)所以当我尝试发出一些请求时,令牌已经过期。 从我的示例中查看代码,我该如何解决这个问题? 关于这个主题的 jsonwebtoken 文档对我来说不是很清楚。

【问题讨论】:

    标签: amazon-web-services aws-lambda jwt amazon-cognito


    【解决方案1】:

    JWT 规范建议将日期值设置为NumericDate

    A JSON numeric value representing the number of seconds from 
    1970-01-01T00:00:00Z UTC until the specified UTC date/time, ignoring leap 
    seconds. This is equivalent to the IEEE Std 1003.1, 2013 Edition [POSIX.1] 
    definition "Seconds Since the Epoch", in which each day is accounted for by 
    exactly 86400 seconds, other than that non-integer values can be 
    represented. See RFC 3339 [RFC3339] for details regarding date/times in 
    general and UTC in particular.
    

    这意味着应该考虑时区。因此,只需确保您的 iat / exp 声明中包含时区,或者签名者和验证者使用相同的时区(例如,标准 UTC)。

    【讨论】:

    • 谢谢,我在验证之前已将日期转换为 UTC,并且成功了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 2016-08-28
    • 2018-12-16
    • 2019-03-26
    • 2017-12-30
    • 2020-06-22
    • 2021-08-28
    相关资源
    最近更新 更多