feat: proactive Bearer token refresh with unified fallback

- Parse JWT 'exp' claim to track token expiry (token_expires_at)
- Proactively refresh Bearer tokens 1 hour before expiry in
  ensure_authenticated()
- Refresh response without expires_in now falls back to JWT exp for
  expiry derivation
- Support custom refresh_path via bearer auth_config whitelist
- Unify 401 fallback: all bearer types (including Sub2API) now go
  through _refresh_bearer_token() instead of separate old path
- Remove dead _is_sub2api_bearer() / _refresh_sub2api_bearer_token()
- Add 2 new tests: refresh_path override + JWT exp backfill

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
SmartUp Developer
2026-07-06 10:31:29 +08:00
co-authored by Claude Opus 4.8
parent 5a20e792fe
commit 2262b6a564
3 changed files with 331 additions and 15 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ SECRET_KEYS = {"password", "token", "refresh_token", "access_token", "auth_token
AUTH_CONFIG_ALLOWED_KEYS = {
"none": set(),
"bearer": {"token", "refresh_token", "expires_in", "token_expires_at"},
"bearer": {"token", "refresh_token", "expires_in", "token_expires_at", "refresh_path"},
"new_api_token": {"token", "user_id", "new_api_user", "provider"},
"nox_token": {"token", "user_id", "new_api_user", "provider"},
"api_key": {"key", "header"},