fix(auth): token 登录将令牌放入 Authorization: Bearer 头
token 换登录调上游 getTokenInfo 时参数传错:原来发静态头 Authorization: Bearer admin + 令牌放 access_token cookie。上游实际 从 Authorization: Bearer <token> 头读取令牌。 - 鉴权头改为 "Bearer "+前端传入 token,删除 access_token cookie - service_authorization 配置项弃用(保留兼容,不再参与请求) - 新增回归测试 test_token_login_upstream_call.py - 同步更新 AUTH_LOGIN.md / CLAUDE.md / config.yaml 注释 / login_config 文档 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c5352f2ee7
commit
5c2379577b
7 files changed
+112
-20
No files matched your search
@@ -255,11 +255,11 @@ async def _get_or_create_user_by_username(username: str):
|
||||
async def _fetch_username_from_token(token: str) -> str:
|
||||
"""Resolve an upstream access token to a username via the configured endpoint.
|
||||
|
||||
Calls ``auth_login.token_login.token_info_url`` exactly like the documented
|
||||
curl: a POST carrying ``Authorization: <service_authorization>`` plus the
|
||||
token as the ``access_token`` cookie. Expects ``{"state": "200", "data":
|
||||
{"username": ...}}`` and returns ``data.username``. Any upstream failure,
|
||||
non-200 ``state``, or missing username raises HTTP 401.
|
||||
Calls ``auth_login.token_login.token_info_url`` with the caller-supplied
|
||||
token placed directly in the ``Authorization: Bearer <token>`` header — the
|
||||
upstream reads the bearer token from there, not from a cookie. Expects
|
||||
``{"state": "200", "data": {"username": ...}}`` and returns ``data.username``.
|
||||
Any upstream failure, non-200 ``state``, or missing username raises HTTP 401.
|
||||
"""
|
||||
config = get_app_config().auth_login.token_login
|
||||
if not config.token_info_url:
|
||||
@@ -276,10 +276,9 @@ async def _fetch_username_from_token(token: str) -> str:
|
||||
upstream = await client.post(
|
||||
config.token_info_url,
|
||||
headers={
|
||||
"Authorization": config.service_authorization,
|
||||
"Authorization": f"Bearer {token}",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
cookies={"access_token": token},
|
||||
)
|
||||
except httpx.HTTPError as exc:
|
||||
# Surface the concrete failure (SSL handshake, DNS, timeout, ...) in logs
|
||||
|
||||
Reference in new issue
Block a user