Google Cloud IoT 核心 JWT 有效期实际上是 24 小时?
Google Cloud IoT core JWT expiration is actually 24 hours?
目前,我正在使用 Google 云服务对我的设备进行编程,作为 IoT 项目的一部分。
几乎一切正常,但不是全部。 我为 Python 编辑了原始 MQTT 库,如果我将 JWT 令牌到期时间设置为少于 2 小时,它就会开始正常工作
24 小时是 JWT 令牌的有效到期时间吗?或者我做错了什么?
我正在使用 Raspberry PI 3B+ 和 Python 3.6.7
我的 JWT 访问和刷新令牌与 Github 中 Google 库中的令牌相同。我的库只在多个线程中运行它,以便我可以从同一设备创建多个连接。
编辑:我在 create_jwt
函数中修改了这一行...
'exp': datetime.datetime.utcnow() + datetime.timedelta(minute=20)
到
'exp': datetime.datetime.utcnow() + datetime.timedelta(hours=12)
此问题的一个可能原因是您的 Raspberry Pi 时钟设置不正确。例如,系统时钟可能设置为本地时间而不是 UTC。确保 运行 date --utc
returns 正确的 UTC 时间。
是的,JWT 的最长生命周期为 24 小时(加上一点以解决时钟偏差)。
以下是文档页面的摘录:https://cloud.google.com/iot/docs/how-tos/credentials/jwts
("Expiration"): The timestamp when the token stops being valid, specified as seconds since 00:00:00 UTC, January 1, 1970. The maximum lifetime of a token is 24 hours + skew.