feat: support PKCE code_verifier in exchange_auth_code_for_tokens - #791
Open
gagalago wants to merge 1 commit into
Open
feat: support PKCE code_verifier in exchange_auth_code_for_tokens#791gagalago wants to merge 1 commit into
gagalago wants to merge 1 commit into
Conversation
5 tasks
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.
Changes
Adds an optional
code_verifierkeyword toAuth0::Api::AuthenticationEndpoints#exchange_auth_code_for_tokens, so the Authorization Code Flow with PKCE can be completed through the SDK.The parameter is sent only when provided:
No endpoint is added, removed or changed.
POST /oauth/tokenis already the target; this only allows one more documented body parameter to reach it. The keyword is appended last and defaults tonil, so every existing call site behaves exactly as before — whencode_verifieris omitted the request body is byte-for-byte what it is today.Usage, completing the flow that
authorization_urlcan already start viaadditional_parameters:References
code_verifierto be passed toexchange_auth_code_for_tokensendpoint #305 — "Allowcode_verifierto be passed toexchange_auth_code_for_tokensendpoint"In #305 a maintainer wrote that "
code_verifierspecifically should be a first-class parameter on that method, and should be optional", which is the shape implemented here. That thread also documented a workaround that reachesrequest_with_retrydirectly; it still works, but it depends on a method outside the documented public API.code_verifierdoes not currently appear anywhere in the repository, so as of v6.1.0 there is no supported way to perform a PKCE exchange. For reference,node-auth0exposes this asauthorizationCodeGrantWithPKCE, which requirescodeandcode_verifier.Testing
Two cases added to
test/unit/authentication_endpoints_test.rb, next to the existingexchange_auth_code_for_tokenstests and using the same WebMock body-matching style:test_exchange_auth_code_for_tokens_with_code_verifier— assertscode_verifieris present in the request body when passedtest_exchange_auth_code_for_tokens_omits_code_verifier_when_not_provided— asserts the key is absent from the body when it is not, which is what protects existing callersTo run them:
I checked that the first test actually fails if the one-line implementation is removed, so it is not a test that passes regardless.
Full suite on Ruby 3.3.9, before and after:
554 runs, 4582 assertions, 0 failures, 0 errors.Unrelated heads-up while testing on Ruby 4.0.6: the full suite reports one error there,
NoMethodError: undefined method 'parse' for class CGI, fromCGI.parseattest/unit/authentication_endpoints_test.rb:480on master.CGI.parsewas removed in Ruby 4.0. It reproduces on a clean checkout of master without this branch, and nothing in this change touchesCGI— flagging it only becauserequired_ruby_versionis>= 3.3.0with no upper bound, so Ruby 4 users will hit it. Happy to open a separate issue or pull request for that if useful.One note on style:
lib/auth0/api/authentication_endpoints.rbuses single-quoted strings throughout and is listed underAllCops.Excludein.rubocop.yml("Files ported verbatim from the legacy ruby-auth0 SDK... Excluded to preserve exact compatibility with the original source"), so I followed the surrounding convention rather than thedouble_quotesstyle enforced elsewhere.bundle exec rubocopreports the same 134 offences with and without this branch — it introduces none.The two new tests pass on both Ruby 3.3.9 and Ruby 4.0.6 (
2 runs, 4 assertions, 0 failures).Checklist