mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
24 lines
506 B
Python
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 {}
|