| 1 |
<?php |
| 2 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 3 |
|
| 4 |
namespace Yoast\WP\SEO\MyYoast_Client\Application\Ports; |
| 5 |
|
| 6 |
use SensitiveParameter; |
| 7 |
use Yoast\WP\SEO\MyYoast_Client\Domain\Auth_Token_Type; |
| 8 |
use Yoast\WP\SEO\MyYoast_Client\Domain\HTTP_Response; |
| 9 |
|
| 10 |
/** |
| 11 |
* Port for communicating with the OAuth authorization/resource server. |
| 12 |
* |
| 13 |
* Handles DPoP proof injection, nonce management, and authenticated requests. |
| 14 |
*/ |
| 15 |
interface OAuth_Server_Client_Interface { |
| 16 |
|
| 17 |
/** |
| 18 |
* Sends an HTTP request with optional DPoP proof injection, nonce retry, and rate limit handling. |
| 19 |
* |
| 20 |
* @param string $method The HTTP method. |
| 21 |
* @param string $url The request URL. |
| 22 |
* @param array<string, string|int|bool|string[]|null> $options Request options: 'headers', 'body', 'timeout', 'dpop' (bool), 'access_token'. |
| 23 |
* |
| 24 |
* @return HTTP_Response The parsed response. |
| 25 |
*/ |
| 26 |
public function request( string $method, string $url, array $options = [] ): HTTP_Response; |
| 27 |
|
| 28 |
/** |
| 29 |
* Sends an authenticated resource request with DPoP proof. |
| 30 |
* |
| 31 |
* @param string $method The HTTP method. |
| 32 |
* @param string $url The resource URL. |
| 33 |
* @param string $access_token The access token. |
| 34 |
* @param string $token_type An Auth_Token_Type constant. |
| 35 |
* @param array<string, string|int|bool|string[]|null> $options Additional request options. |
| 36 |
* |
| 37 |
* @return HTTP_Response The parsed response. |
| 38 |
*/ |
| 39 |
public function authenticated_request( |
| 40 |
string $method, |
| 41 |
string $url, |
| 42 |
// phpcs:ignore PHPCompatibility.Attributes.NewAttributes.PHPNativeAttributeFound -- No-op on PHP < 8.2; redacts parameter from stack traces on PHP 8.2+. |
| 43 |
#[SensitiveParameter] |
| 44 |
string $access_token, |
| 45 |
string $token_type = Auth_Token_Type::DPOP, |
| 46 |
array $options = [] |
| 47 |
): HTTP_Response; |
| 48 |
} |
| 49 |
|