This commit is contained in:
2025-12-01 17:21:38 +08:00
parent 32fee2b8ab
commit fab8c13cb3
7511 changed files with 996300 additions and 0 deletions

24
dify/api/libs/passport.py Normal file
View File

@@ -0,0 +1,24 @@
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:
raise Unauthorized("Token has expired.")
except jwt.InvalidSignatureError:
raise Unauthorized("Invalid token signature.")
except jwt.DecodeError:
raise Unauthorized("Invalid token.")
except jwt.PyJWTError: # Catch-all for other JWT errors
raise Unauthorized("Invalid token.")