Skip to content

feat(auth): add PKCE to OAuth 2.0 login flow#162

Merged
avivsinai merged 1 commit intoavivsinai:masterfrom
ekrako:issue-153-feat-auth-add-pkce-to-oauth-login-flow
Apr 15, 2026
Merged

feat(auth): add PKCE to OAuth 2.0 login flow#162
avivsinai merged 1 commit intoavivsinai:masterfrom
ekrako:issue-153-feat-auth-add-pkce-to-oauth-login-flow

Conversation

@ekrako
Copy link
Copy Markdown
Contributor

@ekrako ekrako commented Apr 13, 2026

Summary

Adds PKCE (RFC 7636, S256 method) to the OAuth 2.0 authorization code flow as defense-in-depth against authorization code interception. The client secret is preserved — Bitbucket Cloud still requires it at token exchange/refresh.

Closes #153

Changes

  • pkg/oauth/flow.go: Added generatePKCE() helper and pkceParams type; buildAuthorizeURL now includes code_challenge + code_challenge_method=S256; exchangeCode now includes code_verifier in POST body
  • pkg/oauth/flow_test.go: Added TestGeneratePKCE (verifier length, charset, S256 derivation, uniqueness); updated TestBuildAuthorizeURL and TestExchangeCode to assert PKCE params
  • pkg/oauth/cloud.go: Updated stale comment that incorrectly stated PKCE was unsupported

Testing

  • go test ./... — 1165 tests pass
  • TestGeneratePKCE verifies verifier charset/length and challenge derivation against known SHA-256 output
  • TestBuildAuthorizeURL asserts code_challenge and code_challenge_method=S256 in authorize URL
  • TestExchangeCode asserts code_verifier in token exchange POST body

Risks

None — stdlib only (crypto/sha256, encoding/base64), isolated to pkg/oauth, no public API changes

Layer PKCE (RFC 7636, S256) onto the existing authorization code flow as
defense-in-depth against code interception. Client secret is preserved —
Bitbucket Cloud still requires it at token exchange/refresh.

Closes avivsinai#153
@sentry
Copy link
Copy Markdown

sentry Bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 84.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/oauth/flow.go 84.00% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@avivsinai avivsinai added enhancement New feature or request go Pull requests that update go code labels Apr 15, 2026
Copy link
Copy Markdown
Owner

@avivsinai avivsinai left a comment

Choose a reason for hiding this comment

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

Blocking pending verification.

As of April 15, 2026, Bitbucket Cloud's official OAuth 2.0 docs still describe the authorization-code flow as:

  • authorize: https://bitbucket.org/site/oauth2/authorize?client_id={client_id}&response_type=code
  • token: POST https://bitbucket.org/site/oauth2/access_token using Basic auth with client_id:secret

Source: https://developer.atlassian.com/cloud/bitbucket/rest/intro/#oauth-2-0

The February 4, 2026 Bitbucket Cloud auth-change notice also enumerates the current OAuth 2.0 behavior changes and does not mention PKCE, code_challenge, or code_verifier:
https://developer.atlassian.com/cloud/bitbucket/changelog/#CHANGE-3052

Inference from those official sources: PKCE support is at best undocumented. I could not complete a live end-to-end check from this machine because there is no Bitbucket Cloud OAuth consumer configured here and no BKT_OAUTH_CLIENT_* credentials are present.

Please add a real Bitbucket Cloud validation that code_challenge + code_verifier are accepted before we merge this, or keep the current unsupported/unverified posture in code/docs until that evidence exists.

avivsinai added a commit that referenced this pull request Apr 15, 2026
Copy the PKCE OAuth files from PR #162 onto a short-lived branch and add a manual workflow that builds bkt with the repository OAuth client secrets embedded.\n\nThis keeps the verification path off the fork PR while producing a binary we can use for a real Bitbucket Cloud login test.

Refs GH-162\nCo-Authored-By: OpenAI Codex <noreply@openai.com>
avivsinai added a commit that referenced this pull request Apr 15, 2026
Scope the verification workflow to pushes on the temporary branch so GitHub runs it without requiring the workflow file to exist on master.\n\nThis keeps the footprint isolated to the scratch branch and preserves the manual trigger.

Refs GH-162\nCo-Authored-By: OpenAI Codex <noreply@openai.com>
avivsinai added a commit that referenced this pull request Apr 15, 2026
Use macos-latest for the temporary verification workflow so the uploaded bkt artifact is runnable on the local machine for the live Bitbucket Cloud login check.

Refs GH-162\nCo-Authored-By: OpenAI Codex <noreply@openai.com>
Copy link
Copy Markdown
Owner

@avivsinai avivsinai left a comment

Choose a reason for hiding this comment

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

Live verification passed on April 15, 2026 against bitbucket.org using a secrets-built artifact from this PR. That clears the PKCE blocker. Thanks, @ekrako.

@avivsinai avivsinai merged commit b025476 into avivsinai:master Apr 15, 2026
7 checks passed
avivsinai added a commit that referenced this pull request Apr 15, 2026
Add the missing Unreleased notes for the notable changes merged after v0.23.0 so the release can be cut through the supported release PR flow.

Refs GH-110
Refs GH-162
Refs GH-164
Co-Authored-By: OpenAI Codex <noreply@openai.com>
avivsinai added a commit that referenced this pull request Apr 15, 2026
Add the missing Unreleased notes for the notable changes merged after v0.23.0 so the next release can be cut through the supported release PR flow.

This covers the Data Center PR comments details view, PKCE in the Bitbucket Cloud OAuth login flow, and the release-pipeline attestation/gate tightening.

Refs GH-110
Refs GH-162
Refs GH-164
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(auth): add PKCE to OAuth 2.0 login flow

2 participants