Ejemplo n.º 1
0
 function Finalize($success)
 {
     if ($this->opened_file) {
         fclose($this->opened_file);
         $this->opened_file = false;
     }
     return parent::Finalize($success);
 }
Ejemplo n.º 2
0
$client->debug_http = 1;
$client->server = 'Yahoo';
$client->redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . dirname(strtok($_SERVER['REQUEST_URI'], '?')) . '/login_with_yahoo.php';
$client->client_id = '';
$application_line = __LINE__;
$client->client_secret = '';
if (strlen($client->client_id) == 0 || strlen($client->client_secret) == 0) {
    die('Please go to Yahoo Apps page https://developer.apps.yahoo.com/wsregapp/ , ' . 'create an application, and in the line ' . $application_line . ' set the client_id to Consumer key and client_secret with Consumer secret. ' . 'The Callback URL must be ' . $client->redirect_uri) . ' Make sure you enable the ' . 'necessary permissions to execute the API calls your application needs.';
}
if ($success = $client->Initialize()) {
    if ($success = $client->Process()) {
        if (strlen($client->access_token)) {
            $success = $client->CallAPI('http://query.yahooapis.com/v1/yql', 'GET', array('q' => 'select * from social.profile where guid=me', 'format' => 'json'), array('FailOnAccessError' => true), $user);
        }
    }
    $success = $client->Finalize($success);
}
if ($client->exit) {
    exit;
}
if ($success) {
    ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Yahoo OAuth client results</title>
</head>
<body>
<?php 
    echo '<h1>', HtmlSpecialChars($user->query->results->profile->nickname), ' you have logged in successfully with Yahoo!</h1>';
    echo '<pre>', HtmlSpecialChars(print_r($user, 1)), '</pre>';
Ejemplo n.º 3
0
/**
 * Check querystring variables
 */
function the_champ_connect()
{
    global $theChampLoginOptions;
    // verify email
    if (isset($_GET['SuperSocializerKey']) && ($verificationKey = trim(esc_attr($_GET['SuperSocializerKey']))) != '') {
        $users = get_users('meta_key=thechamp_key&meta_value=' . $verificationKey);
        if (count($users) > 0 && isset($users[0]->ID)) {
            delete_user_meta($users[0]->ID, 'thechamp_key');
            // update password and send email
            $password = wp_generate_password();
            wp_update_user(array('ID' => $users[0]->ID, 'user_pass' => $password));
            the_champ_password_email($users[0]->ID, $password);
            wp_redirect(home_url() . '?SuperSocializerVerified=1');
            die;
        }
    }
    // Instagram auth
    if (isset($_GET['SuperSocializerInstaToken']) && $_GET['SuperSocializerInstaToken'] != '') {
        $instaAuthUrl = 'https://api.instagram.com/v1/users/self?access_token=' . trim(esc_attr($_GET['SuperSocializerInstaToken']));
        $response = wp_remote_get($instaAuthUrl, array('timeout' => 15));
        if (!is_wp_error($response) && isset($response['response']['code']) && 200 === $response['response']['code']) {
            $body = json_decode(wp_remote_retrieve_body($response));
            if (is_object($body->data) && isset($body->data) && isset($body->data->id)) {
                $redirection = isset($_GET['super_socializer_redirect_to']) && $_GET['super_socializer_redirect_to'] != '' ? esc_attr($_GET['super_socializer_redirect_to']) : '';
                $response = the_champ_user_auth($body->data, 'instagram', $redirection);
                if (is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')) {
                    $redirectTo = esc_attr(the_champ_get_login_redirection_url($redirection, true));
                } elseif (isset($response['message']) && $response['message'] == 'linked') {
                    $redirectTo = $redirection . (strpos($redirection, '?') !== false ? '&' : '?') . 'linked=1';
                } elseif (isset($response['message']) && $response['message'] == 'not linked') {
                    $redirectTo = $redirection . (strpos($redirection, '?') !== false ? '&' : '?') . 'linked=0';
                } elseif (isset($response['url']) && $response['url'] != '') {
                    $redirectTo = $response['url'];
                } else {
                    $redirectTo = esc_attr(the_champ_get_login_redirection_url($redirection));
                }
                the_champ_close_login_popup($redirectTo);
            }
        }
    }
    // send request to Xing
    if (isset($_GET['SuperSocializerAuth']) && $_GET['SuperSocializerAuth'] == 'Xing') {
        session_start();
        if (!isset($_GET['oauth_token']) && isset($_SESSION['OAUTH_ACCESS_TOKEN'])) {
            unset($_SESSION['OAUTH_ACCESS_TOKEN']);
        }
        if (isset($theChampLoginOptions['xing_ck']) && $theChampLoginOptions['xing_ck'] != '' && isset($theChampLoginOptions['xing_cs']) && $theChampLoginOptions['xing_cs'] != '') {
            $xingClient = new oauth_client_class();
            $xingClient->debug = 0;
            $xingClient->debug_http = 1;
            $xingClient->server = 'XING';
            $xingClient->redirect_uri = site_url() . '/index.php?SuperSocializerAuth=Xing&super_socializer_redirect_to=' . esc_attr(str_replace(array('http://', 'https://'), '', urldecode($_GET['super_socializer_redirect_to'])));
            $xingClient->client_id = $theChampLoginOptions['xing_ck'];
            $xingClient->client_secret = $theChampLoginOptions['xing_cs'];
            if ($success = $xingClient->Initialize()) {
                if ($success = $xingClient->Process()) {
                    if (strlen($xingClient->access_token)) {
                        $success = $xingClient->CallAPI('https://api.xing.com/v1/users/me', 'GET', array(), array('FailOnAccessError' => true), $xingResponse);
                    }
                }
                $success = $xingClient->Finalize($success);
            }
            if ($xingClient->exit) {
                die('exit');
            }
            if ($success) {
                if (isset($xingResponse->users) && is_array($xingResponse->users) && isset($xingResponse->users[0]->id)) {
                    $xingRedirect = the_champ_get_http() . esc_attr($_GET['super_socializer_redirect_to']);
                    $response = the_champ_user_auth($xingResponse->users[0], 'xing', $xingRedirect);
                    if (is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')) {
                        $redirectTo = esc_attr(the_champ_get_login_redirection_url($xingRedirect, true));
                    } elseif (isset($response['message']) && $response['message'] == 'linked') {
                        $redirectTo = $xingRedirect . (strpos($xingRedirect, '?') !== false ? '&' : '?') . 'linked=1';
                    } elseif (isset($response['message']) && $response['message'] == 'not linked') {
                        $redirectTo = $xingRedirect . (strpos($xingRedirect, '?') !== false ? '&' : '?') . 'linked=0';
                    } elseif (isset($response['url']) && $response['url'] != '') {
                        $redirectTo = $response['url'];
                    } else {
                        $redirectTo = esc_attr(the_champ_get_login_redirection_url($xingRedirect));
                    }
                    the_champ_close_login_popup($redirectTo);
                }
            } else {
                echo 'Error:' . $xingClient->error;
                die;
            }
        }
    }
    // send request to twitter
    if (isset($_GET['SuperSocializerAuth']) && $_GET['SuperSocializerAuth'] == 'Twitter') {
        if (isset($theChampLoginOptions['twitter_key']) && $theChampLoginOptions['twitter_key'] != '' && isset($theChampLoginOptions['twitter_secret']) && $theChampLoginOptions['twitter_secret'] != '') {
            /* Build TwitterOAuth object with client credentials. */
            $connection = new TwitterOAuth($theChampLoginOptions['twitter_key'], $theChampLoginOptions['twitter_secret']);
            /* Get temporary credentials. */
            $requestToken = $connection->getRequestToken(site_url() . '/index.php');
            if ($connection->http_code == 200) {
                // generate unique ID
                $uniqueId = mt_rand();
                // save oauth token and secret in db temporarily
                update_user_meta($uniqueId, 'thechamp_twitter_oauthtoken', $requestToken['oauth_token']);
                update_user_meta($uniqueId, 'thechamp_twitter_oauthtokensecret', $requestToken['oauth_token_secret']);
                if (isset($_GET['super_socializer_redirect_to']) && $_GET['super_socializer_redirect_to'] != '') {
                    update_user_meta($uniqueId, 'thechamp_twitter_redirect', esc_attr($_GET['super_socializer_redirect_to']));
                }
                wp_redirect($connection->getAuthorizeURL($requestToken['oauth_token']));
                die;
            } else {
                ?>

				<div style="width: 500px; margin: 0 auto">
					<ol>
					<li><?php 
                echo sprintf(__('Enter exactly the following url in <strong>Website</strong> and <strong>Callback Url</strong> options in your Twitter app (see step 3 %s)', 'Super-Socializer'), '<a target="_blank" href="http://support.heateor.com/how-to-get-twitter-api-key-and-secret/">here</a>');
                ?>
<br/>
					<?php 
                echo site_url();
                ?>

					</li>
					<li><?php 
                _e('Make sure cURL is enabled at your website server. You may need to contact the server administrator of your website to verify this', 'Super-Socializer');
                ?>
</li>
					</ol>
				</div>
				<?php 
                die;
            }
        }
    }
    // twitter authentication
    if (isset($_REQUEST['oauth_token'])) {
        global $wpdb;
        $uniqueId = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'thechamp_twitter_oauthtoken' and meta_value = %s", $_REQUEST['oauth_token']));
        $oauthTokenSecret = get_user_meta($uniqueId, 'thechamp_twitter_oauthtokensecret', true);
        // twitter redirect url
        $twitterRedirectUrl = get_user_meta($uniqueId, 'thechamp_twitter_redirect', true);
        if (empty($uniqueId) || $oauthTokenSecret == '') {
            // invalid request
            wp_redirect(site_url());
            die;
        }
        $connection = new TwitterOAuth($theChampLoginOptions['twitter_key'], $theChampLoginOptions['twitter_secret'], $_REQUEST['oauth_token'], $oauthTokenSecret);
        /* Request access tokens from twitter */
        $accessToken = $connection->getAccessToken($_REQUEST['oauth_verifier']);
        /* Create a TwitterOauth object with consumer/user tokens. */
        $connection = new TwitterOAuth($theChampLoginOptions['twitter_key'], $theChampLoginOptions['twitter_secret'], $accessToken['oauth_token'], $accessToken['oauth_token_secret']);
        $content = $connection->get('account/verify_credentials');
        // delete temporary data
        delete_user_meta($uniqueId, 'thechamp_twitter_oauthtokensecret');
        delete_user_meta($uniqueId, 'thechamp_twitter_oauthtoken');
        delete_user_meta($uniqueId, 'thechamp_twitter_redirect');
        if (is_object($content) && isset($content->id)) {
            $response = the_champ_user_auth($content, 'twitter', $twitterRedirectUrl);
            if (is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')) {
                $redirectTo = esc_attr(the_champ_get_login_redirection_url($twitterRedirectUrl, true));
            } elseif (isset($response['message']) && $response['message'] == 'linked') {
                $redirectTo = $twitterRedirectUrl . (strpos($twitterRedirectUrl, '?') !== false ? '&' : '?') . 'linked=1';
            } elseif (isset($response['message']) && $response['message'] == 'not linked') {
                $redirectTo = $twitterRedirectUrl . (strpos($twitterRedirectUrl, '?') !== false ? '&' : '?') . 'linked=0';
            } elseif (isset($response['url']) && $response['url'] != '') {
                $redirectTo = $response['url'];
            } else {
                $redirectTo = esc_attr(the_champ_get_login_redirection_url($twitterRedirectUrl));
            }
            the_champ_close_login_popup($redirectTo);
        }
    }
}
Ejemplo n.º 4
0
function pumpio_connect(&$a)
{
    // Start a session.  This is necessary to hold on to  a few keys the callback script will also need
    session_start();
    // Define the needed keys
    $consumer_key = get_pconfig(local_user(), 'pumpio', 'consumer_key');
    $consumer_secret = get_pconfig(local_user(), 'pumpio', 'consumer_secret');
    $hostname = get_pconfig(local_user(), 'pumpio', 'host');
    if (($consumer_key == "" or $consumer_secret == "") and $hostname != "") {
        logger("pumpio_connect: register client");
        $clientdata = pumpio_registerclient($a, $hostname);
        set_pconfig(local_user(), 'pumpio', 'consumer_key', $clientdata->client_id);
        set_pconfig(local_user(), 'pumpio', 'consumer_secret', $clientdata->client_secret);
        $consumer_key = get_pconfig(local_user(), 'pumpio', 'consumer_key');
        $consumer_secret = get_pconfig(local_user(), 'pumpio', 'consumer_secret');
        logger("pumpio_connect: ckey: " . $consumer_key . " csecrect: " . $consumer_secret, LOGGER_DEBUG);
    }
    if ($consumer_key == "" or $consumer_secret == "") {
        logger("pumpio_connect: " . sprintf("Unable to register the client at the pump.io server '%s'.", $hostname));
        $o .= sprintf(t("Unable to register the client at the pump.io server '%s'."), $hostname);
        return $o;
    }
    // The callback URL is the script that gets called after the user authenticates with pumpio
    $callback_url = $a->get_baseurl() . "/pumpio/connect";
    // Let's begin.  First we need a Request Token.  The request token is required to send the user
    // to pumpio's login page.
    // Create a new instance of the TumblrOAuth library.  For this step, all we need to give the library is our
    // Consumer Key and Consumer Secret
    $client = new oauth_client_class();
    $client->debug = 1;
    $client->server = '';
    $client->oauth_version = '1.0a';
    $client->request_token_url = 'https://' . $hostname . '/oauth/request_token';
    $client->dialog_url = 'https://' . $hostname . '/oauth/authorize';
    $client->access_token_url = 'https://' . $hostname . '/oauth/access_token';
    $client->url_parameters = false;
    $client->authorization_header = true;
    $client->redirect_uri = $callback_url;
    $client->client_id = $consumer_key;
    $client->client_secret = $consumer_secret;
    if ($success = $client->Initialize()) {
        if ($success = $client->Process()) {
            if (strlen($client->access_token)) {
                logger("pumpio_connect: otoken: " . $client->access_token . " osecrect: " . $client->access_token_secret, LOGGER_DEBUG);
                set_pconfig(local_user(), "pumpio", "oauth_token", $client->access_token);
                set_pconfig(local_user(), "pumpio", "oauth_token_secret", $client->access_token_secret);
            }
        }
        $success = $client->Finalize($success);
    }
    if ($client->exit) {
        $o = 'Could not connect to pumpio. Refresh the page or try again later.';
    }
    if ($success) {
        logger("pumpio_connect: authenticated");
        $o .= t("You are now authenticated to pumpio.");
        $o .= '<br /><a href="' . $a->get_baseurl() . '/settings/connectors">' . t("return to the connector page") . '</a>';
    } else {
        logger("pumpio_connect: could not connect");
        $o = 'Could not connect to pumpio. Refresh the page or try again later.';
    }
    return $o;
}
Ejemplo n.º 5
0
 public static function Dropbox($oTenant)
 {
     $bResult = false;
     $oUser = null;
     $bDropboxAllow = $oTenant->SocialDropboxAllow;
     $sDropboxId = $oTenant->SocialDropboxKey;
     $sDropboxSecret = $oTenant->SocialDropboxSecret;
     $sRedirectUrl = rtrim(\MailSo\Base\Http::SingletonInstance()->GetFullUrl(), '\\/ ') . '/?dropbox';
     if (!strpos($sRedirectUrl, '://localhost')) {
         $sRedirectUrl = str_replace('http:', 'https:', $sRedirectUrl);
     }
     if ($bDropboxAllow) {
         require PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/http.php';
         require PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/oauth_client.php';
         $oClient = new \oauth_client_class();
         $oClient->debug = self::$Debug;
         $oClient->debug_http = self::$Debug;
         $oClient->server = 'Dropbox2';
         $oClient->redirect_uri = $sRedirectUrl;
         $oClient->client_id = $sDropboxId;
         $application_line = __LINE__;
         $oClient->client_secret = $sDropboxSecret;
         $oClient->configuration_file = PSEVEN_APP_ROOT_PATH . 'libraries/OAuthClient/' . $oClient->configuration_file;
         if (strlen($oClient->client_id) == 0 || strlen($oClient->client_secret) == 0) {
             $bResult = false;
             exit('Please go to Dropbox Apps page https://www.dropbox.com/developers/apps , ' . 'create an application, and in the line ' . $application_line . ' set the client_id to Consumer key and client_secret with Consumer secret. ' . 'The Callback URL must be ' . $oClient->redirect_uri) . ' Make sure this URL is ' . 'not in a private network and accessible to the Dropbox site.';
         }
         if ($success = $oClient->Initialize()) {
             if ($success = $oClient->Process()) {
                 if (strlen($oClient->access_token)) {
                     $success = $oClient->CallAPI('https://api.dropbox.com/1/account/info', 'GET', array(), array('FailOnAccessError' => true), $oUser);
                 }
             }
             $success = $oClient->Finalize($success);
         }
         if ($oClient->exit) {
             $bResult = false;
             exit;
         }
         if ($success && $oUser) {
             // if you need re-ask user for permission
             //$oClient->ResetAccessToken();
             $aSocial = array('type' => 'dropbox', 'id' => $oUser->uid, 'name' => $oUser->display_name, 'email' => isset($oUser->email) ? $oUser->email : '', 'access_token' => $oClient->access_token);
             \CApi::Log('social_user_dropbox');
             \CApi::LogObject($oUser);
             $bResult = $aSocial;
         } else {
             $bResult = false;
             $oClient->ResetAccessToken();
             self::_socialError($oClient->error, 'dropbox');
         }
     }
     return $bResult;
 }
     }
 */
 if ($success = $linkedin_login_client->Initialize()) {
     if ($success = $linkedin_login_client->Process()) {
         if (strlen($linkedin_login_client->authorization_error)) {
             $linkedin_login_client->error = $linkedin_login_client->authorization_error;
             $success = false;
         } elseif (strlen($linkedin_login_client->access_token)) {
             $success = $linkedin_login_client->CallAPI('https://api.linkedin.com/v1/people/~', 'GET', array('format' => 'json'), array('FailOnAccessError' => true), $user);
             /*
              * Use this if you just want to get the LinkedIn user email address
              */
             $success = $linkedin_login_client->CallAPI('https://api.linkedin.com/v1/people/~/email-address', 'GET', array('format' => 'json'), array('FailOnAccessError' => true), $linkedin_email);
         }
     }
     $success = $linkedin_login_client->Finalize($success);
 }
 cw_log_add('linkedin_login', array($linkedin_email, $user, $success));
 if ($success) {
     //For logged in user, get details from linkedin using access token
     $linkedin_user_id = md5($linkedin_email);
     //        $linkedin_uname                = $user->firstName . ' ' . $user->lastName;
     $linkedin_user_firstname = $user->firstName;
     $linkedin_user_lastname = $user->lastName;
     cw_load('user');
     $user_data = cw_query_first("SELECT {$tables['customers']}.*\n                                    FROM {$tables['customers']} \n                                    WHERE oauth_uid='" . $linkedin_user_id . "' AND oauth_type='L'  \n                                    AND usertype='" . $current_area . "'");
     if (!empty($user_data)) {
         // login user
         if ($user_data['status'] != 'Y') {
             //error message disabled login
             cw_add_top_message(cw_get_langvar_by_name('err_account_temporary_disabled'), 'E');
 public static function service_social_login_naver()
 {
     if (isset($_GET['sym-api']) && $_GET['sym-api'] == 'service-social-login-naver') {
         update_option(WSKL_PREFIX . 'sym-api-' . $_SERVER['HTTP_CLIENT_IP'], 'service-social-login-naver');
     }
     if (isset($_GET['sym-api']) && $_GET['sym-api'] == 'service-social-login-naver' || isset($_GET['code']) && get_option(WSKL_PREFIX . 'sym-api-' . $_SERVER['HTTP_CLIENT_IP']) == 'service-social-login-naver') {
         require 'home-social-login/http.php';
         require 'home-social-login/oauth_client.php';
         $client = new oauth_client_class();
         $client->debug = FALSE;
         $client->debug_http = TRUE;
         $client->server = 'Naver';
         $client->redirect_uri = site_url() . '/index.php';
         $client->client_id = get_option(wskl_get_option_name('naver_client_id'));
         $client->client_secret = get_option(wskl_get_option_name('naver_client_secret'));
         if (strlen($client->client_id) == 0 || strlen($client->client_secret) == 0) {
             wskl_sym__alert('네이버 연동키값을 확인해 주세요.');
         }
         if ($login == 'Y') {
             unset($_SESSION['OAUTH_STATE']);
             $client->ResetAccessToken();
         }
         /* API permissions
          */
         if ($success = $client->Initialize()) {
             if ($success = $client->Process()) {
                 if (strlen($client->access_token)) {
                     $success = $client->CallAPI('https://apis.naver.com/nidlogin/nid/getUserProfile.xml', 'POST', array('mode' => 'userinfo'), array('FailOnAccessError' => TRUE), $user);
                 }
             }
             $success = $client->Finalize($success);
         }
         if ($client->exit) {
             exit;
         }
         if ($success) {
             $xml = simplexml_load_string($user);
             if ($xml->result->resultcode == '00') {
                 $client->GetAccessToken($AccessToken);
                 $mb_gubun = 'naver';
                 $mb_id = $xml->response->enc_id;
                 $mb_name = $xml->response->nickname;
                 $mb_nick = $xml->response->nickname;
                 $mb_email = $xml->response->email;
                 $token_value = $AccessToken['value'];
                 $token_refresh = $AccessToken['refresh'];
                 $token_secret = '';
                 //$client->ResetAccessToken();
                 if (!trim($mb_id) || !trim($token_value)) {
                     wskl_sym__alert("정보가 제대로 넘어오지 않아 오류가 발생했습니다.");
                 }
                 $token_array = urlencode(static::encryptIt($mb_gubun . '|' . substr(str_replace('|', '', $mb_id), 0, 18) . '|' . $mb_name . '|' . $mb_nick . '|' . $mb_email));
                 $redirect_url = '/?sym-api=process-social-login&token=' . $token_array;
                 wp_redirect($redirect_url);
                 exit;
             } else {
                 $error = htmlspecialchars($xml->result->resultcode);
                 alert_close($error);
             }
         } else {
             $error = htmlspecialchars($client->error);
             alert_close($error);
         }
     }
 }
Ejemplo n.º 8
0
function pumpio_connect($a)
{
    // Define the needed keys
    $consumer_key = get_pconfig(local_channel(), 'pumpio', 'consumer_key');
    $consumer_secret = get_pconfig(local_channel(), 'pumpio', 'consumer_secret');
    $hostname = get_pconfig(local_channel(), 'pumpio', 'host');
    if (($consumer_key == "" || $consumer_secret == "") && $hostname != "") {
        $clientdata = pumpio_registerclient($a, $hostname);
        set_pconfig(local_channel(), 'pumpio', 'consumer_key', $clientdata['client_id']);
        set_pconfig(local_channel(), 'pumpio', 'consumer_secret', $clientdata['client_secret']);
        $consumer_key = get_pconfig(local_channel(), 'pumpio', 'consumer_key');
        $consumer_secret = get_pconfig(local_channel(), 'pumpio', 'consumer_secret');
    }
    if ($consumer_key == "" || $consumer_secret == "") {
        return;
    }
    // The callback URL is the script that gets called after the user authenticates with pumpio
    $callback_url = z_root() . '/pumpio/connect';
    // Let's begin.  First we need a Request Token.  The request token is required to send the user
    // to pumpio's login page.
    // Create a new instance of the TumblrOAuth library.  For this step, all we need to give the library is our
    // Consumer Key and Consumer Secret
    $client = new oauth_client_class();
    $client->debug = 1;
    $client->server = '';
    $client->oauth_version = '1.0a';
    $client->request_token_url = 'https://' . $hostname . '/oauth/request_token';
    $client->dialog_url = 'https://' . $hostname . '/oauth/authorize';
    $client->access_token_url = 'https://' . $hostname . '/oauth/access_token';
    $client->url_parameters = false;
    $client->authorization_header = true;
    $client->redirect_uri = $callback_url;
    $client->client_id = $consumer_key;
    $client->client_secret = $consumer_secret;
    if ($success = $client->Initialize()) {
        if ($success = $client->Process()) {
            if (strlen($client->access_token)) {
                set_pconfig(local_channel(), "pumpio", "oauth_token", $client->access_token);
                set_pconfig(local_channel(), "pumpio", "oauth_token_secret", $client->access_token_secret);
            }
        }
        $success = $client->Finalize($success);
    }
    if ($client->exit) {
        $o = 'Could not connect to pumpio. Refresh the page or try again later.';
    }
    if ($success) {
        $o .= t('You are now authenticated to pumpio.');
        $o .= '<br /><a href="' . z_root() . '/settings/featured">' . t('return to the featured settings page') . '</a>';
    }
    return $o;
}
Ejemplo n.º 9
0
 function linkedin()
 {
     require APPPATH . "libraries/linkedin/http.php";
     require APPPATH . "libraries/linkedin/oauth_client.php";
     $client = new oauth_client_class();
     $client->server = 'LinkedIn';
     $client->redirect_uri = site_url('social/linkedin');
     $client->client_id = LINKEDIN_CLIENT_ID;
     $application_line = __LINE__;
     $client->client_secret = LINKEDIN_CLIENT_SECRET;
     if (strlen($client->client_id) == 0 || strlen($client->client_secret) == 0) {
         die('Please go to LinkedIn Apps page https://www.linkedin.com/secure/developer?newapp= , ' . 'create an application, and in the line ' . $application_line . ' set the client_id to Consumer key and client_secret with Consumer secret. ' . 'The Callback URL must be ' . $client->redirect_uri) . ' Make sure you enable the ' . 'necessary permissions to execute the API calls your application needs.';
     }
     if ($success = $client->Initialize()) {
         if ($success = $client->Process()) {
             if (strlen($client->access_token)) {
                 $success = $client->CallAPI('https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,public-profile-url,headline,location,industry,summary,picture-url,positions,phone-numbers,primary-twitter-account)', 'GET', array('format' => 'json'), array('FailOnAccessError' => true), $lUser);
             }
         }
         $success = $client->Finalize($success);
     }
     if (strlen($client->authorization_error)) {
         $client->error = $client->authorization_error;
         $success = false;
     }
     if ($client->exit) {
         exit;
     }
     if ($success) {
         $linkedinUser = json_decode(json_encode($lUser), true);
         if (!empty($linkedinUser)) {
             $exists = $this->User_model->check_email($linkedinUser['emailAddress']);
             if ($exists['rc']) {
                 // user exists and login him/her to the system
                 $user_id = $exists['data']['id'];
                 if ($exists['data']['gravatar_url'] == "") {
                     if (isset($linkedinUser['pictureUrl'])) {
                         $default = base_url() . "resources/images/avatar.jpg";
                         $size = 40;
                         $grav_url = "http://www.gravatar.com/avatar/" . md5(strtolower(trim($linkedinUser['emailAddress']))) . "?d=" . urlencode($default) . "&s=" . $size;
                         $user_data = array('updated_on' => time(), 'gravatar_url' => isset($grav_url) ? $grav_url : "");
                         $response = $this->User_model->update_gravatar_url($user_data, $user_id);
                         $dir = FCPATH . "uploads/profile_images/" . $user_id . "/";
                         if ($exists['data']['profile_image'] == "" || !file_exists($dir . $exists['data']['profile_image'])) {
                             $url = $linkedinUser['pictureUrl'];
                             $this->add_picture($user_id, $url, 'linkedin.jpg');
                         }
                     }
                 }
                 $user_data = array('user_id' => $user_id, 'email' => $exists['data']['email']);
                 $result = $this->set_login_session_data($user_data);
                 if ($this->session->userdata("user_id")) {
                     redirect("user/dashboard");
                     exit;
                 }
             } else {
                 // register the user in the system and log him/her in
                 if (isset($linkedinUser['pictureUrl'])) {
                     $default = base_url() . "resources/images/avatar.jpg";
                     $size = 40;
                     $email = trim($linkedinUser['emailAddress']);
                     // "*****@*****.**"
                     $email = strtolower($email);
                     // "*****@*****.**"
                     $email = md5($email);
                     $grav_url = "http://www.gravatar.com/avatar/" . $email . "";
                 }
                 $hash = md5(microtime() . rand());
                 $user_data = array('name' => $linkedinUser['firstName'] . " " . $linkedinUser['lastName'], 'email' => $linkedinUser['emailAddress'], 'created_on' => time(), 'gravatar_url' => isset($grav_url) ? $grav_url : "", 'account_type' => LINKEDIN_ACCOUNT, "password" => $hash);
                 $response = $this->User_model->add_user_from_social_login($user_data);
                 $session_data["user_id"] = $response["data"];
                 $session_data["email"] = $user_data["email"];
                 $url = $linkedinUser['pictureUrl'];
                 $result_add_pic = $this->add_picture($response["data"], $url, 'linkedin.jpg');
                 $result = $this->set_login_session_data($session_data);
                 if ($this->session->userdata("user_id")) {
                     redirect("user/dashboard");
                     exit;
                 }
             }
         } else {
             $this->session->set_flashdata('error_message', 'Authentication error occured! Please try again.');
             redirect('login');
         }
     } else {
         $this->session->set_flashdata('error_message', 'Authentication error occured! Please try again.');
         redirect('login');
     }
 }
Ejemplo n.º 10
0
/**
 * Check querystring variables
 */
function the_champ_connect()
{
    global $theChampLoginOptions;
    // verify email
    if (isset($_GET['SuperSocializerKey']) && ($verificationKey = trim(esc_attr($_GET['SuperSocializerKey']))) != '') {
        $users = get_users('meta_key=thechamp_key&meta_value=' . $verificationKey);
        if (count($users) > 0 && isset($users[0]->ID)) {
            delete_user_meta($users[0]->ID, 'thechamp_key');
            // update password
            $password = wp_generate_password();
            wp_update_user(array('ID' => $users[0]->ID, 'user_pass' => $password));
            // send notification email
            heateor_ss_new_user_notification($users[0]->ID);
            wp_redirect(home_url() . '?SuperSocializerVerified=1');
            die;
        }
    }
    // Instagram auth
    if (isset($_GET['SuperSocializerInstaToken']) && $_GET['SuperSocializerInstaToken'] != '') {
        $instaAuthUrl = 'https://api.instagram.com/v1/users/self?access_token=' . trim(esc_attr($_GET['SuperSocializerInstaToken']));
        $response = wp_remote_get($instaAuthUrl, array('timeout' => 15));
        if (!is_wp_error($response) && isset($response['response']['code']) && 200 === $response['response']['code']) {
            $body = json_decode(wp_remote_retrieve_body($response));
            if (is_object($body->data) && isset($body->data) && isset($body->data->id)) {
                $redirection = isset($_GET['super_socializer_redirect_to']) && $_GET['super_socializer_redirect_to'] != '' ? esc_attr($_GET['super_socializer_redirect_to']) : '';
                $response = the_champ_user_auth($body->data, 'instagram', $redirection);
                if (is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')) {
                    $redirectTo = esc_attr(the_champ_get_login_redirection_url($redirection, true));
                } elseif (isset($response['message']) && $response['message'] == 'linked') {
                    $redirectTo = $redirection . (strpos($redirection, '?') !== false ? '&' : '?') . 'linked=1';
                } elseif (isset($response['message']) && $response['message'] == 'not linked') {
                    $redirectTo = $redirection . (strpos($redirection, '?') !== false ? '&' : '?') . 'linked=0';
                } elseif (isset($response['url']) && $response['url'] != '') {
                    $redirectTo = $response['url'];
                } else {
                    $redirectTo = esc_attr(the_champ_get_login_redirection_url($redirection));
                }
                the_champ_close_login_popup($redirectTo);
            }
        }
    }
    // Twitch auth
    if (isset($_GET['SuperSocializerAuth']) && $_GET['SuperSocializerAuth'] == 'Twitch') {
        if (isset($_GET['SuperSocializerData'])) {
            $body = explode('&&', urldecode($_GET['SuperSocializerData']));
            $profileData = array();
            foreach ($body as $dataField) {
                $keyValue = explode('=', $dataField);
                $profileData[$keyValue[0]] = $keyValue[1];
            }
            if (isset($profileData['_id']) && $profileData['_id'] != '') {
                $redirection = isset($_GET['super_socializer_redirect_to']) && $_GET['super_socializer_redirect_to'] != '' ? esc_attr($_GET['super_socializer_redirect_to']) : '';
                $response = the_champ_user_auth($profileData, 'twitch', $redirection);
                if (is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')) {
                    $redirectTo = esc_attr(the_champ_get_login_redirection_url($redirection, true));
                } elseif (isset($response['message']) && $response['message'] == 'linked') {
                    $redirectTo = $redirection . (strpos($redirection, '?') !== false ? '&' : '?') . 'linked=1';
                } elseif (isset($response['message']) && $response['message'] == 'not linked') {
                    $redirectTo = $redirection . (strpos($redirection, '?') !== false ? '&' : '?') . 'linked=0';
                } elseif (isset($response['url']) && $response['url'] != '') {
                    $redirectTo = $response['url'];
                } else {
                    $redirectTo = esc_attr(the_champ_get_login_redirection_url($redirection));
                }
                the_champ_close_login_popup($redirectTo);
            }
        } elseif (isset($theChampLoginOptions['twitch_client_id']) && $theChampLoginOptions['twitch_client_id'] != '') {
            ?>
			<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
	  		<script src="https://ttv-api.s3.amazonaws.com/twitch.min.js"></script>
	  		<script>
	  			theChampSerialize = function(obj, prefix) {
				  var str = [];
				  for(var p in obj) {
				    if (obj.hasOwnProperty(p)) {
				      var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
				      str.push(typeof v == "object" ?
				        theChampSerialize(v, k) :
				        encodeURIComponent(k) + "=" + encodeURIComponent(v));
				    }
				  }
				  return str.join("&&");
				}
			    jQuery(function(){
			      Twitch.init({clientId: '<?php 
            echo $theChampLoginOptions['twitch_client_id'];
            ?>
'}, function(error, status) {
			        // the sdk is now loaded
			        console.log(error);
			        console.log(status);
			        if( !status.authenticated ){
				        Twitch.login({
					        scope: ['user_read', 'channel_read']
					      });
			    	} else {
			    		Twitch.api({method: 'user'}, function(error, user) {
			              if(user._id && user._id != null){
			              	window.opener.theChampAjaxUserAuth(user, 'twitch');
			              	window.opener.location.href = '<?php 
            echo site_url();
            ?>
?SuperSocializerAuth=Twitch&super_socializer_redirect_to='+window.opener.theChampTwitterRedirect+'&SuperSocializerData=' + encodeURIComponent(theChampSerialize(user));
			              	window.close();
			              }
			            });
			    	}
			      });
			    });
			</script> 
			<?php 
        }
        die;
    }
    // Steam auth
    if (isset($_GET['SuperSocializerSteamAuth']) && $_GET['SuperSocializerSteamAuth'] != '') {
        global $theChampSteamLogin;
        $theChampSteamId = $theChampSteamLogin->validate();
        $result = wp_remote_get("http://steamcommunity.com/profiles/{$theChampSteamId}/?xml=1", array('timeout' => 15));
        if (!is_wp_error($result) && isset($result['response']['code']) && 200 === $result['response']['code']) {
            $body = wp_remote_retrieve_body($result);
            $xml = simplexml_load_string($body, null, LIBXML_NOCDATA);
            if ($xml && isset($xml->steamID64) && $xml->steamID64) {
                $steamRedirect = esc_url($_GET['SuperSocializerSteamAuth']);
                $response = the_champ_user_auth($xml, 'steam', $steamRedirect);
                if (is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')) {
                    $redirectTo = esc_attr(the_champ_get_login_redirection_url($steamRedirect, true));
                } elseif (isset($response['message']) && $response['message'] == 'linked') {
                    $redirectTo = $steamRedirect . (strpos($steamRedirect, '?') !== false ? '&' : '?') . 'linked=1';
                } elseif (isset($response['message']) && $response['message'] == 'not linked') {
                    $redirectTo = $steamRedirect . (strpos($steamRedirect, '?') !== false ? '&' : '?') . 'linked=0';
                } elseif (isset($response['url']) && $response['url'] != '') {
                    $redirectTo = $response['url'];
                } else {
                    $redirectTo = esc_attr(the_champ_get_login_redirection_url($steamRedirect));
                }
                the_champ_close_login_popup($redirectTo);
            }
        }
        die;
    }
    // send request to Xing
    if (isset($_GET['SuperSocializerAuth']) && $_GET['SuperSocializerAuth'] == 'Xing') {
        session_start();
        if (!isset($_GET['oauth_token']) && isset($_SESSION['OAUTH_ACCESS_TOKEN'])) {
            unset($_SESSION['OAUTH_ACCESS_TOKEN']);
        }
        if (isset($theChampLoginOptions['xing_ck']) && $theChampLoginOptions['xing_ck'] != '' && isset($theChampLoginOptions['xing_cs']) && $theChampLoginOptions['xing_cs'] != '') {
            $xingClient = new oauth_client_class();
            $xingClient->debug = 0;
            $xingClient->debug_http = 1;
            $xingClient->server = 'XING';
            $xingClient->redirect_uri = site_url() . '/index.php?SuperSocializerAuth=Xing&super_socializer_redirect_to=' . esc_attr(str_replace(array('http://', 'https://'), '', urldecode($_GET['super_socializer_redirect_to'])));
            $xingClient->client_id = $theChampLoginOptions['xing_ck'];
            $xingClient->client_secret = $theChampLoginOptions['xing_cs'];
            if ($success = $xingClient->Initialize()) {
                if ($success = $xingClient->Process()) {
                    if (strlen($xingClient->access_token)) {
                        $success = $xingClient->CallAPI('https://api.xing.com/v1/users/me', 'GET', array(), array('FailOnAccessError' => true), $xingResponse);
                    }
                }
                $success = $xingClient->Finalize($success);
            }
            if ($xingClient->exit) {
                die('exit');
            }
            if ($success) {
                if (isset($xingResponse->users) && is_array($xingResponse->users) && isset($xingResponse->users[0]->id)) {
                    $xingRedirect = the_champ_get_http() . esc_attr($_GET['super_socializer_redirect_to']);
                    $response = the_champ_user_auth($xingResponse->users[0], 'xing', $xingRedirect);
                    if (is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')) {
                        $redirectTo = esc_attr(the_champ_get_login_redirection_url($xingRedirect, true));
                    } elseif (isset($response['message']) && $response['message'] == 'linked') {
                        $redirectTo = $xingRedirect . (strpos($xingRedirect, '?') !== false ? '&' : '?') . 'linked=1';
                    } elseif (isset($response['message']) && $response['message'] == 'not linked') {
                        $redirectTo = $xingRedirect . (strpos($xingRedirect, '?') !== false ? '&' : '?') . 'linked=0';
                    } elseif (isset($response['url']) && $response['url'] != '') {
                        $redirectTo = $response['url'];
                    } else {
                        $redirectTo = esc_attr(the_champ_get_login_redirection_url($xingRedirect));
                    }
                    the_champ_close_login_popup($redirectTo);
                }
            } else {
                echo 'Error:' . $xingClient->error;
                die;
            }
        }
    }
    // send request to twitter
    if (isset($_GET['SuperSocializerAuth']) && $_GET['SuperSocializerAuth'] == 'Twitter') {
        if (isset($theChampLoginOptions['twitter_key']) && $theChampLoginOptions['twitter_key'] != '' && isset($theChampLoginOptions['twitter_secret']) && $theChampLoginOptions['twitter_secret'] != '') {
            /* Build TwitterOAuth object with client credentials. */
            $connection = new TwitterOAuth($theChampLoginOptions['twitter_key'], $theChampLoginOptions['twitter_secret']);
            /* Get temporary credentials. */
            $requestToken = $connection->getRequestToken(site_url() . '/index.php');
            if ($connection->http_code == 200) {
                // generate unique ID
                $uniqueId = mt_rand();
                // save oauth token and secret in db temporarily
                update_user_meta($uniqueId, 'thechamp_twitter_oauthtoken', $requestToken['oauth_token']);
                update_user_meta($uniqueId, 'thechamp_twitter_oauthtokensecret', $requestToken['oauth_token_secret']);
                if (isset($_GET['super_socializer_redirect_to']) && $_GET['super_socializer_redirect_to'] != '') {
                    update_user_meta($uniqueId, 'thechamp_twitter_redirect', esc_attr($_GET['super_socializer_redirect_to']));
                }
                wp_redirect($connection->getAuthorizeURL($requestToken['oauth_token']));
                die;
            } else {
                ?>
				<div style="width: 500px; margin: 0 auto">
					<ol>
					<li><?php 
                echo sprintf(__('Enter exactly the following url in <strong>Website</strong> and <strong>Callback Url</strong> options in your Twitter app (see step 3 %s)', 'Super-Socializer'), '<a target="_blank" href="http://support.heateor.com/how-to-get-twitter-api-key-and-secret/">here</a>');
                ?>
<br/>
					<?php 
                echo site_url();
                ?>
					</li>
					<li><?php 
                _e('Make sure cURL is enabled at your website server. You may need to contact the server administrator of your website to verify this', 'Super-Socializer');
                ?>
</li>
					</ol>
				</div>
				<?php 
                die;
            }
        }
    }
    // twitter authentication
    if (isset($_REQUEST['oauth_token'])) {
        global $wpdb;
        $uniqueId = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'thechamp_twitter_oauthtoken' and meta_value = %s", $_REQUEST['oauth_token']));
        $oauthTokenSecret = get_user_meta($uniqueId, 'thechamp_twitter_oauthtokensecret', true);
        // twitter redirect url
        $twitterRedirectUrl = get_user_meta($uniqueId, 'thechamp_twitter_redirect', true);
        if (empty($uniqueId) || $oauthTokenSecret == '') {
            // invalid request
            wp_redirect(site_url());
            die;
        }
        $connection = new TwitterOAuth($theChampLoginOptions['twitter_key'], $theChampLoginOptions['twitter_secret'], $_REQUEST['oauth_token'], $oauthTokenSecret);
        /* Request access tokens from twitter */
        $accessToken = $connection->getAccessToken($_REQUEST['oauth_verifier']);
        /* Create a TwitterOauth object with consumer/user tokens. */
        $connection = new TwitterOAuth($theChampLoginOptions['twitter_key'], $theChampLoginOptions['twitter_secret'], $accessToken['oauth_token'], $accessToken['oauth_token_secret']);
        $content = $connection->get('account/verify_credentials');
        // delete temporary data
        delete_user_meta($uniqueId, 'thechamp_twitter_oauthtokensecret');
        delete_user_meta($uniqueId, 'thechamp_twitter_oauthtoken');
        delete_user_meta($uniqueId, 'thechamp_twitter_redirect');
        if (is_object($content) && isset($content->id)) {
            $response = the_champ_user_auth($content, 'twitter', $twitterRedirectUrl);
            if (is_array($response) && isset($response['message']) && $response['message'] == 'register' && (!isset($response['url']) || $response['url'] == '')) {
                $redirectTo = esc_attr(the_champ_get_login_redirection_url($twitterRedirectUrl, true));
            } elseif (isset($response['message']) && $response['message'] == 'linked') {
                $redirectTo = $twitterRedirectUrl . (strpos($twitterRedirectUrl, '?') !== false ? '&' : '?') . 'linked=1';
            } elseif (isset($response['message']) && $response['message'] == 'not linked') {
                $redirectTo = $twitterRedirectUrl . (strpos($twitterRedirectUrl, '?') !== false ? '&' : '?') . 'linked=0';
            } elseif (isset($response['url']) && $response['url'] != '') {
                $redirectTo = $response['url'];
            } else {
                $redirectTo = esc_attr(the_champ_get_login_redirection_url($twitterRedirectUrl));
            }
            the_champ_close_login_popup($redirectTo);
        }
    }
}
 $mslive_login_client->redirect_uri = $mslive_redirect_url;
 $mslive_login_client->client_id = $config['mslive_login']['mslive_login_consumer_key'];
 $application_line = __LINE__;
 $mslive_login_client->client_secret = $config['mslive_login']['mslive_login_consumer_secret'];
 $mslive_login_info =& cw_session_register('mslive_login_info');
 $mslive_login_client->scope = 'wl.basic wl.emails wl.birthday';
 if ($success = $mslive_login_client->Initialize()) {
     if ($success = $mslive_login_client->Process()) {
         if (strlen($mslive_login_client->authorization_error)) {
             $mslive_login_client->error = $mslive_login_client->authorization_error;
             $success = false;
         } elseif (strlen($mslive_login_client->access_token)) {
             $success = $mslive_login_client->CallAPI('https://apis.live.net/v5.0/me', 'GET', array(), array('FailOnAccessError' => true), $user);
         }
     }
     $success = $mslive_login_client->Finalize($success);
 }
 if ($success) {
     //For logged in user, get details from mslive using access token
     $mslive_user_id = $user->id;
     $mslive_uname = $user->name;
     $mslive_user_firstname = $user->first_name;
     $mslive_user_lastname = $user->last_name;
     if (empty($mslive_user_firstname) && empty($mslive_user_lastname)) {
         $mslive_user_names = explode(' ', $mslive_uname);
         $mslive_user_firstname = $mslive_user_names[0];
         $mslive_user_lastname = $mslive_user_names[1];
     }
     $mslive_email = $user->emails->account;
     if (empty($mslive_email)) {
         $mslive_email = $user->emails->preferred;