Repository navigation
feat(auth/oidc): enable PKCE by default and add WithAuthCodeOptions - #25
Merged
Merged
Conversation
Redirect now generates a PKCE code verifier, stores it in the session and sends the S256 code challenge. Callback requires the verifier and passes it to the token exchange. A session without the verifier is rejected with 400 instead of falling back to the exchange without PKCE. WithoutPKCE disables it for providers that reject PKCE, or for apps that build the authorization URL or exchange the code themselves. WithAuthCodeOptions adds parameters such as prompt and hd to the authorization request. They are applied before state, nonce and the PKCE parameters so that they cannot override them. The test helpers for the login flow are moved to flow_test.go, and the fake provider now verifies the code verifier like real providers.
mackee
force-pushed
the
feat/oidc-pkce-auth-code-options
branch
from
October 8, 2026 05:54
e7726cf to
e9fbefc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
auth/oidcの認可リクエストに、PKCE と任意のパラメータ(prompt・hdなど)を付けられるようにしました。これまではRedirectがAuthCodeURL(state, oidc.Nonce(nonce))に固定されていて、どちらも付けられませんでした。Changes
PKCE をデフォルトで有効化(挙動の変更)
Redirectで code verifier を生成してセッションに保存し、認可 URL に S256 のcode_challengeを付けます。Callbackはセッションから verifier を取り出して削除し、トークン交換にcode_verifierとして渡します。WithoutPKCE()で無効にできます。PKCE に対応していない IdP でも、RFC 6749 §3.1 により知らないパラメータは無視されるため、通常は影響ありません。
WithAuthCodeOptions(opts ...oauth2.AuthCodeOption)の追加Redirect が設定する
state/nonce/ PKCE のパラメータより先に適用するので、これらを上書きすることはできません。既存の利用者への影響
PKCE のデフォルト有効化で失敗するのは、次のケースに限られます。
Callbackだけ使っているWithoutPKCE()Redirectだけ使い、トークン交換は自前code_verifier不足で拒否WithoutPKCE()WithoutPKCE()RedirectとCallbackを別々のHandlersで組み立てていても、セッションを共有していて PKCE の設定が揃っていれば問題ありません。README に PKCE とWithAuthCodeOptionsの節を追加しました。Test
flow_test.goに切り出しました。偽 IdP は、実際の IdP と同様にcode_verifierを検証します(challenge が無いのに verifier が来た場合も拒否)。pkce_test.goで次の挙動を確認しています。WithoutPKCEではcode_challengeを送らないWithAuthCodeOptionsのパラメータが付き、nonce/code_challengeは上書きされないgo test ./...が通ることを確認しました。🤖 Generated with Claude Code