整合 dsAiTeachingModel 接口
This commit is contained in:
21
dsLightRag/Util/JwtUtil.py
Normal file
21
dsLightRag/Util/JwtUtil.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# jwt_utils.py
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from jose import JWTError, jwt
|
||||
from Config.Config import *
|
||||
|
||||
|
||||
def create_access_token(data: dict):
|
||||
to_encode = data.copy()
|
||||
expire = datetime.utcnow() + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
|
||||
to_encode.update({"exp": expire})
|
||||
encoded_jwt = jwt.encode(to_encode, JWT_SECRET_KEY, algorithm=ALGORITHM)
|
||||
return encoded_jwt
|
||||
|
||||
def verify_token(token: str):
|
||||
try:
|
||||
payload = jwt.decode(token, JWT_SECRET_KEY, algorithms=[ALGORITHM])
|
||||
return payload
|
||||
except JWTError:
|
||||
return None
|
||||
|
Reference in New Issue
Block a user