Example #1
0
 public function getAuthorizationUrl()
 {
     $temporaryCredentials = $this->provider->getTemporaryCredentials();
     // Store the credentials in the session.
     $this->session->set(self::TEMP_CRED, serialize($temporaryCredentials));
     // Second part of OAuth 1.0 authentication is to redirect the
     // resource owner to the login screen on the server.
     return $this->provider->getAuthorizationUrl($temporaryCredentials);
 }
Example #2
0
 /**
  * Do twitter login
  *
  * @return mixed|void
  */
 public function twitterLogin()
 {
     $this->autoRender = false;
     $server = new Twitter(['identifier' => Configure::read('OAuth.providers.twitter.options.clientId'), 'secret' => Configure::read('OAuth.providers.twitter.options.clientSecret'), 'callbackUri' => Configure::read('OAuth.providers.twitter.options.redirectUri')]);
     $oauthToken = $this->request->query('oauth_token');
     $oauthVerifier = $this->request->query('oauth_verifier');
     if (!empty($oauthToken) && !empty($oauthVerifier)) {
         $temporaryCredentials = $this->request->session()->read('temporary_credentials');
         $tokenCredentials = $server->getTokenCredentials($temporaryCredentials, $oauthToken, $oauthVerifier);
         $user = (array) $server->getUserDetails($tokenCredentials);
         $user['token'] = ['accessToken' => $tokenCredentials->getIdentifier(), 'tokenSecret' => $tokenCredentials->getSecret()];
         $this->request->session()->write(Configure::read('Users.Key.Session.social'), $user);
         try {
             $user = $this->Auth->identify();
             $this->_afterIdentifyUser($user, true);
         } catch (UserNotActiveException $ex) {
             $exception = $ex;
         } catch (AccountNotActiveException $ex) {
             $exception = $ex;
         } catch (MissingEmailException $ex) {
             $exception = $ex;
         }
         if (!empty($exception)) {
             return $this->failedSocialLogin($exception, $this->request->session()->read(Configure::read('Users.Key.Session.social')), true);
         }
     } else {
         $temporaryCredentials = $server->getTemporaryCredentials();
         $this->request->session()->write('temporary_credentials', $temporaryCredentials);
         $url = $server->getAuthorizationUrl($temporaryCredentials);
         return $this->redirect($url);
     }
 }
Example #3
0
 /**
  * Get the authorize url.
  *
  * @param string|array $requestToken Request token returned by Twitter OAuth server.
  *
  * @return string
  */
 public function getAuthorizeUrl($requestToken)
 {
     return $this->instance->getAuthorizationUrl($requestToken);
 }