Skip to content

Clear the OAuth token and warn when its refresh fails#1184

Merged
ericmj merged 1 commit into
mainfrom
clear-oauth-token-on-refresh-failure
Jun 17, 2026
Merged

Clear the OAuth token and warn when its refresh fails#1184
ericmj merged 1 commit into
mainfrom
clear-oauth-token-on-refresh-failure

Conversation

@ericmj

@ericmj ericmj commented Jun 17, 2026

Copy link
Copy Markdown
Member

An expired global OAuth token whose refresh the server rejects was refreshed once per package during dependency resolution -- dozens of failed POSTs to /oauth/token, serialized by the token-refresh lock -- and the failure was swallowed, so resolution silently continued without credentials. This regressed the OnceCache memoization and warning dropped in cda8717.

Implement the new hex_cli_auth clear_oauth_tokens callback: drop the token from in-memory state (keeping the on-disk token so a transient failure can recover on the next run) and warn once that the session expired and to re-run mix hex.user auth. With the token gone, the rest of the run stops retrying the refresh.

Re-vendors hex_core.

An expired global OAuth token whose refresh the server rejects was refreshed once per package during dependency resolution -- dozens of failed POSTs to /oauth/token, serialized by the token-refresh lock -- and the failure was swallowed, so resolution silently continued without credentials. This regressed the OnceCache memoization and warning dropped in cda8717.

Implement the new hex_cli_auth clear_oauth_tokens callback: drop the token from in-memory state (keeping the on-disk token so a transient failure can recover on the next run) and warn once that the session expired and to re-run `mix hex.user auth`. With the token gone, the rest of the run stops retrying the refresh.

Re-vendors hex_core.
@ericmj ericmj requested a review from maennchen June 17, 2026 15:01
Comment thread lib/hex/auth.ex
@maennchen

Copy link
Copy Markdown
Member

Oh wait, you wanted this behaviour: test clear_oauth_tokens/0 callback keeps the on-disk token so a later run can retry the refresh (Hex.AuthTest)

So your code was correct.

@maennchen

Copy link
Copy Markdown
Member

But the question then is if it makes sense. 500 etc. should not call clear and 401 etc. will never work in the future.

@ericmj ericmj force-pushed the clear-oauth-token-on-refresh-failure branch from d4001d4 to 1468661 Compare June 17, 2026 15:42
@ericmj

ericmj commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

We want to retry on 500 and a 401 will trigger a new device auth, like mix hex.user auth so this is behavior we want I think

@maennchen maennchen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

True. The whole auth logic has so many paths 😅

@ericmj ericmj merged commit a0ab6bc into main Jun 17, 2026
42 checks passed
@ericmj ericmj deleted the clear-oauth-token-on-refresh-failure branch June 17, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants