Skip to content

Replace device-code auth with OAuth2 PKCE flow (PCC-675)#143

Merged
mattshep merged 6 commits intomainfrom
pcc-675
Mar 30, 2026
Merged

Replace device-code auth with OAuth2 PKCE flow (PCC-675)#143
mattshep merged 6 commits intomainfrom
pcc-675

Conversation

@mattshep
Copy link
Copy Markdown
Contributor

This change depends on code changes in the API which are not yet live, it should not be merged until @mattshep confirms that those changes are deployed to and available in the production environment. Those API changes are currently live in the staging environment, and can be tested by installing the CLI from this branch.

PIPECAT_API_HOST="https://staging.qa.pipecat.cloud" pcc auth login

Replace the custom device-code login flow with industry-standard OAuth2 Authorization Code + PKCE. This addresses three pentest findings:

  • PCC-675: Tokens now auto-refresh (1-day access token + long-lived refresh token with rotation), eliminating "please run pcc auth login"
  • PCC-677: PKCE + localhost callback eliminates the phishing/session hijacking vector of the old polling-based device-code flow
  • PCC-678: Logout now revokes tokens server-side via /auth/logout

Changes:

  • auth.py: Replace _AuthFlow/FlowManager device-code with PKCE flow (code_verifier, localhost callback server, Clerk token exchange)
  • auth.py: Logout calls /auth/logout to revoke tokens server-side
  • auth.py: Whoami shows email instead of internal Clerk user ID
  • api.py: Auto-refresh expired OAuth tokens before API calls
  • config.py: Store refresh_token and token_expires_at in TOML config, update in-memory config after writes

@mattshep mattshep self-assigned this Mar 24, 2026
@linear
Copy link
Copy Markdown

linear Bot commented Mar 24, 2026

Comment thread src/pipecatcloud/cli/commands/auth.py Outdated
Comment thread src/pipecatcloud/cli/commands/auth.py Outdated
Comment thread src/pipecatcloud/api.py
Comment thread src/pipecatcloud/cli/commands/auth.py
@mattshep
Copy link
Copy Markdown
Contributor Author

This change is safe to release now, required endpoints are live in prod.

Replace the custom device-code login flow with industry-standard
OAuth2 Authorization Code + PKCE. This addresses three pentest
findings:

- PCC-675: Tokens now auto-refresh (1-day access token + long-lived
  refresh token with rotation), eliminating "please run pcc auth login"
- PCC-677: PKCE + localhost callback eliminates the phishing/session
  hijacking vector of the old polling-based device-code flow
- PCC-678: Logout now revokes tokens server-side via /auth/logout

Changes:
- auth.py: Replace _AuthFlow/FlowManager device-code with PKCE flow
  (code_verifier, localhost callback server, Clerk token exchange)
- auth.py: Logout calls /auth/logout to revoke tokens server-side
- auth.py: Whoami shows email instead of internal Clerk user ID
- api.py: Auto-refresh expired OAuth tokens before API calls
- config.py: Store refresh_token and token_expires_at in TOML config,
  update in-memory config after writes
Address PR review feedback:
- Replace hardcoded Clerk domain, client ID, and scopes with runtime
  discovery via GET /auth/config + OIDC discovery (RFC 8414). The CLI
  only needs to know the API URL — everything else is discovered.
- Replace fixed port 8080 with a range (8400-8404) tried in order.
  Uses a less-common range to avoid conflicting with dev servers.
  Each port is registered as a redirect URI in the Clerk OAuth app.
- `pcc auth use-pat <token>` command to validate and store a PAT
- API client detects pcc_pat_ prefix and skips OAuth token refresh
- `pcc auth whoami` shows auth method (PAT vs OAuth)
- PIPECAT_TOKEN env var with a PAT just works (no login needed)
- Preserves active org when switching to PAT auth
Dark background (#0a0a0a), Pipecat cat logo, green/red status icons,
system font stack. Replaces the plain HTML "Authentication successful!"
page with a branded experience.
PR #142 replaced `import warnings` with `import sys` but this branch
still had a `warnings.warn()` call for config problems. Replace it with
`raise ConfigError(...)` to match the intent of that PR.
@mattshep mattshep merged commit dbc2ca3 into main Mar 30, 2026
2 checks passed
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