Beispiel #1
0
 public function actionAuthorizeGuest()
 {
     $requestPaths = XenForo_Application::get('requestPaths');
     $social = $this->_input->filterSingle('social', XenForo_Input::STRING);
     switch ($social) {
         case 'facebook':
             $facebookLink = XenForo_Link::buildPublicLink('full:register/facebook', null, array('reg' => 1, 'redirect' => $requestPaths['fullUri']));
             return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $facebookLink);
         case 'twitter':
             $twitterLink = XenForo_Link::buildPublicLink('full:register/twitter', null, array('reg' => 1, 'redirect' => $requestPaths['fullUri']));
             return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $twitterLink);
     }
     /* @var $oauth2Model bdApi_Model_OAuth2 */
     $oauth2Model = $this->getModelFromCache('bdApi_Model_OAuth2');
     /* @var $clientModel bdApi_Model_Client */
     $clientModel = $oauth2Model->getClientModel();
     $clientId = $this->_input->filterSingle('client_id', XenForo_Input::STRING);
     $client = $clientModel->getClientById($clientId);
     if (empty($client)) {
         return $this->responseError(new XenForo_Phrase('bdapi_authorize_error_client_x_not_found', array('client' => $clientId)), 404);
     }
     $authorizeParams = $this->_input->filter($oauth2Model->getAuthorizeParamsInputFilter());
     $redirectParams = $authorizeParams;
     $redirectParams['timestamp'] = time() + bdApi_Option::get('authorizeBypassSecs');
     $redirectParams['hash'] = bdApi_Crypt::encryptTypeOne(serialize($authorizeParams), $redirectParams['timestamp']);
     $redirect = XenForo_Link::buildPublicLink('account/authorize', null, $redirectParams);
     $viewParams = array('client' => $client, 'authorizeParams' => $authorizeParams, 'social' => $social, 'redirect' => $redirect);
     $view = $this->responseView('bdApi_ViewPublic_Account_Authorize', 'bdapi_error_authorize_guest', $viewParams);
     $view->responseCode = 403;
     return $view;
 }
Beispiel #2
0
 public function actionGetLogout()
 {
     $redirectUri = $this->_input->filterSingle('redirect_uri', XenForo_Input::STRING);
     if (empty($redirectUri)) {
         return $this->responseError(new XenForo_Phrase('bdapi_slash_tools_login_requires_redirect_uri'), 400);
     }
     /* @var $session bdApi_Session */
     $session = XenForo_Application::getSession();
     $clientId = $session->getOAuthClientId();
     if (empty($clientId)) {
         $this->_response->setHeader('X-Api-Logout-Error', 'client_id');
         return $this->responseNoPermission();
     }
     if (!$session->isValidRedirectUri($redirectUri)) {
         $this->_response->setHeader('X-Api-Logout-Error', 'redirect_uri');
         return $this->responseNoPermission();
     }
     $logoutLinkData = array('redirect' => $redirectUri, '_xfToken' => XenForo_Visitor::getInstance()->get('csrf_token_page'), 'timestamp' => XenForo_Application::$time + 10);
     $logoutLinkData['md5'] = bdApi_Crypt::encryptTypeOne(md5($logoutLinkData['redirect']), $logoutLinkData['timestamp']);
     $logoutLink = XenForo_Link::buildPublicLink('logout', '', $logoutLinkData);
     return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL_PERMANENT, $logoutLink);
 }
Beispiel #3
0
 public static function buildPublicLink($type, $data = null, array $extraParams = array(), $skipPrepend = false)
 {
     // the type MUST BE canonical:$type
     // NOTE: this is the opposite with api links
     if (strpos($type, 'full:') === 0) {
         // replace full: with canonical:
         $type = str_replace('full:', 'canonical:', $type);
     } elseif (strpos($type, 'canonical:') === false) {
         // enforce canonical:
         $type = 'canonical:' . $type;
     }
     $session = bdApi_Data_Helper_Core::safeGetSession();
     if (!empty($session)) {
         // auto appends locale param from session
         if (!isset($extraParams['locale'])) {
             $locale = $session->get('requestLocale');
             if (!empty($locale)) {
                 $timestamp = time() + 86400;
                 $extraParams['_apiLanguageId'] = sprintf('%s %s', $timestamp, bdApi_Crypt::encryptTypeOne($session->get('languageId'), $timestamp));
             }
         }
     }
     return parent::buildPublicLink($type, $data, $extraParams, $skipPrepend);
 }
Beispiel #4
0
 public function actionPostTokenGoogle()
 {
     $client = $this->_getClientOrError();
     /* @var $userExternalModel XenForo_Model_UserExternal */
     $userExternalModel = $this->getModelFromCache('XenForo_Model_UserExternal');
     $googleToken = $this->_input->filterSingle('google_token', XenForo_Input::STRING);
     $httpClient = XenForo_Helper_Http::getClient('https://www.googleapis.com/plus/v1/people/me');
     $httpClient->setParameterGet('access_token', $googleToken);
     $response = $httpClient->request('GET');
     $googleUser = json_decode($response->getBody(), true);
     if (empty($googleUser['id'])) {
         return $this->responseError(new XenForo_Phrase('bdapi_invalid_google_token'));
     }
     $googleAssoc = $userExternalModel->getExternalAuthAssociation('google', $googleUser['id']);
     if (empty($googleAssoc)) {
         $userData = array();
         if (!empty($googleUser['displayName'])) {
             $testDw = XenForo_DataWriter::create('XenForo_DataWriter_User');
             $testDw->set('username', $googleUser['displayName']);
             if (!$testDw->hasErrors()) {
                 // good username
                 $userData['username'] = $googleUser['displayName'];
             }
         }
         if (!empty($googleUser['emails'])) {
             foreach ($googleUser['emails'] as $googleEmail) {
                 $userData['user_email'] = $googleEmail['value'];
                 break;
             }
         }
         if (!empty($googleUser['birthday'])) {
             if (preg_match('#^(?<year>\\d+)-(?<month>\\d+)-(?<day>\\d+)$#', $googleUser['birthday'], $birthdayMatches)) {
                 $userData['user_dob_year'] = $birthdayMatches['year'];
                 $userData['user_dob_month'] = $birthdayMatches['month'];
                 $userData['user_dob_day'] = $birthdayMatches['day'];
             }
         }
         $extraData = array('external_provider' => 'google', 'external_provider_key' => $googleUser['id']);
         if (!empty($userData['user_email'])) {
             $extraData['user_email'] = $userData['user_email'];
         }
         $extraData = serialize($extraData);
         $extraTimestamp = time() + bdApi_Option::get('refreshTokenTTLDays') * 86400;
         $userData += array('extra_data' => bdApi_Crypt::encryptTypeOne($extraData, $extraTimestamp), 'extra_timestamp' => $extraTimestamp);
         $data = array('status' => 'ok', 'message' => new XenForo_Phrase('bdapi_no_google_association_found'), 'user_data' => $userData);
         return $this->responseData('bdApi_ViewApi_OAuth_TokenGoogle_NoAssoc', $data);
     }
     return $this->_actionPostTokenNonStandard($client, $googleAssoc['user_id']);
 }