This commit is contained in:
Ubuntu
2026-07-03 16:58:28 +08:00
commit 32b43f85bd
6240 changed files with 1987678 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
"""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