Workaround method for HWIOAuthBundle issue

Waiting for this issue to be fixed upstream

@param \HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface $response
@return string
183203
protected function getEmail( UserResponseInterface $response )
    {
        $responseArray = $response->getResponse();
        switch ( $response->getResourceOwner()->getName() )
        {
            case UserIdentity::getReadableType( UserIdentity::TYPE_TWITTER ):
                return NULL;
            case UserIdentity::getReadableType( UserIdentity::TYPE_YAHOO ):
                if ( array_key_exists( 'emails', $responseArray['profile'] ))
                {
                    if ( count( $responseArray['profile']['emails'] ) > 0 )
                    {
                        return $responseArray['profile']['emails'][0]['handle'];
                    }
                }
            default:
                if ( array_key_exists( 'email', $responseArray ))
                {
                    return $responseArray['email'];
                }
        }
    }
600174
protected function getProperty(UserResponseInterface $response)
    {
        $resourceOwnerName = $response->getResourceOwner()->getName();

        if (!isset($this->properties[$resourceOwnerName])) {
            throw new \RuntimeException(sprintf("No property defined for entity for resource owner '%s'.", $resourceOwnerName));
        }

        return $this->properties[$resourceOwnerName];
    }
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;
    }
820941
private function GetUserResponse($response)
    {
        if (isset($response->PersonType)) {
            switch ($response->PersonType) {
                case PersonType::Natural:
                    return $this->CastResponseToEntity($response, '\MangoPay\UserNatural');
                case PersonType::Legal:
                    return $this->CastResponseToEntity($response, '\MangoPay\UserLegal');
                default:
                    throw new Libraries\Exception('Unexpected response. Wrong PersonType value');
            }
        } else {
            throw new Libraries\Exception('Unexpected response. Missing PersonType property');
        }
    }
1088123
public static function getPublicKeyFromResponse(string $response) : string
    {
        $version = static::getVersion($response);
        if ($version === 2) {
            if (\strlen($response) < 236) {
                throw new InvalidArgumentException;
            }

            return \substr($response, 28, 32);
        }

        throw new InvalidArgumentException('The response provided is not suitable for public key extraction.');
    }
211000
protected function handleResponse(Response $response)
    {
        $statusCode = $response->getStatusCode();

        switch ($statusCode) {
            case 401:
                $response = $this->processNotAuthorized();
                break;
        }

        return $response;
    }
1229849
static function _httpResponseToMessage($response)
    {
        // Should this function be named Message.fromHTTPResponse instead?
        $response_message = Auth_OpenID_Message::fromKVForm($response->body);

        if ($response->status == 400) {
            return Auth_OpenID_ServerErrorContainer::fromMessage(
                        $response_message);
        } else if ($response->status != 200 and $response->status != 206) {
            return null;
        }

        return $response_message;
    }
706438
protected function getUnauthorizedResponse()
    {
        $authHeaderValue = $this->realm === null ? static::AUTHENTICATION_SCHEME :
            static::AUTHENTICATION_SCHEME . ' realm="' . $this->realm . '"';

        return $this->integration->createResponse(
            null,
            Response::HTTP_UNAUTHORIZED,
            [self::HEADER_WWW_AUTHENTICATE => $authHeaderValue]
        );
    }
611810
protected function _getHandlerKey(Zend_Http_Response $response = null)
    {
        if ($response) {
            $code = $response->getStatus();
            if ($response->isSuccessful() || $response->isRedirect()) {
                return 'success';
            } elseif ($code < 500 && $code >= 400) {
                return 'client_error';
            } elseif ($code >= 500) {
                return 'server_error';
            }
            // @codeCoverageIgnoreStart
        }
        // @codeCoverageIgnoreEnd
        return 'no_response';
    }
77991
protected function _setHeaders($response)
    {
        $headers = $this->getConfig('headers');

        if (!is_array($headers)) {
            return $response;
        }

        return $response
            ->withHeader($headers['limit'], (string)$this->getConfig('limit'))
            ->withHeader($headers['remaining'], (string)$this->_getRemainingConnections())
            ->withHeader(
                $headers['reset'],
                (string)Cache::read($this->_getCacheExpirationKey(), static::$cacheConfig)
            );
    }
614570
protected function createUser( UserResponseInterface $response )
    {
        $user = $this->userManager->createUser();
        $user->setUsername( $this->createUniqueUsername( $this->getRealName( $response )));
        $user->setEmail( $this->getEmail( $response ) );
        $user->setPassword( '' );
        $user->setEnabled( true );
        $this->userManager->updateUser( $user );
        $this->createIdentity( $user, $response );
        return $user;
    }
1088137
public function authenticateResponse(BaseUser $user, Response $response)
    {
        return $this->setCookieForResponse($response, $this->createResponseAuthModel($user));
    }
873042
private function getRequestId(RequestInterface $request, ResponseInterface $response)
    {
        if ($request->hasHeader('X-Request-Id')) {
            return $request->getHeader('X-Request-Id')[0];
        }

        if ($response->hasHeader('X-Request-Id')) {
            return $response->getHeader('X-Request-Id')[0];
        }

        return '';
    }
188791
protected static function get_hold_response($response)
    {
        $iresponse = null;
        if (!is_null($response)) {
            if (is_string($response)) {
                $response = new Response(null, null, null, $response);
            }
            $iresponse = array();
            if (!is_null($response->code)) {
                $iresponse['code'] = $response->code;
            }
            if (!is_null($response->reason)) {
                $iresponse['reason'] = $response->reason;
            }
            if (!is_null($response->headers) && count($response->headers) > 0) {
                $iresponse['headers'] = $response->headers;
            }
            if (!is_null($response->body)) {
                if (Encoding::is_binary_data($response->body)) {
                    $iresponse['body-bin'] = base64_encode($response->body);
                } else {
                    $iresponse['body'] = $response->body;
                }
            }
        }
        return $iresponse;
    }
58307
public function getResponseError(ResponseInterface $response)
    {
        if ($this->isError($response)) {
            $error = $this->getError($response);
            if (in_array($error, ['invalid_token', 'not_allowed_ip'], true)) {
                $this->app->user->logout();
                $this->app->response->refresh()->send();
                $this->app->end();
            }

            return $error ?: 'unknown api error';
        }

        if ($response->getRequest()->getQuery()->action === 'search') {
            $this->fixResponse($response);
        }

        return false;
    }
86585
public function get(UserInterface $user, $platform)
    {
        $request = $this->initHttpRequest(
            $this->account->getApiToken(Token::API_SSO),
            $this->account->getName()
        );
        $request->setPath(ApiRequest::PATH_SSO_AUTH);
        $request->setContentType(self::CONTENT_TYPE_APPLICATION_JSON);
        $request->setReplaceParams(array('{platform}' => $platform));
        $response = $request->post($user);
        if ($response->getCode() !== 200) {
            throw ExceptionBuilder::fromHttpRequestAndResponse($request, $response);
        }

        return $response->getJsonResult()->login_url;
    }
1075467
public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseInterface $response)
    {
        foreach ($this->enabledGrantTypes as $grantType) {
            if (!$grantType->canRespondToAccessTokenRequest($request)) {
                continue;
            }
            $tokenResponse = $grantType->respondToAccessTokenRequest(
                $request,
                $this->getResponseType(),
                $this->grantTypeAccessTokenTTL[$grantType->getIdentifier()]
            );

            if ($tokenResponse instanceof ResponseTypeInterface) {
                return $tokenResponse->generateHttpResponse($response);
            }
        }

        throw OAuthServerException::unsupportedGrantType();
    }