public function callbackAction() { $oauth_token = $this->getRequest()->getParam('oauth_token'); $oauth_verifier = $this->getRequest()->getParam('oauth_verifier'); if (!$oauth_token || !$oauth_verifier) { return $this->_redirectUrl(); } if ($oauth_token != Mage::getSingleton('core/session')->getData('oauth_token')) { return $this->_redirectUrl(); } $connection = new LinkedInOAuth(Mage::getStoreConfig('gomage_social/linkedin/id'), Mage::getStoreConfig('gomage_social/linkedin/secret'), Mage::getSingleton('core/session')->getData('oauth_token'), Mage::getSingleton('core/session')->getData('oauth_token_secret')); $access_token = $connection->getAccessToken($oauth_verifier); Mage::getSingleton('core/session')->unsetData('oauth_token'); Mage::getSingleton('core/session')->unsetData('oauth_token_secret'); $profile = null; switch ($connection->http_code) { case 200: $profile = $connection->get('v1/people/~:(id,first-name,last-name,email-address)', array('format' => 'json')); break; default: $this->getSession()->addError($this->__('Could not connect to LinkedIn. Refresh the page or try again later.')); return $this->_redirectUrl(); } if ($profile) { $social_collection = Mage::getModel('gomage_social/entity')->getCollection()->addFieldToFilter('social_id', $profile->id)->addFieldToFilter('type_id', GoMage_Social_Model_Type::LINKEDIN); if (Mage::getSingleton('customer/config_share')->isWebsiteScope()) { $social_collection->addFieldToFilter('website_id', Mage::app()->getWebsite()->getId()); } $social = $social_collection->getFirstItem(); $customer = null; if ($social && $social->getId()) { $customer = Mage::getModel('customer/customer'); if (Mage::getSingleton('customer/config_share')->isWebsiteScope()) { $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); } $customer->load($social->getData('customer_id')); } if ($customer && $customer->getId()) { $this->getSession()->loginById($customer->getId()); } else { $customer = Mage::getModel('customer/customer'); if (Mage::getSingleton('customer/config_share')->isWebsiteScope()) { $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); } $profile->email = $profile->emailAddress; $profile->first_name = $profile->firstName; $profile->last_name = $profile->lastName; $customer->loadByEmail($profile->email); if (!$customer->getId()) { $customer = $this->createCustomer($profile); } if ($customer && $customer->getId()) { $this->createSocial($profile->id, $customer->getId()); $this->getSession()->loginById($customer->getId()); } } } return $this->_redirectUrl(); }
private static function getFollowersLinkedin($params) { if (!class_exists('LinkedInOAuth')) { require_once dirname(__FILE__) . '/LinkedInOAuth.php'; } $api_config = array('appKey' => $params->get('api_key'), 'appSecret' => $params->get('api_secret'), 'callbackUrl' => NULL); $token_config = array('oauth_token' => $params->get('oauth_token'), 'oauth_token_secret' => $params->get('oauth_token_secret')); $linkedin = new LinkedInOAuth($api_config); $linkedin->setToken($token_config); $page_id = $params->get('linkedin_pageid'); $response = $linkedin->getFollowersCount($page_id); $followers_count = 0; if ($response['success']) { $_xml = isset($response['linkedin']) ? $response['linkedin'] : ''; if ($_xml != false && $_xml != '') { $_array = $linkedin->xmlToArray($_xml); $followers_count = isset($_array['company']['children']['num-followers']['content']) ? $_array['company']['children']['num-followers']['content'] : 0; } } return $followers_count; }
public function handle_linkedin_authorization() { session_start(); global $xoouserultra; //require_once(ABSPATH . 'wp-includes/pluggable.php'); require_once xoousers_path . "libs/linkedin/oauth/linkedinoauth.php"; //get oauttokens $temp_user_session_id = session_id(); $oauthstate = get_option('uultra_linkedin_' . $temp_user_session_id); //get access token and access token secret $oauthstate = $xoouserultra->get_linkedin_access_token($oauthstate); if (!$oauthstate) { echo "empty "; } else { // We've been given some access tokens, so try and use them to make an API call, and // display the results. $accesstoken = $oauthstate['access_token']; $accesstokensecret = $oauthstate['access_token_secret']; //print_r($oauthstate); $to = new LinkedInOAuth($xoouserultra->get_option('social_media_linkedin_api_public'), $xoouserultra->get_option('social_media_linkedin_api_private'), $accesstoken, $accesstokensecret); $find_person = ':(first-name,last-name,email-address)'; $profile_result = $to->oAuthRequest('http://api.linkedin.com/v1/people/~' . $find_person); $profile_data = simplexml_load_string($profile_result); $profile_data = json_decode(json_encode($profile_data), 1); $u_name = $profile_data["first-name"]; $lname = $profile_data["last-name"]; $u_email = $profile_data["email-address"]; $u_user = $u_name . "-" . $lname; //Sanitize Login $user_login = str_replace('.', '-', $u_user); $user_login = sanitize_user($user_login, true); //check if exists //check if already registered $exists = email_exists($u_email); if (!$exists) { //generat3 random password $user_pass = wp_generate_password(12, false); //Build user data $user_data = array('user_login' => $user_login, 'display_name' => !empty($u_name) ? $u_name : $u_user, 'user_email' => $u_email, 'user_pass' => $user_pass); // Create a new user $user_id = wp_insert_user($user_data); if (!$user_id) { } else { $verify_key = $this->get_unique_verify_account_id(); update_user_meta($user_id, 'xoouser_ultra_very_key', $verify_key); update_user_meta($user_id, 'xoouser_ultra_social_signup', 2); update_user_meta($user_id, 'first_name', $u_name); update_user_meta($user_id, 'last_name', $lname); //set account status $this->user_account_status($user_id); //notify depending on status $this->user_account_notify($user_id, $u_email, $user_login, $user_pass); } } else { //if user already created then try to login automatically $users = get_users(array('meta_key' => 'xoouser_linked_in_id', 'meta_value' => $u_linked_in_id, 'meta_compare' => '=')); if (isset($users[0]->ID) && is_numeric($users[0]->ID)) { $returning = $users[0]->ID; $user_login = $users[0]->user_login; $user = get_user_by('login', $user_login); $user_id = $user->ID; } else { //get by using email, we already know the user exists at this point $user = get_user_by('email', $u_email); $user_id = $user->ID; update_user_meta($user_id, 'xoouser_ultra_social_signup', 2); update_user_meta($user_id, 'xoouser_linked_in_id', $u_linked_in_id); //set account status $this->user_account_status($user_id); $returning = ''; } if ($this->is_active($user_id)) { //is active then login wp_set_auth_cookie($user_id, true, $secure); } else { $this->errors[] = __('<strong>ERROR:</strong> YOUR ACCOUNT IS NOT ACTIVE YET.', 'xoousers'); } } //redirect $this->login_registration_afterlogin(); } }
function get_linkedin_oauth_token() { session_start(); require_once xoousers_path . "libs/linkedin/oauth/linkedinoauth.php"; $oauthstate = $this->get_linkedin_oauth_state(); //echo "not set aut state"; error_log("No OAuth state found"); $to = new LinkedInOAuth($this->get_option('social_media_linkedin_api_public'), $this->get_option('social_media_linkedin_api_private')); // This call can be unreliable for some providers if their servers are under a heavy load, so // retry it with an increasing amount of back-off if there's a problem. $maxretrycount = 1; $retrycount = 0; while ($retrycount < $maxretrycount) { $tok = $to->getRequestToken(); if (isset($tok['oauth_token']) && isset($tok['oauth_token_secret'])) { break; } $retrycount += 1; sleep($retrycount * 5); } $tokenpublic = $tok['oauth_token']; $tokenprivate = $tok['oauth_token_secret']; $state = 'start'; // Create a new set of information, initially just containing the keys we need to make // the request. $oauthstate = array('request_token' => $tokenpublic, 'request_token_secret' => $tokenprivate, 'access_token' => '', 'access_token_secret' => '', 'state' => $state); //SET IN DB TEMP TOKEN $temp_user_session_id = session_id(); update_option('uultra_linkedin_' . $temp_user_session_id, $oauthstate); $oauthstate = get_option('uultra_linkedin_' . $temp_user_session_id); $this->set_linkedin_oauth_state($oauthstate); return $oauthstate; }
echo "<li>" . $position->title . " at " . $position->company->name . "</li>"; } echo "</ul>"; echo "<input type='checkbox' style='margin-top: 5px;'"; echo $front->getUser()->getLinkedin_share() == '1' ? 'checked="checked"' : ''; echo " id='linkedin_status' name='linkedin_status' value='Y' />"; echo "Send my weekly love stats to my LinkedIn status. ex: 2 love from 2 people."; echo "</div>"; } } ?> <?php $requestlink = ""; if (empty($access_token) && !empty($request_token)) { $to = new LinkedInOAuth(LINKEDIN_API_KEY_PUBLIC, LINKEDIN_API_KEY_PRIVATE); $requestlink = $to->getAuthorizeURL($request_token); } ?> <div id="sync_linkedin" class="settingsbutton <?php echo !empty($access_token) ? 'hide"' : '"'; ?> onclick="<?php echo "location.href='{$requestlink}';"; ?> " >Link profile</div> <div id="revoke_linkedin" class="settingsbutton <?php echo !empty($access_token) ? '"' : 'hide"'; ?> >Revoke</div>
/** * Login con linkedin * */ public function loginLinkedin() { try { //recuperar tokens de autentificacion $tok = $_SESSION['linkedin_token']; $to = new \LinkedInOAuth($this->linkedin_id, $this->linkedin_secret, $tok['oauth_token'], $tok['oauth_token_secret']); //obtenemos los tokens de acceso $tok = $to->getAccessToken($_GET['oauth_verifier']); //borramos los tokens de autentificacion de la session, ya no nos sirven //unset($_SESSION['linkedin_token']); if (empty($tok['oauth_token']) || empty($tok['oauth_token_secret'])) { $this->last_error = "oauth-linkedin-access-denied"; return false; } //guardar los tokens en la base datos si se quieren usar mas adelante! //con los tokens podems acceder a la info del user, hay que recrear el objecto con los tokens privados $this->tokens['linkedin']['token'] = $tok['oauth_token']; $this->tokens['linkedin']['secret'] = $tok['oauth_token_secret']; $profile_result = $to->oAuthRequest('http://api.linkedin.com/v1/people/~:(id,first-name,last-name,summary,public-profile-url,picture-url,headline,interests,twitter-accounts,member-url-resources:(url),positions:(company),location:(name))'); $profile_data = simplexml_load_string($profile_result); $this->user_data['name'] = trim($profile_data->{"first-name"} . " " . $profile_data->{"last-name"}); if ($profile_data->{"public-profile-url"}) { //linkedin link $this->user_data['linkedin'] = current($profile_data->{"public-profile-url"}); //username from url $this->user_data['username'] = basename($this->user_data['linkedin']); } if ($profile_data->{"member-url-resources"}->{"member-url"}) { $urls = array(); foreach ($profile_data->{"member-url-resources"}->{"member-url"} as $url) { $urls[] = current($url->url); } $this->user_data['website'] .= implode("\n", $urls); } if ($profile_data->headline) { $this->user_data['about'] = current($profile_data->headline); } if ($profile_data->location->name) { $this->user_data['location'] = current($profile_data->location->name); } if ($profile_data->{"picture-url"}) { $this->user_data['profile_image_url'] = current($profile_data->{"picture-url"}); } //si el usuario tiene especificada su cuenta twitter if ($profile_data->{"twitter-accounts"}->{"twitter-account"}) { $this->user_data['twitter'] = 'http://twitter.com/' . current($profile_data->{"twitter-accounts"}->{"twitter-account"}->{"provider-account-name"}); } //ver todos los datos disponibles: //print_r($profile_data);print_r($this->user_data);die; return true; } catch (Exception $e) { $this->last_error = $e->getMessage() . " 1/ " . get_class($e); return false; } return true; }
function lic_oAuth_Start() { $lic_consumer_key = get_option('lic_consumer_key'); $lic_consumer_secret = get_option('lic_consumer_secret'); if (!empty($lic_consumer_key) && !empty($lic_consumer_secret)) { /* Create LinkedInOAuth object with app key/secret */ //echo "Create LinkedInOAuth object with app key/secret"; $loc = $_GET['loc']; $uri = explode('#', $loc); //$url = $uri[0]; $url = get_option('siteurl'); $liclient = new LinkedInOAuth($lic_consumer_key, $lic_consumer_secret, $url); //$liclient->debug = true; /* Request tokens from linkedin */ $liclient->getRequestToken(); /* Save client for later */ $_SESSION['linkedin_client'] = serialize($liclient); //$_SESSION['linkedin_oauth_request_token_secret'] = $tok['oauth_token_secret']; $_SESSION['linkedin_oauth_callback'] = $loc; echo '<script type="text/javascript">location.href = "' . $liclient->generateAuthorizeUrl() . '";</script>'; //echo $liclient->generateAuthorizeUrl(); } }