Close #3: forgot/reset password routes

This commit is contained in:
François Voron
2019-10-13 12:05:10 +02:00
parent ef1f60d7e5
commit 49daeff869
9 changed files with 305 additions and 37 deletions

14
fastapi_users/utils.py Normal file
View File

@ -0,0 +1,14 @@
from datetime import datetime, timedelta
import jwt
JWT_ALGORITHM = "HS256"
def generate_jwt(
data: dict, lifetime_seconds: int, secret: str, algorithm: str = JWT_ALGORITHM
) -> str:
payload = data.copy()
expire = datetime.utcnow() + timedelta(seconds=lifetime_seconds)
payload["exp"] = expire
return jwt.encode(payload, secret, algorithm=algorithm).decode("utf-8")