Verify and extract security token from the HTTP response
@param mixed $response
@return mixed BinarySecurityToken or Exception when an error is present
@throws Exception
979860
protected function processSecurityTokenResponse($response)
    {
        $xml = new \DOMDocument();
        $xml->loadXML($response);
        $xpath = new \DOMXPath($xml);
        if ($xpath->query("//wsse:BinarySecurityToken")->length > 0) {
            $nodeToken = $xpath->query("//wsse:BinarySecurityToken")->item(0);
            if (!empty($nodeToken)) {
              return $nodeToken->nodeValue;
            }
        }

        if ($xpath->query("//S:Fault")->length > 0) {
            // Returning the full fault value in case any other response comes within the fault node.
            throw new \RuntimeException($xpath->query("//S:Fault")->item(0)->nodeValue);
        }

        throw new \RuntimeException('Error trying to get a token, check your URL or credentials');
    }
847149
public function validateResponse($url, $response)
	{
		if (strpos($url, 'verify_credentials') === false && $response->code != 200)
		{
			$error = json_decode($response->body);

			if (property_exists($error, 'error'))
			{
				throw new \DomainException($error->error);
			}

			$error = $error->errors;

			throw new \DomainException($error[0]->message, $error[0]->code);
		}
	}
1060405
protected function response($response) {
    // Check for HTTP response error codes.
    if ($this->client->error) {
      $this->onErrorResponse(
        $this->client->errorCode,
        $this->client->errorMessage,
        $response
      );
    }
    else {
      $this->onSuccessfulResponse($response);
    }
    return $response;
  }
877283
private function decodeResponse(string $response)
    {
        if (strpos($response, '!') !== false) {
            throw new \Exception($response);
        }

        return new BotScoutResponse($response);
    }
220559
protected function verifyResponse($response)
    {
        if (false === $response) {
            throw new BadResponseException('WAMP Server did not respond properly');
        }

        $subres = substr($response, 0, 12);

        if ($subres != 'HTTP/1.1 101') {
            throw new BadResponseException('Unexpected Response. Expected HTTP/1.1 101 got ' . $subres);
        }
    }
1248642
public function getUserFromTokenResponse($response)
    {
        $user = $this->mapUserToObject($this->getUserByToken(
            $token = $this->parseAccessToken($response)
        ));

        $this->credentialsResponseBody = $response;

        if ($user instanceof User) {
            $user->setAccessTokenResponseBody($this->credentialsResponseBody);
        }

        return $user->setToken($token)
            ->setRefreshToken($this->parseRefreshToken($response))
            ->setExpiresIn($this->parseExpiresIn($response));
    }
166986
public function verifyResponseMac(Response $response)
    {
        $mac = $this->generateMacKey($response, 'payment_response');

        /** @noinspection SpellCheckingInspection */
        if ($mac !== $response->getParam('SOLOPMT_RETURN_MAC')) {
            /** @noinspection SpellCheckingInspection */
            $params = [
                'SOLOPMT_RETURN_VERSION' => $response->getParam('SOLOPMT_RETURN_VERSION'),
                'SOLOPMT_RETURN_STAMP' => $response->getParam('SOLOPMT_RETURN_STAMP'),
                'SOLOPMT_RETURN_REF' => $response->getParam('SOLOPMT_RETURN_REF'),
                'SOLOPMT_RETURN_PAID' => $response->getParam('SOLOPMT_RETURN_PAID'),
                'SOLOPMT_RETURN_MAC' => $response->getParam('SOLOPMT_RETURN_MAC'),
                'generated_mac' => $mac,
            ];
            throw new Exception('BankNet-> Incorrect signature. (' . implode(',', $params) . ')');
        }
    }
1024105
protected function getFederatedAuthenticationInformation($response) {
        if ($response) {
            $xml = new \DOMDocument();
            $xml->loadXML($response);
            $xpath = new \DOMXPath($xml);
            if ($xpath->query("//STSAuthURL")->length > 0) {
                return $xpath->query("//STSAuthURL")->item(0);
            }
        }
        return '';
    }
347435
protected function getJsonFromResponse(Response $response)
    {
        $responseBody = $response->getBody();
        if ($response->getStatusCode() >= 400) {
            throw new Exception($responseBody);
        }
        $json = @json_decode($responseBody, true);
        if ($json === null) {
            throw new Exception('Failed to decode CommunityTranslation response');
        }

        return $json;
    }
930661
public function detect($response)
    {
        if (stripos($response, '<error>') === false) {
            return $response;
        }

        $error = preg_replace('/^.*<error>([^<]+)<\/error>.*$/ims', '$1', $response);

        switch ($error) {
            case 'Banned':
                throw BannedException::banned();
            case 'Anime not found':
                throw NotFoundException::anime();
            default:
                throw ErrorException::error($error);
        }
    }
1153798
public function validateResponse(Response $response)
	{
		$xml = simplexml_load_string($response->body);

		if (isset($xml->warnings))
		{
			throw new \DomainException($xml->warnings->info);
		}

		if (isset($xml->error))
		{
			throw new \DomainException($xml->error['info']);
		}

		return $xml;
	}
1183736
protected function processResponse(Response $response)
    {
        if ($response->hasErrors()) {
            throw new \Exception($this->getErrorMessage($response));
        }

        return is_array($response->body) ? $response->body['data'] : $response->body->data;
    }
974452
protected function parseResponse($response)
    {
        $result = json_decode((string) $response->getBody(), true);

        if (isset($result['exception'])) {
            throw (new DelegationException($result['message']))->setException($result['exception']);
        }

        return $result;
    }
831343
private function verifyResponseMac(Response $response)
    {
        $macSource = $this->getMacSource($response);
        $macValue = $response->getParam('VK_MAC');
        $certPath = $this->getPkcCertPath();

        $isVerified = $this->verifySignatureWithCertificate($certPath, $macSource, base64_decode($macValue));

        return (bool)$isVerified;
    }
830713
public function validateResponseSignature(\Yubikey\Response $response)
    {
        $params = array();
        foreach ($response->getProperties() as $property) {
            $value = $response->$property;
            if ($value !== null) {
                $params[$property] = $value;
            }
        }
        ksort($params);

        $signature = $this->generateSignature($params);
        return $this->hash_equals($signature, $response->getHash(true));
    }
163062
public function isValid($response)
    {
        if (is_null($this->secretKey))
            throw new \Exception('You must set your secret key');

        if (empty($response)) {

            $this->errorCodes = array('internal-empty-response');

            return false;
        }

        $params = array(
            'secret'   => $this->secretKey,
            'response' => $response,
            'remoteip' => $this->remoteIp,
        );

        $url = self::VERIFY_URL.'?'.http_build_query($params);

        if (function_exists('curl_version'))
        {
            $curl = curl_init($url);
            curl_setopt($curl, CURLOPT_HEADER, false);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, $this->verifyTimeout);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            $response = curl_exec($curl);
        }
        else
        {
            $response = file_get_contents($url);
        }

        if (empty($response) || is_null($response) || !$response)
        {
            return false;
        }

        $json = json_decode($response, true);

        if (isset($json['error-codes']))
        {
            $this->errorCodes = $json['error-codes'];
        }

        return $json['success'];
    }
897305
protected function handleTokenResponse(ResponseInterface $response)
    {
        $statusCode = $response->getStatusCode();
        if (500 <= $statusCode) {
            $e = new ServiceUnavailableException();
            $e->setResponse($response);
            throw $e;
        }

        $contentTypes = $response->getHeader('content-type');
        if (empty($contentTypes) || (0 !== strpos($contentTypes[0], 'application/json') && 0 !== strpos($contentTypes[0], 'text/javascript'))) {
            $e = new UnknownContentTypeException();
            $e->setResponse($response);
            if (!empty($contentTypes)) {
                $e->setContentType($contentTypes[0]);
            }
            throw $e;
        }

        $data = json_decode($response->getBody()->getContents(), true);
        if (200 !== $statusCode) {
            $e = new RequestTokenException();
            $e->setResponse($response);

            if (isset($data['error'])) {
                $e->setError(is_array($data['error']) ? json_encode($data['error']) : $data['error']);
            }

            if (isset($data['error_description'])) {
                $e->setDescription($data['error_description']);
            }

            if (isset($data['error_uri'])) {
                $e->setUri($data['error_uri']);
            }

            throw $e;
        }

        if (isset($data['access_token'])) {
            $this->setAccessToken($data['access_token']);
        }

        return $data;
    }