wppaste
WordPress

ApiKeyRequestAuthentication

Since
0.1.0
Source
wp-includes/php-ai-client/src/Providers/Http/DTO/ApiKeyRequestAuthentication.php:19
Class for HTTP request authentication using an API key.

Compatibility

WordPress
since 0.1.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 2 of the 5 tracked releases, added in 0.1.0.

Properties · 1

$apiKeystringprotected

Methods · 6

Source code

class ApiKeyRequestAuthentication extends AbstractDataTransferObject implements RequestAuthenticationInterface{    public const KEY_API_KEY = 'apiKey';    /**     * @var string The API key used for authentication.     */    protected string $apiKey;    /**     * Constructor.     *     * @since 0.1.0     *     * @param string $apiKey The API key used for authentication.     */    public function __construct(string $apiKey)    {        $this->apiKey = $apiKey;    }    /**     * {@inheritDoc}     *     * @since 0.1.0     */    public function authenticateRequest(\WordPress\AiClient\Providers\Http\DTO\Request $request): \WordPress\AiClient\Providers\Http\DTO\Request    {        // Add the API key to the request headers.        return $request->withHeader('Authorization', 'Bearer ' . $this->apiKey);    }    /**     * Gets the API key.     *     * @since 0.1.0     *     * @return string The API key.     */    public function getApiKey(): string    {        return $this->apiKey;    }    /**     * {@inheritDoc}     *     * @since 0.1.0     *     * @since 0.1.0     *     * @return ApiKeyRequestAuthenticationArrayShape     */    public function toArray(): array    {        return [self::KEY_API_KEY => $this->apiKey];    }    /**     * {@inheritDoc}     *     * @since 0.1.0     *     * @since 0.1.0     */    public static function fromArray(array $array): self    {        static::validateFromArrayData($array, [self::KEY_API_KEY]);        return new self($array[self::KEY_API_KEY]);    }    /**     * {@inheritDoc}     *     * @since 0.1.0     */    public static function getJsonSchema(): array    {        return ['type' => 'object', 'properties' => [self::KEY_API_KEY => ['type' => 'string', 'title' => 'API Key', 'description' => 'The API key used for authentication.']], 'required' => [self::KEY_API_KEY]];    }}

Changelog

Introduced in 0.1.0. Unchanged from 7.0.4 through 7.1.0.

  1. 7.0.4
  2. 7.1.0

Signature, return type and hooks compared across 2 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/php-ai-client/src/Providers/Http/DTO/ApiKeyRequestAuthentication.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.