Files
gsfdc/demo-dify/dify/api/libs/passport.py
T
wuzilongandCursor 6519682885 chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 13:59:25 +08:00

25 lines
911 B
Python

import jwt
from werkzeug.exceptions import Unauthorized
from configs import dify_config
class PassportService:
def __init__(self):
self.sk = dify_config.SECRET_KEY
def issue(self, payload):
return jwt.encode(payload, self.sk, algorithm="HS256")
def verify(self, token):
try:
return jwt.decode(token, self.sk, algorithms=["HS256"])
except jwt.ExpiredSignatureError as caught_error:
raise Unauthorized("Token has expired.") from caught_error
except jwt.InvalidSignatureError as caught_error:
raise Unauthorized("Invalid token signature.") from caught_error
except jwt.DecodeError as caught_error:
raise Unauthorized("Invalid token.") from caught_error
except jwt.PyJWTError as caught_error: # Catch-all for other JWT errors
raise Unauthorized("Invalid token.") from caught_error