copanier/copanier/utils.py
Yohan Boniface 782c08d5ee For now, log all incoming POST
We want to be able to debug any issue during a command.
Hint: DO MORE TESTS!
2019-04-02 19:51:38 +02:00

24 lines
506 B
Python

from datetime import datetime, timezone, timedelta
import jwt
from . import config
def utcnow():
return datetime.now(timezone.utc)
def create_token(email):
return jwt.encode(
{"sub": str(email), "exp": utcnow() + timedelta(days=7)},
config.SECRET,
config.JWT_ALGORITHM,
)
def read_token(token):
try:
return jwt.decode(token, config.SECRET, algorithms=[config.JWT_ALGORITHM])
except (jwt.DecodeError, jwt.ExpiredSignatureError):
return {}