Files
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

22 lines
698 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""SSO Cookie 本地验签 —— 与 SSO 中心共享 SECRET_KEY(Flask 版)"""
from jose import jwt, JWTError
# 必须与 SSO 中心 sso_config.py 完全一致
SECRET_KEY = "your-secret-key-change-in-production"
ALGORITHM = "HS256"
def get_user_from_sso_cookie(request):
"""从请求 Cookie 中读取 access_token,本地验签后返回用户信息"""
token = request.cookies.get("access_token")
if not token:
return None
try:
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
username = payload.get("sub")
if not username:
return None
return {"username": username}
except JWTError:
return None