mirror of
https://github.com/wangdage12/Snap.Server.git
synced 2026-02-18 02:42:12 +08:00
初始提交
This commit is contained in:
18
app/utils/jwt_utils.py
Normal file
18
app/utils/jwt_utils.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import jwt
|
||||
import datetime
|
||||
from flask import current_app
|
||||
from app.config_loader import config_loader
|
||||
|
||||
def create_token(user_id):
|
||||
payload = {
|
||||
"user_id": user_id,
|
||||
"exp": datetime.datetime.utcnow() + datetime.timedelta(hours=config_loader.JWT_EXPIRATION_HOURS)
|
||||
}
|
||||
return jwt.encode(payload, current_app.config["SECRET_KEY"], algorithm=config_loader.JWT_ALGORITHM)
|
||||
|
||||
def verify_token(token):
|
||||
try:
|
||||
data = jwt.decode(token, current_app.config["SECRET_KEY"], algorithms=[config_loader.JWT_ALGORITHM])
|
||||
return data["user_id"]
|
||||
except:
|
||||
return None
|
||||
Reference in New Issue
Block a user