public function authenticate(array $options = []): array
    {
        if (empty($options['code']) || !is_string($options['code'])) {
            throw AuthenticationException::invalidArgument('code', $options);
        }

        $query = [
            'grant_type' => 'authorization_code',
            'code' => $options['code'],
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'redirect_uri' => $options['redirect_uri'] ?? $this->redirectUri,
        ];

        try {
            $data = (array) $this->httpClient->requestJson(HttpInterface::METHOD_POST, $this->getTokenEndpoint(), null, $query);
        } catch (GuzzleException $e) {
            throw $this->handleApiException($e);
        }

        if (empty($data['access_token'])) {
            throw new AuthenticationException($data, 'OAuth2 authentication is failed.');
        }

        $this->setAccessToken($data['access_token']);

        return $data;
    }
public function authenticate(array $options = []): array
    {
        if (empty($options['code']) || !is_string($options['code'])) {
            throw AuthenticationException::invalidArgument('code', $options);
        }

        $query = [
            'grant_type' => 'authorization_code',
            'code' => $options['code'],
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'redirect_uri' => $options['redirect_uri'] ?? $this->redirectUri,
        ];

        try {
            $data = (array) $this->httpClient->requestJson(HttpInterface::METHOD_POST, $this->getTokenEndpoint(), null, $query);
        } catch (GuzzleException $e) {
            throw $this->handleApiException($e);
        }

        if (empty($data['access_token'])) {
            throw new AuthenticationException($data, 'OAuth2 authentication is failed.');
        }

        $this->setAccessToken($data['access_token']);

        return $data;
    }
{@inheritdoc}