public function oauth2() { try { $this->initOauth2(); $action = $this->getParam('oa2_action'); $state = $this->getParam('oa2_state'); // compare with 'state' $adapter_id = $this->getParam('oa2_adapter'); $ajax = $this->getParam('ajax'); $params = $this->request->get; unset($params['route']); if ($ajax !== 'ajax') { $params['ajax'] = 'ajax'; $url = $this->url->link('account/social_media_login/oauth2') . '&' . http_build_query($params); $this->vars['ajaxurl'] = html_entity_decode($url); $this->vars['message'] = $this->language->get('please_wait'); return $this->out(); } /** Everything from here should only be handled as an ajax request ajax request */ if ($action === 'connecting' && ($adapter = $this->getOAuth2Adapter($adapter_id, $state))) { $logged = $adapter->login($params); // log weirdness if (empty($logged['access_token'])) { OAuth2::log($logged); } $profile = $adapter->profile($logged); $session = array($profile[OAuth2_Consts::CUSTOMER_EXT_ID], $profile[OAuth2_Consts::CUSTOMER_DISPLAYNAME], $adapter->getId()); $user = $this->createCustomerAndLogin($profile, $logged); if (!$user || !$this->customer->isLogged()) { $this->vars['success'] = false; $this->vars['message'] = $this->language->get('error_retry'); } else { OAuth2::createSession($session); $this->vars['success'] = true; $this->vars['message'] = $this->language->get('success_login'); $this->vars['redirect'] = isset($this->session->data['redirect']) ? $this->session->data['redirect'] : $this->url->link('account/account'); } // either output html or ajax here } elseif ($action === 'cancel' && ($adapter = $this->getOAuth2Adapter($adapter_id, $state))) { $this->vars['success'] = false; $this->vars['message'] = $this->language->get('error_retry'); } } catch (OAuth2_Exception $e) { $this->logException($e); $this->vars['success'] = false; $this->vars['message'] = $this->language->get('error_retry'); } $this->outJSON(); }
/** * Get Avatar from remote site pointed by URL * Adapters may wish to override this to access protected resource. * * @throws OAuth2_Exception * @param string $url * @param array $params Authentication Parameters * @return string|bool */ public function getAvatar($url, $params) { $info = array(); $result = OAuth2_CURL::HttpRequest($url, null, OAuth2_CURL::HTTP_METHOD_GET, null, $info); if ($info['http_code'] != '200') { OAuth2::log($url . ': bad statuscode ' . $info['http_code']); return false; } return $result; }