AWS Cognito and Lambda: JWT expiration



我遵循了无服务器框架中的此示例,以便创建一个用作授权方的 Lambda:

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

从我的客户端,我能够获得令牌,但时区存在问题,当我尝试提出一些请求时,它一直返回我">未经授权"。

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

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(。

最新更新