Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add PKCE support for OIDC authentication#21204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
blinkagent wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromfeat/oidc-pkce-support

Conversation

@blinkagent
Copy link
Contributor

Summary

This adds support for PKCE (Proof Key for Code Exchange) when Coder acts as an OIDCclient. PKCE is an OAuth 2.0 extension (RFC 7636) that prevents authorization code interception attacks, making authentication more secure especially for public clients.

Problem

Some identity providers require or strongly recommend PKCE for OAuth2/OIDC flows. Without PKCE support, Coder cannot authenticate with these IdPs.

Changes

  • AddCODER_OIDC_PKCE environment variable (default: false)
  • Add--oidc-pkce flag to enable PKCE for OIDC authentication
  • AddOAuth2PKCECookie constant for storing the PKCE verifier
  • ModifyExtractOAuth2 middleware to:
    • Generate PKCE code verifier when initiating auth flow
    • Store verifier in HttpOnly cookie
    • Includecode_challenge (S256) in authorization request
    • Passcode_verifier during token exchange
  • Update allExtractOAuth2 call sites withpkceEnabled parameter

Configuration

To enable PKCE for OIDC authentication:

export CODER_OIDC_PKCE=true

Or via CLI:

coder server --oidc-pkce

Implementation Details

  • Uses S256 challenge method (SHA256 hash of verifier) as recommended by RFC 7636
  • Verifier stored in HttpOnly cookie for CSRF protection
  • Leveragesgolang.org/x/oauth2's built-in PKCE support (oauth2.GenerateVerifier(),oauth2.S256ChallengeOption(),oauth2.VerifierOption())
  • Backward compatible - PKCE is disabled by default
  • Only applies to OIDC authentication; GitHub and external auth remain unchanged

Testing

  • Updated existingTestOAuth2 tests to passpkceEnabled parameter
  • All OAuth2 middleware tests pass

TODO (for follow-up)

  • Add PKCE-specific tests
  • Test with various IdPs (Okta, Azure AD, Keycloak, Google)
  • Documentation updates

Related

  • RFC 7636: Proof Key for Code Exchange
  • OAuth 2.1 makes PKCE required by default

This adds support for PKCE (Proof Key for Code Exchange) when Coder acts as anOIDC client. PKCE is an OAuth 2.0 extension that prevents authorization codeinterception attacks, making authentication more secure especially for publicclients.## Changes- Add `CODER_OIDC_PKCE` environment variable (default: false)- Add `--oidc-pkce` flag to enable PKCE for OIDC authentication- Modify ExtractOAuth2 middleware to:  - Generate PKCE code verifier when initiating auth flow  - Store verifier in HttpOnly cookie  - Include code_challenge (S256) in authorization request  - Pass code_verifier during token exchange- Update all ExtractOAuth2 call sites with pkceEnabled parameter## ConfigurationTo enable PKCE for OIDC authentication:```bashexport CODER_OIDC_PKCE=true```Or via CLI:```bashcoder server --oidc-pkce```## Security- Uses S256 challenge method (SHA256 hash of verifier)- Verifier stored in HttpOnly cookie for CSRF protection- Compatible with all major IdPs that support PKCE (Okta, Azure AD, Keycloak, etc.)Related: RFC 7636 - Proof Key for Code Exchange
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant


[8]ページ先頭

©2009-2025 Movatter.jp