Spaces:
Sleeping
Sleeping
File size: 690 Bytes
6371c95 d6c726b 6371c95 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import os
import jwt
from jwt.exceptions import InvalidTokenError as jwtITError, DecodeError as jwtDError, InvalidSignatureError as jwtISError
import supabase
jwtKey: string = os.environ.get("JWTKey")
class User:
def __init__(self, username, token):
self.name = username
self.token = token # Tokens should be JWT
def validate(self):
try:
curToken = jwt.decode(self.token, jwtKey, algorithms="HS256")
except jwtDError:
return (false, "Validation failed")
try:
if curToken["username"] != self.name:
raise jwtDError
else:
return (true, "OK")
|