Repository navigation
feat: add PKCE support to OAuth2 authorization code flow - #266
Merged
Merged
Conversation
- Add dependency on golang.org/x/oauth2 for PKCE (Proof Key for Code Exchange) support - Include code challenge and code challenge method fields in the AuthorizationCode struct - Implement PKCE code challenge validation in the authorization code grant flow - Replace custom S256 hashing with oauth2 library's S256ChallengeFromVerifier function - Add comprehensive tests for PKCE flows, including correct/incorrect verifier, missing verifier, plain method, and non-PKCE backward compatibility Signed-off-by: appleboy <[email protected]>
Contributor
Reviewer's GuideThis PR adds full PKCE support to the OAuth2 authorization code flow by extending the data model with code challenge fields, implementing verifier validation using the golang.org/x/oauth2 helper, and ensuring coverage with comprehensive tests. Sequence diagram for PKCE validation in OAuth2 authorization code grant flowsequenceDiagram
participant Client
participant "OAuth2 Server"
participant "Storage"
Client->>"OAuth2 Server": POST /token (code, code_verifier)
"OAuth2 Server"->>"Storage": Retrieve AuthorizationCode
"OAuth2 Server"->>"OAuth2 Server": computeCodeChallenge(code_verifier, code_challenge_method)
"OAuth2 Server"->>"OAuth2 Server": Compare computedChallenge with stored code_challenge
alt Challenge matches
"OAuth2 Server"->>Client: Issue access token
else Challenge does not match
"OAuth2 Server"->>Client: Return error (invalid_grant)
end
Class diagram for updated AuthorizationCode struct with PKCE fieldsclassDiagram
class AuthorizationCode {
string Code
string ClientID
string RedirectURI
string[] Scope
string CodeChallenge
string CodeChallengeMethod
int64 ExpiresAt
int64 CreatedAt
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Enforce the PKCE code_verifier length (43–128 characters) before computing the challenge to fully adhere to RFC7636 requirements.
- Default the code_challenge_method to “plain” when the parameter is omitted in the authorization request to conform with RFC7636 spec.
- Extract the repeated PKCE test setup into helper functions to reduce duplication and improve readability of TestPKCE_CodeVerifier.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Enforce the PKCE code_verifier length (43–128 characters) before computing the challenge to fully adhere to RFC7636 requirements.
- Default the code_challenge_method to “plain” when the parameter is omitted in the authorization request to conform with RFC7636 spec.
- Extract the repeated PKCE test setup into helper functions to reduce duplication and improve readability of TestPKCE_CodeVerifier.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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 by Sourcery
Enable PKCE in the OAuth2 authorization code grant by extending the AuthorizationCode model, implementing challenge verification using the oauth2 library, and covering the new behavior with thorough tests
New Features:
Enhancements:
Tests: