public function loginAction() { if ($this->getSession()->isLoggedIn()) { return $this->_redirectUrl(); } $connection = new LinkedInOAuth(Mage::getStoreConfig('gomage_social/linkedin/id'), Mage::getStoreConfig('gomage_social/linkedin/secret')); $callback_params = array('_secure' => true); if ($this->getRequest()->getParam('gs_url', '')) { $callback_params['gs_url'] = $this->getRequest()->getParam('gs_url'); } $callback_url = Mage::getUrl('gomage_social/linkedin/callback', $callback_params); $request_token = $connection->getRequestToken($callback_url); switch ($connection->http_code) { case 200: Mage::getSingleton('core/session')->setData('oauth_token', $request_token['oauth_token']); Mage::getSingleton('core/session')->setData('oauth_token_secret', $request_token['oauth_token_secret']); $url = $connection->getAuthorizeURL($request_token['oauth_token']); return $this->_redirectUrl($url); break; default: $this->getSession()->addError($this->__('Could not connect to LinkedIn. Refresh the page or try again later.')); } return $this->_redirectUrl(); }
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; }
/** * Autentica con LinkedIn, redirige a LinkedIn para que el usuario acepte * */ public function authenticateLinkedin() { try { //do the authentication: //get public tokens $to = new \LinkedInOAuth($this->linkedin_id, $this->linkedin_secret); // 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($this->callback_url); if (isset($tok['oauth_token']) && isset($tok['oauth_token_secret'])) { break; } $retrycount += 1; sleep($retrycount * 5); } if (empty($tok['oauth_token']) || empty($tok['oauth_token_secret'])) { $this->last_error = "oauth-token-request-error"; return false; } //en linkedin hay que guardar los token de autentificacion para usarlos //despues para obtener los tokens de acceso, $_SESSION['linkedin_token'] = $tok; //set URL $url = $to->getAuthorizeURL($tok['oauth_token']); header("Location: {$url}"); exit; } catch (Exception $e) { $this->last_error = $e->getMessage() . " 1/ " . get_class($e); return false; } return true; }
//error_log("Found access tokens in the URL - $urlaccesstoken, $urlaccessverifier"); //error_log("Creating API with $request_token, $request_token_secret"); $to = new LinkedInOAuth(LINKEDIN_API_KEY_PUBLIC, LINKEDIN_API_KEY_PRIVATE, $request_token, $request_token_secret); $tok = $to->getAccessToken($urlaccessverifier); $access_token = $tok['oauth_token']; $access_token_secret = $tok['oauth_token_secret']; $front->getUser()->updateAccessTokens($access_token, $access_token_secret); //error_log("Calculated access tokens $access_token, $access_token_secret"); } if (empty($access_token)) { //error_log("Creating request"); $to = new LinkedInOAuth(LINKEDIN_API_KEY_PUBLIC, LINKEDIN_API_KEY_PRIVATE); $maxretrycount = 1; $retrycount = 0; while ($retrycount < $maxretrycount) { $tok = $to->getRequestToken(SERVER_URL . "settings.php"); if (isset($tok['oauth_token']) && isset($tok['oauth_token_secret'])) { break; } $retrycount += 1; sleep($retrycount * 5); } $request_token = $tok['oauth_token']; $request_token_secret = $tok['oauth_token_secret']; $front->getUser()->updateRequestTokens($request_token, $request_token_secret); } if (!empty($access_token) && !empty($access_token_secret)) { $to = new LinkedInOAuth(LINKEDIN_API_KEY_PUBLIC, LINKEDIN_API_KEY_PRIVATE, $access_token, $access_token_secret); $profile_result = $to->oAuthRequest('http://api.linkedin.com/v1/people/~:(public-profile-url,three-current-positions:(title,company:(name)))'); $profile_data = simplexml_load_string($profile_result); if (strpos($profile_data->message, 'unauthorized') > 0) {
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(); } }