public function authenticate(array $options = []): array
    {
        $query = [];
        foreach (self::$openIdRequiredFields as $field) {
            if (isset($options['openid_'.$field])) {
                $query['openid.'.$field] = $options['openid_'.$field];
            } elseif (isset($options['openid.'.$field])) {
                $query['openid.'.$field] = $options['openid.'.$field];
            } else {
                throw AuthenticationException::invalidArgument($field, $options);
            }
        }

        if (self::OPEN_ID_NS !== $query['openid.ns']) {
            throw AuthenticationException::invalidArgument('ns', $options);
        }

        if ('id_res' === $query['openid.mode']) {
            $query['openid.mode'] = 'check_authentication';
        } else {
            throw AuthenticationException::invalidArgument('mode', $options);
        }

        if ($this->getAuthEndpoint() !== $query['openid.op_endpoint']) {
            throw AuthenticationException::invalidArgument('op_endpoint', $options);
        }

        if ($this->getRedirectUriWithState($options['state'] ?? null) !== $query['openid.return_to']) {
            throw AuthenticationException::invalidArgument('return_to', $options);
        }

        if (isset($options['openid_claimed_id'], $options['openid_identity'])) {
            $query['openid.claimed_id'] = $options['openid_claimed_id'];
            $query['openid.identity'] = $options['openid_identity'];
        } elseif (isset($options['openid.claimed_id'], $options['openid.identity'])) {
            $query['openid.claimed_id'] = $options['openid.claimed_id'];
            $query['openid.identity'] = $options['openid.identity'];
        }

        try {
            $data = $this->httpClient->requestKeyValueForm(HttpInterface::METHOD_POST, $this->getAuthEndpoint(), $query);
        } catch (GuzzleException $e) {
            throw $this->handleApiException($e);
        }
        if (!isset($data['ns'], $data['is_valid']) || self::OPEN_ID_NS !== $data['ns'] || 'true' !== $data['is_valid']) {
            throw new AuthenticationException($data, 'OpendID authentication is failed.');
        }

        return array_merge($query, $data);
    }
public function authenticate(array $options = []): array
    {
        $query = [];
        foreach (self::$openIdRequiredFields as $field) {
            if (isset($options['openid_'.$field])) {
                $query['openid.'.$field] = $options['openid_'.$field];
            } elseif (isset($options['openid.'.$field])) {
                $query['openid.'.$field] = $options['openid.'.$field];
            } else {
                throw AuthenticationException::invalidArgument($field, $options);
            }
        }

        if (self::OPEN_ID_NS !== $query['openid.ns']) {
            throw AuthenticationException::invalidArgument('ns', $options);
        }

        if ('id_res' === $query['openid.mode']) {
            $query['openid.mode'] = 'check_authentication';
        } else {
            throw AuthenticationException::invalidArgument('mode', $options);
        }

        if ($this->getAuthEndpoint() !== $query['openid.op_endpoint']) {
            throw AuthenticationException::invalidArgument('op_endpoint', $options);
        }

        if ($this->getRedirectUriWithState($options['state'] ?? null) !== $query['openid.return_to']) {
            throw AuthenticationException::invalidArgument('return_to', $options);
        }

        if (isset($options['openid_claimed_id'], $options['openid_identity'])) {
            $query['openid.claimed_id'] = $options['openid_claimed_id'];
            $query['openid.identity'] = $options['openid_identity'];
        } elseif (isset($options['openid.claimed_id'], $options['openid.identity'])) {
            $query['openid.claimed_id'] = $options['openid.claimed_id'];
            $query['openid.identity'] = $options['openid.identity'];
        }

        try {
            $data = $this->httpClient->requestKeyValueForm(HttpInterface::METHOD_POST, $this->getAuthEndpoint(), $query);
        } catch (GuzzleException $e) {
            throw $this->handleApiException($e);
        }
        if (!isset($data['ns'], $data['is_valid']) || self::OPEN_ID_NS !== $data['ns'] || 'true' !== $data['is_valid']) {
            throw new AuthenticationException($data, 'OpendID authentication is failed.');
        }

        return array_merge($query, $data);
    }
{@inheritdoc}