1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

remove legacy jwt encoding module

This commit is contained in:
thatmattlove
2021-12-22 22:25:09 -07:00
parent dfca1a5bc1
commit 16e9dc82fa

View File

@ -1,26 +0,0 @@
"""Handle JSON Web Token Encoding & Decoding."""
# Standard Library
import datetime
# Third Party
import jwt
async def jwt_decode(payload: str, secret: str) -> str:
"""Decode & validate an encoded JSON Web Token (JWT)."""
decoded = jwt.decode(payload, secret, algorithm="HS256")
decoded = decoded["payload"]
return decoded
async def jwt_encode(payload: str, secret: str, duration: int) -> str:
"""Encode a query to a JSON Web Token (JWT)."""
token = {
"payload": payload,
"nbf": datetime.datetime.utcnow(),
"iat": datetime.datetime.utcnow(),
"exp": datetime.datetime.utcnow() + datetime.timedelta(seconds=duration),
}
encoded = jwt.encode(token, secret, algorithm="HS256").decode("utf-8")
return encoded