Creates oauth exception from response.

@param  ResponseInterface $response
@param  array $data Parsed response data

@return IdentityProviderException
771729
public static function oauthException(ResponseInterface $response, $data)
    {
        return static::fromResponse(
            $response,
            isset($data['error']) ? $data['error'] : $response->getReasonPhrase()
        );
    }
329671
public function editPermission(array $data = [], $id = null)
    {
        if (!empty($id)) {
            $data['id'] = $id;
        }
        try{
            return $this->createPermission($data);
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }
    }
1141223
public static function createFromResponse($responseData)
    {
        $balance = new self();
        $balance->setRawResponseData($responseData)
            ->processResponse();

        if ($balance['status'] !== 0 && $balance['status'] !== '0') {
            throw new Exception($balance['err_msg']);
        }

        return $balance;
    }
1322969
protected function _httpAuthenticate(Varien_Object $response)
    {
        $result = array(
            'authentication' => false,
            'message' => ''
        );

        $this->fixCgiHttpAuthentication(); //add cgi support
        $internalMerchantAccount = $this->_getConfigData('merchantAccount');
        $username = $this->_getConfigData('notification_username');
        $password = Mage::helper('core')->decrypt($this->_getConfigData('notification_password'));
        $submitedMerchantAccount = $response->getData('merchantAccountCode');

        if (empty($submitedMerchantAccount) && empty($internalMerchantAccount)) {
            if (strtolower(
                substr(
                    $response->getData('pspReference'), 0,
                    17
                )
            ) == "testnotification_" || strtolower(
                substr(
                    $response->getData('pspReference'), 0,
                    5
                )
            ) == "test_") {
                Mage::log(
                    'Notification test failed: merchantAccountCode is empty in magento settings', Zend_Log::DEBUG,
                    "adyen_notification.log", true
                );
                $result['message'] = 'merchantAccountCode is empty in magento settings';
            }

            return $result;
        }

        // validate username and password
        if ((!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW']))) {
            if (strtolower(
                substr(
                    $response->getData('pspReference'), 0,
                    17
                )
            ) == "testnotification_" || strtolower(
                substr(
                    $response->getData('pspReference'), 0,
                    5
                )
            ) == "test_") {
                Mage::log(
                    'Authentication failed: PHP_AUTH_USER and PHP_AUTH_PW are empty. See Adyen Magento manual CGI mode',
                    Zend_Log::DEBUG, "adyen_notification.log", true
                );
                $result['message'] = 'Authentication failed: PHP_AUTH_USER and PHP_AUTH_PW are empty. See Adyen Magento manual CGI mode';
            }

            return $result;
        }

        $accountCmp = !$this->_getConfigData('multiple_merchants')
            ? strcmp($submitedMerchantAccount, $internalMerchantAccount)
            : 0;
        $usernameCmp = strcmp($_SERVER['PHP_AUTH_USER'], $username);
        $passwordCmp = strcmp($_SERVER['PHP_AUTH_PW'], $password);
        if ($accountCmp === 0 && $usernameCmp === 0 && $passwordCmp === 0) {
            $result['authentication'] = true;
            return $result;
        }

        // If notification is test check if fields are correct if not return error
        if (strtolower(
            substr(
                $response->getData('pspReference'), 0,
                17
            )
        ) == "testnotification_" || strtolower(
            substr(
                $response->getData('pspReference'), 0,
                5
            )
        ) == "test_") {
            if ($accountCmp != 0) {
                $result['message'] = "MerchantAccount in notification is not the same as in Magento settings and Allow multiple merchants option is not enabled";
            } elseif ($usernameCmp != 0 || $passwordCmp != 0) {
                $result['message'] = "username (PHP_AUTH_USER) and/or password (PHP_AUTH_PW) are not the same as Magento settings";
            }

            Mage::log($result['message'], Zend_Log::DEBUG, "adyen_notification.log", true);
        }

        return $result;
    }
276985
public static function createFromResponse($responseData)
    {
        $verifyCode = new self(null, null);
        $verifyCode->setRawResponseData($responseData)
            ->processResponse();

        if ($verifyCode['status'] !== 0 && $verifyCode['status'] !== '0') {
            throw new Exception($verifyCode['err_msg']);
        }

        return $verifyCode;
    }
1156522
protected function checkResponse(ResponseInterface $response, $data)
    {
        if (!empty($data['error'])) {
            throw new AmazonIdentityProviderException(
                $data['error'] ?: $response->getReasonPhrase(),
                $response->getStatusCode(),
                $response
            );
        }
    }
1051513
protected function checkResponse(ResponseInterface $response, $data)
    {
        if ($response->getStatusCode() >= 400) {
            throw DiscordIdentityProviderException::clientException($response, $data);
        }
    }
712903
protected function createUser(array $data, UserProviderInterface $userManager)
    {
        $userIdentityfield = $this->container->getParameter('rch_jwt_user.user_identity_field');

        $user = $userManager->createUser()
            ->setUsername($data[$userIdentityfield])
            ->setEmail($data[$userIdentityfield])
            ->setEnabled(true)
            ->setPlainPassword($data['password']);

        if (isset($data['facebook_id'])) {
            $user->setFacebookId($data['facebook_id']);
        }

        try {
            $userManager->updateUser($user);
        } catch (\Exception $e) {
            $message = $e->getMessage() ?: 'An error occured while creating the user.';

            throw new UserException(422, $message, $e);
        }

        return $user;
    }
280488
private function respondWithJson(ResponseInterface $response, array $data, $status)
    {
        $body = $response->getBody();
        $body->rewind();
        $body->write(json_encode($data));

        $response = $response->withStatus($status);
        $response = $response->withHeader('Content-Type', 'application/json;charset=utf-8');

        return $response;
    }
991996
public function getAccessTokenData(RequestInterface $request, ResponseInterface $response)
    {
        // Get the token parameter
        if ($token_param = $this->tokenType->getAccessTokenParameter($request, $response)) {
            // Get the stored token data (from the implementing subclass)
            // Check we have a well formed token
            // Check token expiration (expires is a mandatory paramter)
            if (!$token = $this->tokenStorage->getAccessToken($token_param)) {
                $response->setError(401, 'invalid_token', 'The access token provided is invalid');
            } elseif (!isset($token["expires"]) || !isset($token["client_id"])) {
                $response->setError(401, 'malformed_token', 'Malformed token (missing "expires")');
            } elseif (time() > $token["expires"]) {
                $response->setError(401, 'invalid_token', 'The access token provided has expired');
            } else {
                return $token;
            }
        }

        $authHeader = sprintf('%s realm="%s"', $this->tokenType->getTokenType(), $this->config['www_realm']);

        if ($error = $response->getParameter('error')) {
            $authHeader = sprintf('%s, error="%s"', $authHeader, $error);
            if ($error_description = $response->getParameter('error_description')) {
                $authHeader = sprintf('%s, error_description="%s"', $authHeader, $error_description);
            }
        }

        $response->addHttpHeaders(array('WWW-Authenticate' => $authHeader));

        return null;
    }
142111
protected function checkResponse(ResponseInterface $response, $data)
    {
        if (isset($data['error'])) {
            throw OktaIdentityProviderException::oauthException($response, $data);
        }
    }
470253
protected static function throwTransportableExceptionIfNeeded(
        array $response,
        string $url = ''
    ) {
        if (
            !isset($response['code']) ||
            0 === $response['code']
        ) {
            throw ConnectionException::buildConnectExceptionByUrl($url);
        }

        switch ($response['code']) {
            case ResourceNotAvailableException::getTransportableHTTPError():
                throw new ResourceNotAvailableException($response['body']['message']);
            case InvalidTokenException::getTransportableHTTPError():
                throw new InvalidTokenException($response['body']['message']);
            case InvalidFormatException::getTransportableHTTPError():
                throw new InvalidFormatException($response['body']['message']);
            case ResourceExistsException::getTransportableHTTPError():
                throw new ResourceExistsException($response['body']['message']);
            case ForbiddenException::getTransportableHTTPError():
                throw new ForbiddenException($response['body']['message']);
            case ConnectionException::getTransportableHTTPError():
                throw new ConnectionException('Apisearch returned an internal error code [500]');
        }
    }
531609
public static function factory(RequestInterface $request, Response $response)
    {
        if ($response->isClientError()) {
            $label = 'Client error response';
            $class = __NAMESPACE__ . '\\ClientErrorResponseException';
        } elseif ($response->isServerError()) {
            $label = 'Server error response';
            $class = __NAMESPACE__ . '\\ServerErrorResponseException';
        } else {
            $label = 'Unsuccessful response';
            $class = __CLASS__;
        }

        $message = $label . PHP_EOL . implode(PHP_EOL, array(
            '[status code] ' . $response->getStatusCode(),
            '[reason phrase] ' . $response->getReasonPhrase(),
            '[url] ' . $request->getUrl(),
        ));

        $e = new $class($message);
        $e->setResponse($response);
        $e->setRequest($request);

        return $e;
    }
497377
protected function parseResponse(ResponseInterface $response)
    {
        $response = json_decode($response->getBody()->getContents());

        if (isset($response->success) && $response->success) {
            return $response->data;
        }

        throw new \Exception($response->error_info, $response->error_code);
    }
11640
public function method($methodName, array $data = array())
    {
        $curl = new CURL();
        $url = $this->url . $methodName . '.json';
        $result = $curl->getURL($url, $data);
        $json = json_decode($result);
        if (!$result) {
            throw new Exception('No response retrieved');
        } elseif (!$json) {
            throw new Exception('Cannot parse JSON');
        } elseif ($json->error) {
            throw new Exception($result);
        }
        return $json;
    }
1155918
protected function createException(RequestInterface $request, Response $response, array $parts)
	{
		$message = 'Status Code: ' . $response->getStatusCode() . PHP_EOL
			. 'Kinvey Request ID: ' . $parts['request_id'] . PHP_EOL
			. 'Kinvey Exception Type: ' . $parts['type'] . PHP_EOL
			. 'Kinvey Error Message: ' . $parts['description'] . PHP_EOL
			. 'Kinvey Debug: ' . $parts['debug'];

		$class = new KinveyResponseException($message);
		$class->setExceptionType($parts['type']);
		$class->setResponse($response);
		$class->setRequest($request);
		$class->setRequestId($parts['request_id']);
		$class->setDebug($parts['debug']);
		return $class;
	}
1225129
protected function createRedirectErrorResponse(OAuthRedirectException $exception): ResponseInterface
    {
        $parameters = $this->filterNulls([
            'error'             => $exception->getErrorCode(),
            'error_description' => $exception->getErrorDescription(),
            'error_uri'         => $exception->getErrorUri(),
            'state'             => $exception->getState(),
        ]);

        $this->logDebug('Sending OAuth error via redirect.', $parameters);

        $fragment = $this->encodeAsXWwwFormUrlencoded($parameters);
        $uri      = (new Uri($exception->getRedirectUri()))->withFragment($fragment);

        $response = new RedirectResponse($uri, 302, $exception->getHttpHeaders());

        return $response;
    }