128 ) { return false; } if ( 43 !== strlen( $challenge ) ) { return false; } // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- RFC 7636 §4.6 mandates base64url encoding; not obfuscation. $sha_bytes = hash( 'sha256', $verifier, true ); $base64 = base64_encode( $sha_bytes ); $base64_url = strtr( $base64, '+/', '-_' ); $computed = rtrim( $base64_url, '=' ); // phpcs:enable WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode return hash_equals( $challenge, $computed ); } /** * Return true iff the given method name is exactly `S256`. Convenience * for the authorize handler — reject anything else early with * `invalid_request&error_description=PKCE+S256+required`. * * @param string $method Client-supplied code_challenge_method. * @return bool */ public static function is_s256( string $method ): bool { return 'S256' === $method; } }