How is OAuth2PKCEClient supposed to work?
nclavaud opened this issue · 2 comments
Hi there,
I have been trying to implement PKCE with an unsupported provider (Zitadel) and had an issue with the authorization code exchange: the code challenge was always invalid (message invalid_grant
, description invalid code challenge
).
The OAuth2PKCEClient
does generate a code challenge, but it is later overriden by league/oauth2-client AbstractProvider
generating another one. As a result, the code challenge sent for authorization code exchange is not the same as before, hence the error.
With which provider is this OAuth2PKCEClient
client class supposed to work?
After a little further sought, I went to the conclusion that OAuth2PKCEClient
should not be responsible for generating the PKCE code challenge. I will open a pull request with an alternative that works for my use-case.
After more testing, things got clearer and here is the summary of what I have learned.
The league/oauth2-client package added support for PKCE in its latest version (2.7). It can be enabled by setting the pkceMethod
option on the provider.
The current implementation of this bundle (v2.15.0) works well with the latest league/oauth2-client package (2.7.0) as long as the pkceMethod
option is not defined on the provider.
However, if defined, the pkceMethod
option set on the provider will conflict with the OAuth2PKCEClient
class: both the client and the provider will generate a random code challenge (and they won't match, and no access token can be retrieved).
Two options:
- do not set the
pkceMethod
on the provider, it just works (the client class will be responsible of generating the code challenge) - consider a pull request like #407 to leverage the fact that league/oauth2-bundle now supports PKCE natively