| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Yoast\WP\SEO\Config; |
| 4 | 4 | |
| 5 | +use Exception; | |
| 5 | 6 | use UnexpectedValueException; |
| 6 | 7 | use YoastSEO_Vendor\GuzzleHttp\Exception\BadResponseException; |
| 7 | 8 | use YoastSEO_Vendor\League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
| 8 | 9 | use YoastSEO_Vendor\League\OAuth2\Client\Provider\GenericProvider; |
| @@ -26,9 +27,9 @@ | ||
| 26 | 27 | |
| 27 | 28 | /** |
| 28 | 29 | * The method to use. |
| 29 | 30 | * |
| 30 | - * @var string | |
| 31 | + * @var string|null | |
| 31 | 32 | */ |
| 32 | 33 | protected $pkceMethod = null; |
| 33 | 34 | |
| 34 | 35 | /** |
| @@ -70,9 +71,9 @@ | ||
| 70 | 71 | * @param int $length Length of the random string to be generated. |
| 71 | 72 | * |
| 72 | 73 | * @return string |
| 73 | 74 | * |
| 74 | - * @throws \Exception Throws exception if an invalid value is passed to random_bytes. | |
| 75 | + * @throws Exception Throws exception if an invalid value is passed to random_bytes. | |
| 75 | 76 | */ |
| 76 | 77 | protected function getRandomPkceCode( $length = 64 ) { |
| 77 | 78 | return \substr( |
| 78 | 79 | \strtr( |
| @@ -78,12 +79,12 @@ | ||
| 78 | 79 | \strtr( |
| 79 | 80 | // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
| 80 | 81 | \base64_encode( \random_bytes( $length ) ), |
| 81 | 82 | '+/', |
| 82 | - '-_' | |
| 83 | + '-_', | |
| 83 | 84 | ), |
| 84 | 85 | 0, |
| 85 | - $length | |
| 86 | + $length, | |
| 86 | 87 | ); |
| 87 | 88 | } |
| 88 | 89 | |
| 89 | 90 | /** |
| @@ -102,9 +103,9 @@ | ||
| 102 | 103 | * |
| 103 | 104 | * @return array The authorization parameters |
| 104 | 105 | * |
| 105 | 106 | * @throws InvalidArgumentException Throws exception if an invalid PCKE method is passed in the options. |
| 106 | - * @throws \Exception When something goes wrong with generating the PKCE code. | |
| 107 | + * @throws Exception When something goes wrong with generating the PKCE code. | |
| 107 | 108 | */ |
| 108 | 109 | protected function getAuthorizationParameters( array $options ) { |
| 109 | 110 | if ( empty( $options['state'] ) ) { |
| 110 | 111 | $options['state'] = $this->getRandomState(); |
| @@ -134,11 +135,11 @@ | ||
| 134 | 135 | \strtr( |
| 135 | 136 | // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
| 136 | 137 | \base64_encode( \hash( 'sha256', $this->pkceCode, true ) ), |
| 137 | 138 | '+/', |
| 138 | - '-_' | |
| 139 | + '-_', | |
| 139 | 140 | ), |
| 140 | - '=' | |
| 141 | + '=', | |
| 141 | 142 | ); |
| 142 | 143 | } |
| 143 | 144 | elseif ( $pkce_method === 'plain' ) { |
| 144 | 145 | $options['code_challenge'] = $this->pkceCode; |
| @@ -188,9 +189,9 @@ | ||
| 188 | 189 | $response = $this->getParsedResponse( $request ); |
| 189 | 190 | |
| 190 | 191 | if ( \is_array( $response ) === false ) { |
| 191 | 192 | throw new UnexpectedValueException( |
| 192 | - 'Invalid response received from Authorization Server. Expected JSON.' | |
| 193 | + 'Invalid response received from Authorization Server. Expected JSON.', | |
| 193 | 194 | ); |
| 194 | 195 | } |
| 195 | 196 | |
| 196 | 197 | $prepared = $this->prepareAccessTokenResponse( $response ); |
| @@ -215,9 +216,9 @@ | ||
| 215 | 216 | 'responseCode', |
| 216 | 217 | 'responseResourceOwnerId', |
| 217 | 218 | 'scopes', |
| 218 | 219 | 'pkceMethod', |
| 219 | - ] | |
| 220 | + ], | |
| 220 | 221 | ); |
| 221 | 222 | } |
| 222 | 223 | |
| 223 | 224 | /** |