Search code examples
pythongoogle-cloud-platformjwtiotgoogle-cloud-iot

Google Cloud IoT core JWT expiration is actually 24 hours?


Currently I'm programming my device as part of an IoT project with Google Cloud services.

Almost everything is working, but not all. I edited the original MQTT library for Python and it started to work correctly if I set the JWT token expiration to less than 2 hours

Is 24 hours a valid expiration time for a JWT token? Or maybe Im doing something wrong?

I'm using Raspberry PI 3B+ and Python 3.6.7

My JWT access and refresh token is the same as the one in the library from Google in Github. My library only runs it in multiple threads so that I could create multiple conections from the same device.

Edit: i modified this line in the create_jwt function...

'exp': datetime.datetime.utcnow() + datetime.timedelta(minute=20)

to

'exp': datetime.datetime.utcnow() + datetime.timedelta(hours=12)

Solution

  • Yes, the maximum lifetime of a JWT is 24 hours (plus a little to account for clock skew).

    Here's an excerpt from the docs page: 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.