Commit a8a79b3b authored by Ahmad Anvari's avatar Ahmad Anvari

Add utils for jwt

parent ede2d6df
from authlib.jose import jwt import jwt
def generate_jwt(user_id): def generate_jwt(user_id):
header = {'alg': 'RS256'} encoded = jwt.encode({'user_id': user_id}, 'secret', algorithm='HS256')
payload = {'iss': 'Authlib', 'sub': '123', 'user_id': user_id} return encoded.decode()
key = "SOME_KEY".encode()
return jwt.encode(header, payload, key)
def decode_jwt(jwt_token):
return jwt.decode(jwt_token, 'secret', algorithms=['HS256'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment