Skip to content

feat(oauth): only the current client's user credentials count, and a failed connect stores nothing (#275) - #875

Merged
aixle-com[bot] merged 6 commits into
developfrom
feature/oauth-current-client-only
Nov 25, 2026
Merged

aixle-com[bot] merged 6 commits into
developfrom
feature/oauth-current-client-only

Conversation

@NOX73

@NOX73 NOX73 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

What changed

Two gaps in how a person's own account (GitHub, GitLab, Bitbucket) connects through the OAuth engine (#275).

1. Only the current client's credentials count.

  • OauthCredential.on_other_client / #on_other_client? own the rule. "Current" is the OauthClient with the issuer and client id the deployment is configured with now (Oauth::Providers.current_client_ref, settings only).
  • *_connections_of, and so latest_*/live_* (profile page, *_user_token tools, and the pull_request_* write tools acting as a user, which use the same contexts), skip other clients' credentials. refresh_due and Oauth::TokenService.fresh skip them too, so they lapse.
  • GitLab's on_other_gitlab_instance is folded into this: a changed GITLAB_ENDPOINT changes the issuer.
  • Disconnect deletes all of the person's credentials for the provider. Only a current-client credential is revoked at the provider.

2. A failed connect stores nothing.

  • after_connect / record_identity! are replaced by a fetch_identity: registry hook that runs with the new access token before anything is stored. upsert_from_token!(identity:) then saves the token and identity in one save.
  • A failed fetch: no new credential, a previous one is untouched (token and identity), the person sees "Failed to complete connection" as before. MCP flows have no hook and are unchanged.

Docs: a note in the three user-identity designs, oauth-implementation.md, and a new docs/operations/rotating-oauth-clients.md (rotating a client means people reconnect).

Out of scope, unchanged: Sentry, Railway and MCP credentials (the rule is limited to CLIENT_BOUND_PROVIDERS). No revocation of old-client grants at the provider. No migration.

Tests

  • Per provider: old-client credential not listed, not vended, not in refresh_due, not refreshed by fresh, deleted on disconnect; first connect with a failing identity fetch stores nothing; reconnect with a failing fetch keeps the previous credential and identity; successful connect stores both.
  • pull_request_acting_as: a write tool acting as a user treats an old-client credential as not connected, for each host.
  • Factories: a person's connection is made with the configured client (github_current, and the gitlab/bitbucket traits). Some tests now stub the client id they use.

How to test: bin/rails test test/models test/services/oauth test/services/internal_tools test/controllers/web/oauth_controller_test.rb test/services/user_connections_test.rb test/integration/web/profile_connections_test.rb. On staging: connect, disconnect and reconnect GitHub and check a token is handed out.

@aixle-com aixle-com Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of #275: no [Must] findings. Two recommendations and one note inline.

Comment thread app/services/oauth/token_service.rb Resolved
Comment thread app/models/oauth_credential.rb Resolved
Comment thread app/controllers/web/oauth_controller.rb Resolved

@aixle-com aixle-com Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed head 9d8c509. Both earlier [Recommendation] threads are addressed: Oauth::TokenService.fresh now checks on_other_client? before the expired? return (with a test for an unexpired other-client credential), and the controller calls Oauth::Providers.fetch_identity directly. No new findings.

@aixle-com
aixle-com Bot merged commit c074b6c into develop Nov 25, 2026
18 checks passed
artempartos added a commit that referenced this pull request Nov 25, 2026
* origin/develop:
  docs(runners): tech design for a short Add machine instruction (#878)
  feat(oauth): only the current client's user credentials count, and a failed connect stores nothing (#275) (#875)

# Conflicts:
#	CHANGELOG.md
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.

1 participant