| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
|
| 5 |
namespace Yoast\WP\SEO\AI\Authentication\Application; |
| 6 |
|
| 7 |
use WP_User; |
| 8 |
use Yoast\WP\SEO\AI\HTTP_Request\Domain\Request; |
| 9 |
use Yoast\WP\SEO\AI\HTTP_Request\Domain\Response; |
| 10 |
|
| 11 |
/** |
| 12 |
* Strategy for authenticating and dispatching an outbound yoast-ai request. |
| 13 |
* |
| 14 |
* Strategies own the full call: they acquire whatever credentials they need, dispatch the request, |
| 15 |
* map the result into the AI Response domain object, and translate any non-200 into the matching |
| 16 |
* typed exception. Any failure-path cleanup (clearing a stale cached token, deleting stored JWTs, |
| 17 |
* translating one exception type into another) happens inside the implementation before the |
| 18 |
* exception is rethrown. The sender does not retry — it only chooses between a primary and an |
| 19 |
* optional fallback strategy. |
| 20 |
*/ |
| 21 |
interface Auth_Strategy_Interface { |
| 22 |
|
| 23 |
/** |
| 24 |
* Authenticates and dispatches the request, returning the parsed response. |
| 25 |
* |
| 26 |
* Non-200 responses are translated into typed exceptions from the AI HTTP_Request exception |
| 27 |
* family. Strategy-specific 4xx semantics (e.g. an OAuth-only `insufficient_scope` 403) are |
| 28 |
* thrown as their own typed exceptions so the sender can route them past the fallback path. |
| 29 |
* |
| 30 |
* @param Request $request The base request, without auth headers. |
| 31 |
* @param WP_User $user The WP user the request is on behalf of. |
| 32 |
* |
| 33 |
* @return Response The parsed response. |
| 34 |
*/ |
| 35 |
public function send( Request $request, WP_User $user ): Response; |
| 36 |
} |
| 37 |
|