Skip to content

feat(auth): OAuth 2.0 login for Cloud and Data Center #136

@avivsinai

Description

@avivsinai

Context

bkt auth login currently uses API tokens (Cloud) and PATs (DC) with copy-paste. Both Bitbucket Cloud and Data Center support OAuth 2.0 for API access, which would enable a browser-based login flow similar to gh auth login --web.

This came up during review of #133 and triage of #121 — the auth UX has room to improve.

What Bitbucket supports

Cloud DC
Auth Code Grant (3LO) Yes Yes
PKCE No Yes
Device Flow (RFC 8628) No No
Localhost redirect (RFC 8252) Yes Likely (admin-controlled)

Sources:

What gh does

gh auth login --web uses OAuth device flow (RFC 8628), falling back to auth code + localhost server. Bitbucket doesn't support device flow on either platform, so bkt would use the auth-code + localhost-server pattern.

Rough implementation sketch

Cloud:

  1. Register an OAuth consumer in a bkt-owned workspace (scopes: repository, pullrequest, account, etc.)
  2. bkt auth login --web starts a temporary localhost HTTP server, opens browser to Bitbucket's authorize URL
  3. User grants access, Bitbucket redirects to localhost with auth code
  4. Exchange code for access_token + refresh_token (2h TTL, auto-refresh)
  5. Store tokens in config, auto-refresh on expiry

Caveat: Cloud lacks PKCE, so the client_secret ships with the binary. Same trade-off gh makes.

DC:
Same flow but with PKCE (no embedded secret needed). Endpoints at /rest/oauth2/latest/.... Requires admin to set up an Application Link.

Trade-offs vs current auth

  • Better UX: one-click browser flow vs copy-paste tokens
  • Better security: short-lived tokens (2h) with auto-refresh vs long-lived PATs
  • More setup: OAuth consumer registration (Cloud), Application Links (DC)
  • Embedded secret: Cloud requires client_secret in binary (no PKCE)

Scope

This would add a --web / --oauth flow alongside the existing token-based login, not replace it. Token-based auth remains the default for headless/CI use cases (especially with BKT_TOKEN).

Not blocking anything — just capturing the research while it's fresh.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions