Skip to content

fix(auth): anthropic OAuth login falls back to current token endpoint - #48704

Closed
clower80 wants to merge 1 commit into
NousResearch:mainfrom
clower80:fix/anthropic-oauth-login-stale-token-endpoint
Closed

fix(auth): anthropic OAuth login falls back to current token endpoint#48704
clower80 wants to merge 1 commit into
NousResearch:mainfrom
clower80:fix/anthropic-oauth-login-stale-token-endpoint

Conversation

@clower80

Copy link
Copy Markdown

Summary

hermes auth add anthropic --type oauth fails at the code→token exchange with:

Token exchange failed: HTTP Error 404: Not Found
Anthropic OAuth login did not return credentials.

Root cause: run_hermes_oauth_login_pure() in agent/anthropic_adapter.py exchanges the authorization code against only the legacy https://console.anthropic.com/v1/oauth/token endpoint, which now returns HTTP 404.

The token refresh path (refresh_anthropic_oauth_pure, the token_endpoints list around L997) already tries https://platform.claude.com/v1/oauth/token first and falls back to the console URL — but the login path was never updated to match. So a fresh subscription login is broken even though refresh works.

Fix

Mirror the same ordered-fallback list in the login exchange: try platform.claude.com first, fall back to console.anthropic.com, and only surface the error if every endpoint fails. Minimal, scoped to the one broken function.

Test

Adds test_token_exchange_falls_back_to_legacy_endpoint to tests/agent/test_anthropic_oauth_pkce.py, asserting the current endpoint is tried first and the legacy endpoint is used as a fallback when the first fails.

$ python -m pytest tests/agent/test_anthropic_oauth_pkce.py -o 'addopts=' -q
...                                                                      [100%]
3 passed in 0.74s

Notes

  • Reproduced on a real macOS install (Hermes v0.16.0) — the login 404'd, the patch made it complete and store the OAuth credential successfully.
  • No behavior change for users already on the working endpoint; this only adds a fallback when the first endpoint errors.

run_hermes_oauth_login_pure() exchanged the authorization code only against
the legacy https://console.anthropic.com/v1/oauth/token URL, which now
returns HTTP 404 — breaking `hermes auth add anthropic --type oauth` with
"Token exchange failed: HTTP Error 404: Not Found".

The token *refresh* path already tries https://platform.claude.com first and
falls back to the console URL; the *login* path was never updated. Mirror the
same ordered-fallback list in the login exchange so a 404 (or any failure) on
the first endpoint advances to the next.

Adds a regression test asserting platform.claude.com is tried first and
console.anthropic.com is used as a fallback.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/auth Authentication, OAuth, credential pools provider/anthropic Anthropic native Messages API P1 High — major feature broken, no workaround labels Jun 18, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Adds fallback for Anthropic OAuth login when token endpoint fails. 2-file fix with graceful degradation.


Reviewed by Hermes Agent

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users labels Jun 21, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Closing as a duplicate. This was fixed via #51723 (salvage of #48706 by @yusekiotacode, which fixed both the CLI login and dashboard OAuth paths). Thanks for the report and the fix — credited in the cluster.

#51723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P1 High — major feature broken, no workaround provider/anthropic Anthropic native Messages API sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants