Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/OAuth2/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ abstract class AbstractProvider extends AbstractBaseProvider

protected bool $pkce = false;

protected int $pkceCodeVerifierLength = 96;

@ADmad ADmad Aug 27, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to pkceCodeVerifierByteLength to be more clear about what length it indicates?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that will make it more understandable. I also renamed it in the generatePKCECodeVerifier method.


/**
* @return string
*/
Expand All @@ -50,7 +52,7 @@ public function getAuthUrlParameters(): array
$parameters['response_type'] = 'code';

if ($this->pkce) {
$codeVerifier = $this->generatePKCECodeVerifier();
$codeVerifier = $this->generatePKCECodeVerifier($this->pkceCodeVerifierLength);
$this->session->set('code_verifier', $codeVerifier);

$parameters['code_challenge'] = $this->generatePKCECodeChallenge($codeVerifier);
Expand All @@ -60,10 +62,12 @@ public function getAuthUrlParameters(): array
return $parameters;
}

private function generatePKCECodeVerifier(int $length = 128)
private function generatePKCECodeVerifier(int $length = 96): string
{
if ($length < 43 || $length > 128) {
throw new \Exception("Length must be between 43 and 128");
if ($length < 32 || $length > 96) {
throw new \Exception(
"Final length must be between 43 and 128, so the number of random bytes must be between 32 and 96"
);
}

$randomBytes = random_bytes($length);
Expand Down