feat!: support PKCE in the oauth2 client's auth/exchange flow #21215
+433
−168
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.
Breaking Change: Existing oauth apps might now use PKCE. If an unknown type was being used, and it does not support PKCE, it will break.
To fix, set the PKCE methods on the external auth to
nonePKCE challenge used in primary coderd oauth2 flow.
Closes #21213
Implementation from: golang/oauth2@55cd552
What this does
This adds PKCE support when Coder is the OAuth client to an external IdP.
OIDC
PKCE support is automatically detected from the
well-knownconfiguration endpoint. If it is supported, Coder will use it.coder/cli/server.go
Lines 189 to 195 in 53fc864
OAuth (github login & external auth).
Known Oauth types have defaults set based on manual testing. We need to manually test to expand coverage.
We assume PKCE is supported by all unknown oauth IdP's. This can fixed in the configuration
Example to disable:
Manual tests
Tested to work on:
{"message":"Failed exchanging Oauth code.","detail":"oauth2: \"bad_verification_code\" \"The code passed is incorrect or expired.\" \"https://docs.github.com/apps/managing-oauth-apps/troubleshooting-oauth-app-access-token-request-errors/#bad-verification-code\""}{"message":"Failed exchanging Oauth code.","detail":"oauth2: \"invalid_grant\" \"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.\""}{"message":"Failed exchanging Oauth code.","detail":"oauth2: \"unauthorized_client\" \"failed PKCE code challenge\""}{"message":"Failed exchanging Oauth code.","detail":"oauth2: \"invalid_grant\" \"Invalid authorization code\""}