mcp: don't run API keys through JWT validation

_resolve_token tried the JWT path before checking for the gns3_ prefix,
so every API-key connection logged a spurious "JWT rejected" ERROR from
get_token_data. Check the prefix first, and downgrade the JWT-rejected
log to WARNING — a rejected token is a client problem, not a server one.
This commit is contained in:
YueGuobin committed 2026-08-21 21:41:47 +08:00
1 parent 200ccf0dfe
commit c3145a9f65
2 files changed
+12 -10

No files matched your search

+10 -8
View File
@@ -213,14 +213,16 @@ async def _resolve_token(token: str) -> str | None:
Returns None if the token is invalid.
"""
# Try JWT first
try:
token_data = auth_service.get_token_data(token)
_jwt_username_var.set(token_data.username)
_jwt_token_version_var.set(token_data.token_version)
return token
except Exception:
pass
# API keys (gns3_...) are never valid JWTs — skip the JWT attempt for them
# so it doesn't log a spurious "JWT rejected" line on every API-key connection.
if not token.startswith("gns3_"):
try:
token_data = auth_service.get_token_data(token)
_jwt_username_var.set(token_data.username)
_jwt_token_version_var.set(token_data.token_version)
return token
except Exception:
pass
# Try API key — format: gns3_<api_key_id>_<random_secret> → O(1) lookup
if token.startswith("gns3_") and _app is not None: