api_key = $api_key; } /** * Authenticates the given request with the credentials. * * @since 0.1.0 * * @param Request $request The request instance. Updated in place. */ public function authenticate( Request $request ): void { if ( 'authorization' === strtolower( $this->header_name ) ) { $request->add_header( $this->header_name, 'Bearer ' . $this->api_key ); } else { $request->add_header( $this->header_name, $this->api_key ); } } /** * Sets the header name to use to add the credentials to a request. * * @since 0.1.0 * * @param string $header_name The header name. */ public function set_header_name( string $header_name ): void { $this->header_name = $header_name; } /** * Returns the option definitions needed to store the credentials. * * @since 0.1.0 * * @param string $service_slug The service slug. * @return array> The option definitions. */ public static function get_option_definitions( string $service_slug ): array { $option_slug = sprintf( 'ais_%s_api_key', $service_slug ); return array( $option_slug => array( 'type' => 'string', 'default' => '', 'show_in_rest' => true, 'autoload' => true, ), ); } }