getAuthorizeURL() public method

Get the authorize URL
public getAuthorizeURL ( $token, $sign_in_with_twitter = TRUE )
Exemplo n.º 1
0
 protected function _loginAction()
 {
     $option = $this->_getProviderOption();
     // セッションにアクセストークンがなかったらloginページに飛ぶ
     // サインインしていてもログイン状態でなければSESSIONを消す
     $pengin =& Pengin::getInstance();
     if ($pengin->cms->isUser() == false) {
         unset($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
     }
     if (isset($_SESSION['oauth_token']) == true and isset($_SESSION['oauth_token_secret']) == true) {
         if ($_SESSION['oauth_token'] === NULL && $_SESSION['oauth_token_secret'] === NULL) {
             $tokenExist = false;
         } else {
             $tokenExist = true;
         }
     } else {
         $tokenExist = false;
     }
     if ($tokenExist == false) {
         // OAuthオブジェクト生成
         $to = new TwitterOAuth($option['key'], $option['secret']);
         // callbackURLを指定してRequest tokenを取得
         $tok = $to->getRequestToken($this->connect);
         // セッションに保存
         $_SESSION['request_token'] = $token = $tok['oauth_token'];
         $_SESSION['request_token_secret'] = $tok['oauth_token_secret'];
         // サインインするためのURLを取得
         $url = $to->getAuthorizeURL($token);
         header("location:" . $url);
         die;
     } else {
         //サインインしていればヘッダーを出力
         //include("user_header.php");
     }
 }
Exemplo n.º 2
0
 function update($new_instance, $old_instance)
 {
     $instance = $old_instance;
     $tb_o = get_option('tweet-blender');
     $errors = array();
     // check to make sure we have oAuth token
     if (!$tb_o['oauth_access_token']) {
         // Create TwitterOAuth object and get request token
         $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
         // Get request token
         $request_token = $connection->getRequestToken(get_bloginfo('url') . '/' . PLUGINDIR . "/tweet-blender/lib/twitteroauth/callback.php");
         if ($connection->http_code == 200) {
             // Save request token to session
             $tb_o['oauth_token'] = $token = $request_token['oauth_token'];
             $tb_o['oauth_token_secret'] = $request_token['oauth_token_secret'];
             update_option('tweet-blender', $tb_o);
             $errors[] = __("Twitter API v1.1 requires authentication", 'tweetblender') . " <a href='javascript:tAuth(\"" . $connection->getAuthorizeURL($token) . "\")' title=" . __('Authorize Access', 'tweetblender') . ">" . __('Use your Twitter account to login', 'tweetblender') . "</a>.";
         } else {
             $errors[] = __("Twitter oAuth is not possible at this time.", 'tweetblender') . "<!--" . $connection->last_api_call . "-->";
         }
     }
     if (sizeof($errors) == 0) {
         $this->message = __('Settings saved', 'tweetblender');
         $instance['title'] = trim(strip_tags($new_instance['title']));
         $instance['widget_refresh_rate'] = $new_instance['widget_refresh_rate'];
         $instance['widget_tweets_num'] = $new_instance['widget_tweets_num'];
         return $instance;
     } else {
         if (sizeof($errors) > 0) {
             $this->error .= join(', ', $errors);
         }
         $this->bad_input = $new_instance;
         return false;
     }
 }
Exemplo n.º 3
0
 protected function authTwitter($save_name)
 {
     $config = $this->config;
     $conn = new TwitterOAuth($config['consumer_key'], $config['consumer_secret']);
     $request_token = $conn->getRequestToken();
     if ($request_token === false || $conn->lastStatusCode() != 200) {
         throw new RuntimeException("Error fetching Twitter auth token: Status code " . $conn->lastStatusCode() . '; ' . $conn->http_error);
     }
     $url = $conn->getAuthorizeURL($request_token);
     // Automatically send the user to the auth page.
     $ui = new UI();
     $ui->openBrowser($url);
     $pin = $ui->readline("Please visit {$url} then type the pin number: ");
     $conn = new TwitterOAuth($config['consumer_key'], $config['consumer_secret'], $request_token['oauth_token'], $request_token['oauth_token_secret']);
     $access_token = $conn->getAccessToken($pin);
     if ($access_token === false || $conn->lastStatusCode() != 200) {
         throw new RuntimeException("Error fetching Twitter access token: Status code " . $conn->lastStatusCode() . '; ' . $conn->http_error);
     }
     $this->config['oauth_token'] = $access_token['oauth_token'];
     $this->config['oauth_token_secret'] = $access_token['oauth_token_secret'];
     echo "Your Twitter token is " . $access_token['oauth_token'] . "\n";
     echo "Your Twitter token secret is " . $access_token['oauth_token_secret'] . "\n";
     echo "(Written to twitter-{$save_name}.txt)\n";
     if (file_put_contents("twitter-{$save_name}.txt", $access_token['oauth_token'] . "\n" . $access_token['oauth_token_secret'])) {
         return;
     }
     throw new RuntimeException("Failed to save oauth token to twitter-{$save_name}.txt");
 }
Exemplo n.º 4
0
 static function loginLink()
 {
     $connection = new TwitterOAuth(WRA_CONF::$twiappid, WRA_CONF::$twiappsecret);
     $temporary_credentials = $connection->getRequestToken(WRA_CONF::$twiauthlink);
     $redirect_url = $connection->getAuthorizeURL($temporary_credentials);
     return $redirect_url;
 }
Exemplo n.º 5
0
 /**
  * This method is used to process the first part of authentication workflow, before redirect
  *
  * @return array Array with status and redirect URI
  */
 public function getRedirectUri()
 {
     $ngConnectINI = eZINI::instance('ngconnect.ini');
     $http = eZHTTPTool::instance();
     $consumerKey = trim($ngConnectINI->variable('LoginMethod_twitter', 'AppConsumerKey'));
     $consumerSecret = trim($ngConnectINI->variable('LoginMethod_twitter', 'AppConsumerSecret'));
     if (empty($consumerKey) || empty($consumerSecret)) {
         return array('status' => 'error', 'message' => 'Consumer key or consumer secret undefined.');
     }
     $callbackUri = self::CALLBACK_URI_PART;
     $loginWindowType = trim($ngConnectINI->variable('ngconnect', 'LoginWindowType'));
     if ($loginWindowType == 'popup') {
         $callbackUri = '/layout/set/ngconnect' . self::CALLBACK_URI_PART;
     }
     $state = md5(session_id() . (string) time());
     $http->setSessionVariable('NGConnectOAuthState', $state);
     $callbackUri .= '?state=' . $state;
     eZURI::transformURI($callbackUri, false, 'full');
     $connection = new TwitterOAuth($consumerKey, $consumerSecret);
     $connection->host = self::TWITTER_API_URI;
     $tempCredentials = $connection->getRequestToken($callbackUri);
     $redirectUri = $connection->getAuthorizeURL($tempCredentials);
     if (!$redirectUri) {
         return array('status' => 'error', 'message' => 'Invalid redirection URI.');
     }
     $http->setSessionVariable('NGConnectOAuthToken', $tempCredentials['oauth_token']);
     $http->setSessionVariable('NGConnectOAuthTokenSecret', $tempCredentials['oauth_token_secret']);
     return array('status' => 'success', 'redirect_uri' => $redirectUri);
 }
Exemplo n.º 6
0
 public function requestToken($Account)
 {
     $NGPushIni = eZINI::instance('ngpush.ini');
     $ConsumerKey = $NGPushIni->variable($Account, 'ConsumerKey');
     $ConsumerSecret = $NGPushIni->variable($Account, 'ConsumerSecret');
     $AccessToken = $NGPushIni->variable($Account, 'AccessToken');
     $AccessTokenSecret = $NGPushIni->variable($Account, 'AccessTokenSecret');
     // If access tokens are given
     if ($AccessToken && $AccessTokenSecret) {
         // Save request signing tokens to cache
         ngPushBase::save_token($Account, $AccessToken, 'request_sign_oauth_token');
         ngPushBase::save_token($Account, $AccessTokenSecret, 'request_sign_oauth_token_secret');
         ngPushBase::save_token($Account, $AccessToken . '%%%' . $AccessTokenSecret, 'main_token');
     } else {
         $connection = new TwitterOAuth($ConsumerKey, $ConsumerSecret);
         $connection->host = "https://api.twitter.com/1.1/";
         $AdministrationUrl = '/';
         eZURI::transformURI($AdministrationUrl, false, 'full');
         $AdministrationUrl = base64_encode($AdministrationUrl);
         $SettingsBlock = base64_encode($Account);
         $temporary_credentials = $connection->getRequestToken('http://' . $NGPushIni->variable('PushNodeSettings', 'ConnectURL') . '/redirect.php/' . $AdministrationUrl . '/' . $SettingsBlock . '?case=twitter');
         // Save request signing tokens to cache
         ngPushBase::save_token($Account, $temporary_credentials['oauth_token'], 'request_sign_oauth_token');
         ngPushBase::save_token($Account, $temporary_credentials['oauth_token_secret'], 'request_sign_oauth_token_secret');
         $redirect_url = $connection->getAuthorizeURL($temporary_credentials, FALSE);
         self::$response['RequestPermissionsUrl'] = $redirect_url;
     }
 }
Exemplo n.º 7
0
 public static function initComment($api)
 {
     session_start();
     $options = Typecho_Widget::widget('Widget_Options');
     $config = $options->plugin('ConnectToTwitter');
     //发送请求到twitter
     if (isset($api->request->connect_to_twitter)) {
         $to = new TwitterOAuth($config->consumerKey, $config->consumerSecret);
         $tok = $to->getRequestToken();
         Typecho_Cookie::set('oauth_request_token', $tok['oauth_token']);
         Typecho_Cookie::set('oauth_request_token_secret', $tok['oauth_token_secret']);
         /* Build the authorization URL */
         $request_link = $to->getAuthorizeURL($tok['oauth_token']);
         header('Location:' . $request_link);
     }
     //从twitter返回
     if (isset($api->request->oauth_token)) {
         if (Typecho_Cookie::get('oauth_request_token') && Typecho_Cookie::get('oauth_request_token_secret')) {
             $to = new TwitterOAuth($config->consumerKey, $config->consumerSecret, Typecho_Cookie::get('oauth_request_token'), Typecho_Cookie::get('oauth_request_token_secret'));
             $tok = $to->getAccessToken();
             Typecho_Cookie::set('oauth_access_token', $tok['oauth_token'], time() + 60 * 60 * 24 * 30);
             Typecho_Cookie::set('oauth_access_token_secret', $tok['oauth_token_secret'], time() + 60 * 60 * 24 * 30);
             $info_json = $to->OAuthRequest('https://twitter.com/account/verify_credentials.json', array(), 'GET');
             $info = Typecho_Json::decode($info_json, true);
             self::twitterLogin($info, $api);
         }
     }
 }
/**
 * Method for Twitter login
 */
function ie_api_twitter_login()
{
    // Test user is logged in
    if (!iewp_api_user_is_logged_in()) {
        die('Error: please sign in');
    }
    // Twitter app credentials
    $consumer_key = trim(get_option('iewp_api_twitterapp_consumer_key', ''));
    $consumer_secret = trim(get_option('iewp_api_twitterapp_consumer_secret', ''));
    $callback_url = site_url('wp-json/ie-api/twitter-callback');
    // Test app creds have been set
    if ($consumer_key == '' || $consumer_secret == '') {
        die('Error: invalid twitter app credentials');
    }
    // Get a request token
    $connection = new TwitterOAuth($consumer_key, $consumer_secret);
    $request_token = $connection->getRequestToken($callback_url);
    // Store the request token for use in callback
    $user_id = iewp_api_id_from_hash();
    update_user_meta($user_id, 'twitter_oauth_token', $request_token['oauth_token']);
    update_user_meta($user_id, 'twitter_oauth_token_secret', $request_token['oauth_token_secret']);
    // Redirect to Twitter app approval page
    $redirect_url = $connection->getAuthorizeURL($request_token);
    wp_redirect($redirect_url);
    exit;
}
 public function authControl()
 {
     $config = Config::getInstance();
     Loader::definePathConstants();
     $this->setViewTemplate(THINKUP_WEBAPP_PATH . 'plugins/twitter/view/twitter.account.index.tpl');
     $this->view_mgr->addHelp('twitter', 'userguide/settings/plugins/twitter/index');
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     // get plugin option values if defined...
     $plugin_options = $this->getPluginOptions();
     $oauth_consumer_key = $this->getPluginOption('oauth_consumer_key');
     $oauth_consumer_secret = $this->getPluginOption('oauth_consumer_secret');
     $archive_limit = $this->getPluginOption('archive_limit');
     $num_twitter_errors = $this->getPluginOption('num_twitter_errors');
     $this->addToView('twitter_app_name', "ThinkUp " . $_SERVER['SERVER_NAME']);
     $this->addToView('thinkup_site_url', Utils::getApplicationURL(true));
     $plugin = new TwitterPlugin();
     if ($plugin->isConfigured()) {
         $this->addToView('is_configured', true);
         $owner_instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'twitter');
         $this->addToView('owner_instances', $owner_instances);
         if (isset($this->owner) && $this->owner->isMemberAtAnyLevel()) {
             if ($this->owner->isMemberLevel()) {
                 if (sizeof($owner_instances) > 0) {
                     $this->do_show_add_button = false;
                     $this->addInfoMessage("To connect another Twitter account to ThinkUp, upgrade your membership.", 'membership_cap');
                 }
             }
         }
         if (isset($_GET['oauth_token']) || $this->do_show_add_button) {
             $twitter_oauth = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret);
             /* Request tokens from twitter */
             $token_array = $twitter_oauth->getRequestToken(Utils::getApplicationURL(true) . "account/?p=twitter");
             if (isset($token_array['oauth_token']) || isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS" || getenv("MODE") == "TESTS") {
                 //testing
                 $token = $token_array['oauth_token'];
                 SessionCache::put('oauth_request_token_secret', $token_array['oauth_token_secret']);
                 if (isset($_GET['oauth_token'])) {
                     self::addAuthorizedUser($oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors);
                 }
                 if ($this->do_show_add_button) {
                     /* Build the authorization URL */
                     $oauthorize_link = $twitter_oauth->getAuthorizeURL($token);
                     $this->addToView('oauthorize_link', $oauthorize_link);
                 }
             } else {
                 //set error message here
                 $this->addErrorMessage("Unable to obtain OAuth tokens from Twitter. Please double-check the consumer key and secret " . "are correct.", "setup");
                 $oauthorize_link = '';
                 $this->addToView('is_configured', false);
             }
         }
     } else {
         $this->addInfoMessage('Please complete plugin setup to start using it.', 'setup');
         $this->addToView('is_configured', false);
     }
     // add plugin options from
     $this->addOptionForm();
     return $this->generateView();
 }
Exemplo n.º 10
0
 /**
  * Used to set temporary credentials in Session
  * Get this credentials from Twitter API library
  *
  * @access public
  * @return string
  */
 public function set_temporary_credentials()
 {
     $connection = new TwitterOAuth($this->_config['consumer_key'], $this->_config['consumer_secret']);
     $temporary_credentials = $connection->getRequestToken();
     $this->_ci->session->set_userdata('oauth_token', $temporary_credentials['oauth_token']);
     $this->_ci->session->set_userdata('oauth_token_secret', $temporary_credentials['oauth_token_secret']);
     $redirect_url = $connection->getAuthorizeURL($temporary_credentials);
     return $redirect_url;
 }
Exemplo n.º 11
0
 public function redirectToTwitter()
 {
     $connection = new \TwitterOAuth($this->client_id, $this->client_secret);
     $request_token = $connection->getRequestToken($this->callback);
     $redirect_url = $connection->getAuthorizeURL($request_token, false);
     Session::put("request_oauth_token", $request_token['oauth_token']);
     Session::put("request_oauth_token_secret", $request_token['oauth_token_secret']);
     return Redirect::to($redirect_url);
 }
 /**
  * Setup and handle the signin via the TwitterOAuth class.
  * User must be logged on, otherwise it shouldn't be allowed to even link this! 
  */
 public function signin()
 {
     if (Member::currentUserID()) {
         $siteconfig = SiteConfig::current_site_config();
         $conn = new TwitterOAuth($siteconfig->ConsumerKey, $siteconfig->ConsumerSecret);
         $temp = $conn->getRequestToken(Director::absoluteBaseURL() . 'TwitterController/callback');
         $redirURL = $conn->getAuthorizeURL($temp);
         $this->redirect($redirURL);
     }
 }
 /**
  * @return str
  */
 public function authControl()
 {
     $config = Config::getInstance();
     Loader::definePathConstants();
     $this->setViewTemplate(THINKUP_WEBAPP_PATH . 'plugins/twitterrealtime/view/twitterrealtime.account.index.tpl');
     $this->view_mgr->addHelp('twitterrealtime', 'userguide/settings/plugins/twitterrealtime');
     $id = DAOFactory::getDAO('InstanceDAO');
     $od = DAOFactory::getDAO('OwnerDAO');
     // get plugin option values if defined...
     $plugin_options = $this->getPluginOptions();
     // get oauth option values from twitter plugin.
     // @TODO -- what is the right way to do this?
     $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
     $twitter_options = $plugin_option_dao->getOptionsHash('twitter', true);
     $oauth_consumer_key = null;
     if (isset($twitter_options['oauth_consumer_key'])) {
         $oauth_consumer_key = $twitter_options['oauth_consumer_key']->option_value;
     }
     $oauth_consumer_secret = null;
     if (isset($twitter_options['oauth_consumer_secret'])) {
         $oauth_consumer_secret = $twitter_options['oauth_consumer_secret']->option_value;
     }
     // @TODO - get any other option values as necessary
     // $archive_limit = $this->getPluginOption('archive_limit');
     $auth_from_twitter = '';
     if (isset($oauth_consumer_key) && isset($oauth_consumer_secret)) {
         $to = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret);
         /* Request tokens from twitter */
         $tok = $to->getRequestToken();
         if (isset($tok['oauth_token'])) {
             $token = $tok['oauth_token'];
             $_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret'];
             /* Build the authorization URL */
             $oauthorize_link = $to->getAuthorizeURL($token);
             // create indication that auth from twitter plugin is okay
             $auth_from_twitter = "Using the Twitter Consumer key and secret as set in " . "the <a href=\"./?p=twitter\">Twitter plugin</a>.";
         } else {
             //set error message here
             $this->addErrorMessage("Unable to obtain OAuth token. Check your Twitter plugin consumer key and secret configuration.");
             $oauthorize_link = '';
         }
     } else {
         $this->addErrorMessage("Missing required settings! Please configure the Twitter plugin.");
         $oauthorize_link = '';
     }
     $owner_instances = $id->getByOwnerAndNetwork($this->owner, 'twitter');
     $this->addToView('owner_instances', $owner_instances);
     $this->addToView('oauthorize_link', $oauthorize_link);
     $this->addToView('auth_from_twitter', $auth_from_twitter);
     // add plugin options from
     $this->addOptionForm();
     $plugin = new TwitterRealtimePlugin();
     $this->addToView('is_configured', $plugin->isConfigured());
     return $this->generateView();
 }
Exemplo n.º 14
0
 public static function getAuthorizeUri($redirectUri)
 {
     list($consumerKey, $consumerSecret) = bdSocialShare_Option::getTwitterConsumerPair();
     $twitter = new TwitterOAuth($consumerKey, $consumerSecret);
     $requestToken = $twitter->getRequestToken($redirectUri);
     if (empty($requestToken['oauth_token']) or empty($requestToken['oauth_token_secret'])) {
         throw new XenForo_Exception('Twitter responded: ' . var_export($requestToken, true), false);
     }
     $oauthToken = $requestToken['oauth_token'];
     $oauthTokenSecret = $requestToken['oauth_token_secret'];
     return array($twitter->getAuthorizeURL($oauthToken), $oauthToken, $oauthTokenSecret);
 }
Exemplo n.º 15
0
 public function action_login()
 {
     $twitter = new TwitterOAuth(Kohana::$config->load('twitteroauth.consumer_key'), Kohana::$config->load('twitteroauth.consumer_secret'));
     $request_token = $twitter->getRequestToken(Kohana::$config->load('twitteroauth.oauth_callback'));
     /* Save request token to session */
     $_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
     $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
     /* If last connection fails don't display authorization link */
     if ($twitter->http_code == 200) {
         $this->request->redirect($twitter->getAuthorizeURL($token));
     }
     echo 'Could not connect to Twitter. Refresh the page or try again later.';
 }
Exemplo n.º 16
0
 public function login()
 {
     $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
     $request_token = $connection->getRequestToken(OAUTH_CALLBACK);
     $this->session->oauth_token = $token = $request_token['oauth_token'];
     $this->session->oauth_token_secret = $request_token['oauth_token_secret'];
     if (200 == $connection->http_code) {
         $url = $connection->getAuthorizeURL($token);
         $this->redirect($url);
     } else {
         $this->render->debug = 'Cannot authenticate with Twitter';
     }
 }
Exemplo n.º 17
0
 function getAuthorizeURL()
 {
     /* Create TwitterOAuth object with app key/secret */
     $to = new TwitterOAuth($this->consumer_key, $this->consumer_secret);
     /* Request tokens from twitter */
     $tok = $to->getRequestToken();
     /* Save tokens for later */
     //$_SESSION['oauth_request_token'] = $token = $tok['oauth_token'];
     //$_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret'];
     $token = $tok['oauth_token'];
     /* Build the authorization URL */
     $request_link = $to->getAuthorizeURL($token);
     return array('oauth_token' => $tok['oauth_token'], 'oauth_token_secret' => $tok['oauth_token_secret'], 'request_link' => $request_link);
 }
Exemplo n.º 18
0
 public static function requestAuthorization($user)
 {
     $culture = $user->getCulture();
     $connection = new TwitterOAuth(sfConfig::get("app_twitter_api_consumer_key_{$culture}"), sfConfig::get("app_twitter_api_consumer_secret_{$culture}"));
     $request_token = $connection->getRequestToken(sfContext::getInstance()->getController()->genUrl("sfReviewFront/sendTwitter", true));
     if ($connection->http_code == 200) {
         $twAuthUrl = $connection->getAuthorizeURL($request_token['oauth_token']);
         $user->setAttribute('oauth_token', $request_token['oauth_token'], 'vo/twitter');
         $user->setAttribute('oauth_token_secret', $request_token['oauth_token_secret'], 'vo/twitter');
         return $twAuthUrl;
     } else {
         throw new Exception('Connection failed!');
     }
 }
Exemplo n.º 19
0
 private function authorize()
 {
     $oauth = new \TwitterOAuth($this->access["key"], $this->access["secret"]);
     // vyžádáme si request token
     $requestToken = $oauth->getRequestToken();
     $sess = $this->session->getSection("twitter");
     // uložíme request token do sessions
     $sess->token = $requestToken['oauth_token'];
     $sess->secret = $requestToken['oauth_token_secret'];
     // získáme URL autentizačního serveru
     $url = $oauth->getAuthorizeURL($requestToken['oauth_token']);
     header('Location: ' . $url, TRUE, 301);
     exit;
 }
Exemplo n.º 20
0
 function oob($oauth_key, $oauth_secret, $suff = '')
 {
     $connection = new TwitterOAuth($oauth_key, $oauth_secret);
     $request_token = $connection->getRequestToken('oob');
     /* Save request token to session */
     $_SESSION['oauth_token' . $suff] = $request_token['oauth_token'];
     $_SESSION['oauth_token_secret' . $suff] = $request_token['oauth_token_secret'];
     if ($connection->http_code != 200) {
         http_error($connection->http_code);
     }
     $url = $connection->getAuthorizeURL($request_token['oauth_token'], FALSE);
     $oauth_verifier = oauth_proxy($url, $_POST['username'], $_POST['password']);
     return "&oauth_token{$suff}=" . $request_token['oauth_token'] . "&oauth_verifier{$suff}=" . $oauth_verifier;
 }
Exemplo n.º 21
0
 function login()
 {
     if ($this->uri->segment(3) == 'twitter') {
         $twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET);
         // Requesting authentication tokens, the parameter is the URL we will be redirected to
         $request_token = $twitteroauth->getRequestToken(site_url() . '/home/twitter');
         // Saving them into the session
         $this->session->set_userdata('oauth_token', $request_token['oauth_token']);
         $this->session->set_userdata('oauth_token_secret', $request_token['oauth_token_secret']);
         // If everything goes well..
         if ($twitteroauth->http_code == 200) {
             // Let's generate the URL and redirect
             $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
             redirect($url, 'refresh');
         }
     } else {
         if ($this->uri->segment(3) == 'facebook') {
             $facebook = new Facebook(array('appId' => APP_ID, 'secret' => APP_SECRET, 'cookie' => true));
             $session = $facebook->getSession();
             if (!empty($session)) {
                 //Active session, let's try getting the user id (getUser()) and user info (api->('/me'))
                 try {
                     $uid = $facebook->getUser();
                     $user = $facebook->api('/me');
                 } catch (Exception $e) {
                 }
                 if (!empty($user)) {
                     //User info ok? Let's print it (Here we will be adding the login and registering routines)
                     //print_r($user);
                     $username = $user['name'];
                     $userdata = $this->usermodel->get_user($uid, 'facebook', $username);
                     if (!empty($userdata)) {
                         $this->session->set_userdata('id', $userdata['id']);
                         $this->session->set_userdata('oauth_id', $uid);
                         $this->session->set_userdata('username', $userdata['username']);
                         $this->session->set_userdata('oauth_provider', $userdata['oauth_provider']);
                         redirect(site_url(), 'refresh');
                     }
                 }
             } else {
                 # There's no active session, let's generate one
                 $login_url = $facebook->getLoginUrl();
                 redirect($login_url, 'refresh');
             }
         } else {
             //redirect 404?
         }
     }
 }
Exemplo n.º 22
0
 /**
  * Get Twitter authendication URL
  * 
  * @return string Twitter authendication URL
  */
 public function getTwitterUrl()
 {
     require 'sociallogin/twitter/twitteroauth.php';
     require 'sociallogin/config/twconfig.php';
     $twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET);
     /**
      * Request to authendicate token, the @param string URL redirects the authorize page
      */
     $request_token = $twitteroauth->getRequestToken(Mage::getBaseUrl() . 'sociallogin/index/twitterlogin');
     if ($twitteroauth->http_code == 200) {
         $tw_oauth_token = Mage::getSingleton('customer/session')->setTwToken($request_token['oauth_token']);
         $tw_oauth_token_secret = Mage::getSingleton('customer/session')->setTwSecret($request_token['oauth_token_secret']);
         return $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
     }
 }
Exemplo n.º 23
0
 /**
  * Get URL for login
  * @param string $callbackURL
  * @return string URL login
  */
 public function getLoginUrl()
 {
     $this->twitterOAuth = new \TwitterOAuth($this->params["consumerKey"], $this->params["consumerSecret"]);
     $this->requestToken = $this->twitterOAuth->getRequestToken($this->params["callbackURL"]);
     $sessionSection = $this->session->getSection("twitter");
     $sessionSection->oauth_token = $token = $this->requestToken['oauth_token'];
     $sessionSection->oauth_token_secret = $this->requestToken['oauth_token_secret'];
     /*
             // If last connection failed don't display authorization link.
             switch ( $this->twitterOAuth->http_code ) {
                 case 200:
                     // Build authorize URL and redirect user to Twitter.
                     $url = $this->twitterOAuth->getAuthorizeURL( $this->requestToken['oauth_token'] );
                     $this->redirectUrl( $url );
                     break;
                 default:
                     // Show notification if something went wrong.
                     $this->flashMessage( 'Could not connect to Twitter.', "error" );
                     $this->redirect( "Sign:login" );
             }*/
     $loginUrl = $this->twitterOAuth->getAuthorizeURL($this->requestToken);
     // Use Sign in with Twitter
     return $loginUrl;
 }
Exemplo n.º 24
0
 public function action_twitter()
 {
     $redirect = '';
     try {
         $connection = new TwitterOAuth(arr::get($this->creds, 'key'), arr::get($this->creds, 'secret'));
         $tmp = $connection->getRequestToken('http://morningpages.net/auth/twittercallback');
         Session::instance()->set('twitter_oauth_token', arr::get($tmp, 'oauth_token', ''));
         Session::instance()->set('twitter_oauth_token_secret', arr::get($tmp, 'oauth_token_secret', ''));
         $redirect = $connection->getAuthorizeURL($tmp);
     } catch (exception $e) {
         ajax::error('Oh no! Something went wrong and we couldn\'t get a hold of Twitter! They might be too busy right now. You can either wait a bit and see if Twitter wakes up or use another way of logging in.');
         site::redirect();
     }
     site::redirect($redirect);
 }
Exemplo n.º 25
0
function handleTwitterAuthentication($state)
{
    global $session;
    /*
     * 'default': Get a request token from Twitter for new user
     * 'returned': The user has authorized the app on Twitter and been returned
     */
    switch ($state) {
        case 'returned':
            $userDetailsJSON = NULL;
            try {
                $to = new TwitterOAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $_SESSION['oauthRequestToken'], $_SESSION['oauthRequestTokenSecret']);
                $tok = $to->getAccessToken();
                $userDetails = $to->OAuthRequest('https://twitter.com/account/verify_credentials.json', array(), 'GET');
            } catch (Exception $e) {
                /*echo '01 - '.$e->getMessage();
                		debugDump();
                		exit();*/
                header("Location: logout.php");
            }
            $userDetailsJSON = json_decode($userDetails);
            $session->loggedIn = $session->createSession($userDetailsJSON->id, $tok['oauth_token'], $tok['oauth_token_secret'], $userDetailsJSON);
            if (!$session->loggedIn) {
                /*echo '02';
                		debugDump();
                		exit();*/
                header('Location: logout.php');
            }
            break;
        default:
            try {
                $to = new TwitterOAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
                $tok = $to->getRequestToken();
            } catch (Exception $e) {
                /*echo '02';
                		debugDump();
                		exit();*/
                header('Location: logout.php');
            }
            $_SESSION['oauthRequestToken'] = $token = $tok['oauth_token'];
            $_SESSION['oauthRequestTokenSecret'] = $tok['oauth_token_secret'];
            $_SESSION['oauthState'] = "start";
            $oAuthRequestLink = $to->getAuthorizeURL($token);
            include 'tmp/account/login.php';
            break;
    }
}
Exemplo n.º 26
0
 public function login()
 {
     Phalanx::loadClasses('twitteroauth');
     $connection = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
     $request_token = $connection->getRequestToken(HOST . TWITTER_REDIRECT_URI);
     $this->session->oauth_token = $token = $request_token['oauth_token'];
     $this->session->oauth_token_secret = $request_token['oauth_token_secret'];
     switch ($connection->http_code) {
         case 200:
             $url = $connection->getAuthorizeURL($token);
             header('Location: ' . $url);
             break;
         default:
             echo 'Could not connect to Twitter. Refresh the page or try again later.';
             break;
     }
 }
Exemplo n.º 27
0
 public function index()
 {
     if ($this->customer->isLogged()) {
         $this->redirect(Url::createUrl("account/account"));
     }
     if (!$this->customer->isLogged() && (!$this->config->get('social_twitter_consumer_key') || !$this->config->get('social_twitter_consumer_secret'))) {
         $this->redirect(Url::createUrl("account/login", array("error" => "No se pudo iniciar sesion utilizando Twitter, por favor intente con otro servicio")));
     }
     $this->load->library('twitter_sdk/twitteroauth');
     if ($this->session->has("oauth_token") && $this->session->has("oauth_token_secret") && $this->request->hasQuery("oauth_verifier")) {
         $twitter = new TwitterOAuth($this->config->get('social_twitter_consumer_key'), $this->config->get('social_twitter_consumer_secret'), $this->session->get("oauth_token"), $this->session->get("oauth_token_secret"));
         $access_token = $twitter->getAccessToken($this->request->getQuery("oauth_verifier"));
         $user_info = $twitter->get('account/verify_credentials');
         $data = array("oauth_id" => $user_info->id, "company" => $user_info->name, "oauth_provider" => 'twitter', "oauth_token" => $this->session->get("oauth_token"), "oauth_token_secret" => $this->session->get("oauth_token_secret"));
         $result = $this->modelCustomer->getCustomerByTwitter($data);
         if ($result) {
             if ($this->customer->loginWithTwitter($data)) {
                 if (!$result['email']) {
                     $this->redirect(Url::createUrl("account/complete_profile"));
                 } elseif ($this->session->has('redirect')) {
                     $this->redirect(str_replace('&amp;', '&', $this->session->get('redirect')));
                 } else {
                     $this->redirect(Url::createUrl("common/home"));
                 }
             } else {
                 $this->redirect(Url::createUrl("account/login", array("error" => "No se pudo iniciar sesion utilizando Twitter, por favor intente con otro servicio")));
             }
         } elseif ($this->modelCustomer->addCustomerFromTwitter($data)) {
             if ($this->customer->loginWithTwitter($data)) {
                 $this->redirect(Url::createUrl("account/complete_profile"));
             } else {
                 $this->redirect(Url::createUrl("account/login", array("error" => "No se pudo iniciar sesion utilizando Twitter, por favor intente con otro servicio")));
             }
         }
     } else {
         $twitter = new TwitterOAuth($this->config->get('social_twitter_consumer_key'), $this->config->get('social_twitter_consumer_secret'));
         $request_token = $twitter->getRequestToken(Url::createUrl("api/twitter"));
         $this->session->set("oauth_token", $request_token['oauth_token']);
         $this->session->set("oauth_token_secret", $request_token['oauth_token_secret']);
         if ($twitter->http_code == '200') {
             $this->redirect($twitter->getAuthorizeURL($request_token['oauth_token']));
         } else {
             $this->redirect(Url::createUrl("account/login", array("error" => "No se pudo iniciar sesion utilizando Twitter, por favor intente con otro servicio")));
         }
     }
 }
Exemplo n.º 28
0
 function redirectAction()
 {
     require_once APPPATH . 'models/libs/twitteroauth/twitteroauth.php';
     $connection = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
     $request_token = $connection->getRequestToken(TWITTER_OAUTH_CALLBACK);
     $session = array('oauth_token' => $token = $request_token['oauth_token'], 'oauth_token_secret' => $request_token['oauth_token_secret']);
     $this->session->set_userdata($session);
     switch ($connection->http_code) {
         case 200:
             $url = $connection->getAuthorizeURL($token);
             header('Location: ' . $url);
             break;
         default:
             echo 'Could not connect to Twitter. Refresh the page or try again later.';
     }
     exit;
 }
Exemplo n.º 29
0
 public function AuthenticateUser()
 {
     require_once 'includes/twitteroauth.php';
     $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
     $request_token = $connection->getRequestToken(OAUTH_CALLBACK);
     $_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
     $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
     switch ($connection->http_code) {
         case 200:
             $url = $connection->getAuthorizeURL($token);
             wp_redirect($url);
             exit;
             break;
         default:
             return 'Could not connect to Twitter. Refresh the page or try again later.';
     }
 }
Exemplo n.º 30
0
 public function data()
 {
     $config = new Controllers_Api_Twitter_Config_App();
     $result = array();
     if (isset($_REQUEST['oauth_token'])) {
         //Successful response returns oauth_token, oauth_token_secret, user_id, and screen_name
         $connection = new TwitterOAuth($config->config['consumer_key'], $config->config['consumer_secret'], $_SESSION['token_twitter'], $_SESSION['token_secret_twitter']);
         $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
         if ($connection->http_code == '200') {
             //Redirect user to twitter
             $result['status'] = true;
             $result['data']['oauth_token'] = $access_token['oauth_token'];
             $result['data']['oauth_token_secret'] = $access_token['oauth_token_secret'];
             $result['data']['oauth_verifier'] = $_REQUEST['oauth_verifier'];
             //Insert user into the database
             $user_info = $connection->get('account/verify_credentials');
             $result['data']['user'] = $user_info;
             $result['data']['social'] = 'twitter';
         } else {
             $result = array('status' => false, 'error' => 'error, try again later');
         }
     } else {
         if (isset($_GET["denied"])) {
             $result = array('status' => false, 'error' => 'denied');
         } else {
             //Fresh authentication
             $connection = new TwitterOAuth($config->config['consumer_key'], $config->config['consumer_secret']);
             $request_token = $connection->getRequestToken($this->config->get('domain') . 'api/twitter/callback/data');
             //Received token info from twitter
             $_SESSION['token_twitter'] = $request_token['oauth_token'];
             $_SESSION['token_secret_twitter'] = $request_token['oauth_token_secret'];
             //Any value other than 200 is failure, so continue only if http code is 200
             if ($connection->http_code == '200') {
                 //redirect user to twitter
                 $twitter_url = $connection->getAuthorizeURL($request_token['oauth_token']);
                 $result = array('status' => true, 'url' => $twitter_url, 'token' => $request_token['oauth_token'], 'token_secret' => $request_token['oauth_token_secret']);
                 header('Location: ' . $twitter_url);
             } else {
                 $result = array('status' => false, 'error' => 'error connecting to twitter! try again later!');
                 //die("error connecting to twitter! try again later!");
             }
         }
     }
     echo json_encode($result);
 }