Skip to content

Support custom OAuth redirect_uri#186

Merged
jeremy merged 3 commits intomainfrom
oauth-redirect-uri
Mar 4, 2026
Merged

Support custom OAuth redirect_uri#186
jeremy merged 3 commits intomainfrom
oauth-redirect-uri

Conversation

@jeremy
Copy link
Member

@jeremy jeremy commented Mar 3, 2026

Summary

  • Add BASECAMP_OAUTH_REDIRECT_URI env var and LoginOptions.RedirectURI field so users with custom OAuth client credentials can specify a matching redirect URI
  • Add resolveOAuthCallback() with full RFC 8252 loopback validation (http scheme, loopback host, explicit port, no userinfo/query/fragment)
  • Rename credential env vars to BASECAMP_OAUTH_CLIENT_ID/BASECAMP_OAUTH_CLIENT_SECRET with strict pairing
  • BC3 DCR clients registered with a custom redirect URI are session-only (not persisted to client.json)
  • Improve auth timeout error to include listener address

Closes #183

Test plan

  • make check passes (fmt, vet, lint, unit tests, e2e tests)
  • TestResolveOAuthCallback — 11 subtests covering default, env override, programmatic override, CallbackAddr compat, and all validation rejections
  • TestResolveClientCredentials — 4 subtests covering both-set, ID-only error, secret-only error, neither-set
  • TestBuildAuthURL_UsesResolvedRedirectURI — resolved URI propagates to authorization URL
  • TestExchangeCode_UsesResolvedRedirectURI — resolved URI propagates to token exchange
  • TestRegisterBC3Client_UsesResolvedRedirectURI — resolved URI sent in DCR request body
  • TestRegisterBC3Client_CustomRedirectNotPersisted — custom redirect skips client.json write
  • TestRegisterBC3Client_DefaultRedirectPersisted — default redirect persists as before
  • TestLoadClientCredentials_BC3_CustomRedirect_SkipsStoredClient — custom redirect bypasses stored client, forces fresh DCR

jeremy added 2 commits March 3, 2026 14:28
Users with their own OAuth client credentials registered on Launchpad
need the CLI's redirect_uri to match their app's registered callback.
The CLI previously hardcoded http://127.0.0.1:8976/callback with no
way to override it.

Add resolveOAuthCallback() with precedence chain:
  LoginOptions.RedirectURI > BASECAMP_OAUTH_REDIRECT_URI env var >
  CallbackAddr-derived > hardcoded default

Validate all redirect URIs (including default) against RFC 8252
loopback rules: http scheme, loopback host, explicit port, no
userinfo/query/fragment.

Rename credential env vars to BASECAMP_OAUTH_CLIENT_ID/SECRET with
strict pairing (both required when either is set).

BC3 DCR clients registered with a custom redirect URI are not
persisted to client.json, preventing stale credentials on subsequent
runs without the override.

Closes #183
Copilot AI review requested due to automatic review settings March 3, 2026 22:28
@github-actions github-actions bot added tests Tests (unit and e2e) auth OAuth authentication docs enhancement New feature or request labels Mar 3, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for user-specified OAuth redirect_uri (via env var and programmatic options) so custom OAuth clients can complete the auth flow, with strict loopback redirect validation aligned with RFC 8252 and updated credential env var handling.

Changes:

  • Add BASECAMP_OAUTH_REDIRECT_URI + LoginOptions.RedirectURI, and resolve/validate loopback redirect + listener address via resolveOAuthCallback().
  • Rename/standardize OAuth credential env vars to BASECAMP_OAUTH_CLIENT_ID / BASECAMP_OAUTH_CLIENT_SECRET with strict pairing via resolveClientCredentials().
  • Adjust BC3 DCR persistence behavior: custom redirect URI clients are session-only; improve auth timeout error to include listener address; add comprehensive tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
internal/auth/auth.go Implements redirect URI resolution/validation, updates auth URL + token exchange to use resolved redirect URI, and adjusts BC3 DCR persistence behavior.
internal/auth/auth_test.go Adds unit tests covering redirect resolution/validation, env credential pairing, redirect propagation, and BC3 persistence rules.
README.md Documents new env vars for custom OAuth credentials and redirect URI configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…est isolation

- Remove `customRedirect bool` parameter from `registerBC3Client`; derive
  it from `opts.RedirectURI != defaultRedirectURI` inside the function
- Add `XDG_CONFIG_HOME` override in `TestRegisterBC3Client_UsesResolvedRedirectURI`
  to prevent writing to the developer's real config dir
- Use full env var names in README sentence
@jeremy jeremy merged commit 8990b3d into main Mar 4, 2026
21 checks passed
@jeremy jeremy deleted the oauth-redirect-uri branch March 4, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth OAuth authentication docs enhancement New feature or request tests Tests (unit and e2e)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth redirect_uri not approved

2 participants