File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ abstract class AbstractProvider extends AbstractBaseProvider
2727
2828 protected bool $ pkce = false ;
2929
30+ protected int $ pkceCodeVerifierByteLength = 96 ;
31+
3032 /**
3133 * @return string
3234 */
@@ -50,7 +52,7 @@ public function getAuthUrlParameters(): array
5052 $ parameters ['response_type ' ] = 'code ' ;
5153
5254 if ($ this ->pkce ) {
53- $ codeVerifier = $ this ->generatePKCECodeVerifier ();
55+ $ codeVerifier = $ this ->generatePKCECodeVerifier ($ this -> pkceCodeVerifierByteLength );
5456 $ this ->session ->set ('code_verifier ' , $ codeVerifier );
5557
5658 $ parameters ['code_challenge ' ] = $ this ->generatePKCECodeChallenge ($ codeVerifier );
@@ -60,13 +62,15 @@ public function getAuthUrlParameters(): array
6062 return $ parameters ;
6163 }
6264
63- private function generatePKCECodeVerifier (int $ length = 128 )
65+ private function generatePKCECodeVerifier (int $ byteLength = 96 ): string
6466 {
65- if ($ length < 43 || $ length > 128 ) {
66- throw new \Exception ("Length must be between 43 and 128 " );
67+ if ($ byteLength < 32 || $ byteLength > 96 ) {
68+ throw new \Exception (
69+ "Final length must be between 43 and 128, so the number of random bytes must be between 32 and 96 "
70+ );
6771 }
6872
69- $ randomBytes = random_bytes ($ length );
73+ $ randomBytes = random_bytes ($ byteLength );
7074 return rtrim (strtr (base64_encode ($ randomBytes ), '+/ ' , '-_ ' ), '= ' );
7175 }
7276
You can’t perform that action at this time.
0 commit comments