protected function getUserIdFromApi() { // Create a LinkedIn object $linkedInApiConfig = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => APP_URL . '/' . Content::l() . '/login/linkedincallback/' . (!empty($_GET['nextPage']) ? $_GET['nextPage'] : '')); $linkedIn = new LinkedIn($linkedInApiConfig); try { $response = $linkedIn->retrieveTokenAccess($_GET['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']); } catch (Error $e) { Debug::l('Error. Could not retrieve LinkedIn access token. ' . $e); header('Location: ' . APP_URL . '/' . Content::l() . '/login/linkedin/'); exit; } if ($response['success'] === TRUE) { // The request went through without an error, gather user's access tokens $_SESSION['oauth']['linkedin']['access'] = $response['linkedin']; // Set the user as authorized for future quick reference $_SESSION['oauth']['linkedin']['authorized'] = true; } else { $this->exitWithMessage('Error. The OAuth access token was not retrieved. ' . print_r($response, 1)); } $this->accessToken = serialize($response['linkedin']); /* Retrieve the user ID The XML response will look like one of these: <person> <id>8GhzNjjaOi</id> </person> <error> <status>401</status> <timestamp>1288518358054</timestamp> <error-code>0</error-code> <message>[unauthorized]. The token used in the OAuth request is not valid.</message> </error> */ try { $response = $linkedIn->profile('~:(id,first-name,last-name)'); if ($response['success'] === TRUE) { $response['linkedin'] = new SimpleXMLElement($response['linkedin']); if ($response['linkedin']->getName() != 'person') { Debug::l('Error. Could not retrieve person data from LinkedIn. ' . print_r($response, 1)); header('Location: ' . APP_URL . '/' . Content::l() . '/login/linkedin/'); exit; } } else { Debug::l('Error. Could not retrieve person data from LinkedIn. ' . print_r($response, 1)); header('Location: ' . APP_URL . '/' . Content::l() . '/login/linkedin/'); exit; } $this->linkedInId = (string) $response['linkedin']->id; $this->name = $response['linkedin']->{'first-name'} . ' ' . $response['linkedin']->{'last-name'}; } catch (Error $e) { Debug::l('Error. Could not retrieve person ID from LinkedIn. ' . $e); header('Location: ' . APP_URL . '/' . Content::l() . '/login/linkedin/'); exit; } }
function get_resume_data() { $this->_check_auth(); $API_CONFIG = $this->config->item('LINKEDIN_KEYS'); $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($this->session->userdata('access')); $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON); $resumeResponse = $OBJ_linkedin->profile('~:(first-name,last-name,formatted-name,industry,skills,summary,specialties,positions,picture-url,educations,interests,headline,phone-numbers,email-address,member-url-resources)'); if ($resumeResponse['success'] === TRUE) { $resumeData = json_decode($resumeResponse['linkedin'], true); //print_r($resumeData); $this->load->model('resume'); $userId = $this->session->userdata('user_id'); $resumeData = array(); $resumeData['user_id'] = $userId; $resumeData['json_data'] = $resumeResponse['linkedin']; $resumeData['update_date'] = date('Y-m-d h:i:s'); if (!$this->resume->exist($userId)) { $resumeData['create_date'] = date('Y-m-d h:i:s'); $resumeId = $this->resume->create($resumeData); } else { $resumeId = $this->resume->update_user_id($userId, $resumeData); } redirect('/builder/customize/' . $resumeId, 'refresh'); } }
private function loadProfiles($person, $personIsUser) { $profiles = array(); if (!empty($person['facebook_access_token']) && (!$personIsUser || $this->mergeNetwork != 'Facebook')) { try { //$params = array('access_token' => $user['facebook_access_token']); $facebookProfile = SessionManager::getInstance()->getFacebook()->api('/' . $person['facebook_id']); } catch (FacebookApiException $e) { Debug::l('Error loading Facebook profile for ' . ($personIsUser ? 'current' : 'other') . ' user. ' . $e); } if (isset($facebookProfile)) { $profiles[] = '<a href="' . $facebookProfile['link'] . '" target="_blank" class="profile"><img src="https://graph.facebook.com/' . $person['facebook_id'] . '/picture?type=square" /> ' . $facebookProfile['name'] . ' on Facebook</a>'; } } if (!empty($person['linkedin_access_token']) && (!$personIsUser || $this->mergeNetwork != 'LinkedIn')) { $API_CONFIG = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => ''); $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess(unserialize($person['linkedin_access_token'])); try { $linkedInProfile = $OBJ_linkedin->profile('id=' . $person['linkedin_id'] . ':(first-name,last-name,public-profile-url,picture-url)'); } catch (ErrorException $e) { Debug::l('Error loading LinkedIn profile for ' . ($personIsUser ? 'current' : 'other') . ' user. ' . $e); } if ($linkedInProfile['success'] === TRUE) { $linkedInProfile['linkedin'] = new SimpleXMLElement($linkedInProfile['linkedin']); if ($linkedInProfile['linkedin']->getName() == 'person') { $li_pr = (string) $linkedInProfile['linkedin']->{'public-profile-url'}; $li_pi = (string) $linkedInProfile['linkedin']->{'picture-url'}; $li_fn = (string) $linkedInProfile['linkedin']->{'first-name'}; $li_ln = (string) $linkedInProfile['linkedin']->{'last-name'}; $profiles[] = '<a href="' . $li_pr . '" target="_blank" class="profile"><img src="' . $li_pi . '" /> ' . $li_fn . ' ' . $li_ln . ' on LinkedIn</a>'; } } } if (!empty($person['twitter_access_token']) && ($personIsUser || $this->mergeNetwork != 'Twitter')) { try { $twitterAccessToken = unserialize($person['twitter_access_token']); $twitter = new TwitterOAuth(TW_CONSUMER, TW_SECRET, $twitterAccessToken['oauth_token'], $twitterAccessToken['oauth_token_secret']); $twitter->format = 'json'; $twitterProfile = $twitter->get('users/show', array('user_id' => $person['twitter_id'])); } catch (ErrorException $e) { Debug::l('Error loading Twitter profile for ' . ($personIsUser ? 'current' : 'other') . ' user. ' . $e); } if (isset($twitterProfile)) { $profiles[] = '<a href="http://twitter.com/' . $twitterProfile->screen_name . '" target="_blank" class="profile"><img src="' . $twitterProfile->profile_image_url . '" /> @' . $twitterProfile->screen_name . ' on Twitter</a>'; } } return $profiles; }
/** * this function used to get all linkedIn user data * @author Ahmed <*****@*****.**> * @param string $appKey * @param string $appSecret * @param array $linkedIn_oauth array of user oauth data */ public static function getUserData($appKey, $appSecret, $linkedIn_oauth) { //linkedIn config parameters $config = array('appKey' => $appKey, 'appSecret' => $appSecret, 'callbackUrl' => ''); //create new linkedIn oauth object $oauth = new \LinkedIn($config); $oauth->setTokenAccess($linkedIn_oauth); $userData = $oauth->profile('~:(id,first-name,last-name,picture-url,headline,site-standard-profile-request,location:(country:(code)),summary,positions,skills,educations,courses,email-address,phone-numbers,main-address,date-of-birth)'); //check if connection success with twitter if (200 == $userData['info']['http_code']) { return $userData; } else { return NULL; } }
/** * {@inheritdoc} */ function getUserContacts() { try { $response = $this->api->profile('~/connections:(id,first-name,last-name,picture-url,public-profile-url,summary)'); } catch (LinkedInException $e) { throw new Exception("User contacts request failed! {$this->providerId} returned an error: {$e}"); } if (!$response || !$response['success']) { return array(); } $connections = new SimpleXMLElement($response['linkedin']); $contacts = array(); foreach ($connections->person as $connection) { $uc = new Hybrid_User_Contact(); $uc->identifier = (string) $connection->id; $uc->displayName = (string) $connection->{'last-name'} . " " . $connection->{'first-name'}; $uc->profileURL = (string) $connection->{'public-profile-url'}; $uc->photoURL = (string) $connection->{'picture-url'}; $uc->description = (string) $connection->{'summary'}; $contacts[] = $uc; } return $contacts; }
<div class="fill"> <div class="container"> <a class="brand" href="#">LinkedIn Assestment - Falcon Social</a> </div> </div> </div> <div class="container"> <?php if (checkSession() === true) { // Bruger er allerede tilsluttet $SimpleLI = new LinkedIn($API_CONFIG); $SimpleLI->setTokenAccess($_SESSION['oauth']['linkedin']['access']); ?> <?php $response = $SimpleLI->profile('~:(id,first-name,last-name,headline,industry,summary,location,picture-url,positions,educations,recommendations-received,connections)'); if ($response['success'] === TRUE) { $response['linkedin'] = new SimpleXMLElement($response['linkedin']); $li_profile = $response['linkedin']; ?> <div class="well"> <img src="<?php echo $li_profile->{'picture-url'}; ?> " style="float: left; padding-right: 10px;"> <h1><?php echo $li_profile->{'first-name'} . ' ' . $li_profile->{'last-name'}; ?> <br /> <small><?php echo $li_profile->{'headline'};
function linkedin() { $cookie_name = "linkedin_oauth_" . SETTING::linkedInAPI; //Check if Cookie exists && Login is enabled if ($this->repository->get_data("linkedinLogin") && isset($_COOKIE[$cookie_name]) && $_COOKIE[$cookie_name]) { $credentials_json = $_COOKIE[$cookie_name]; // where PHP stories cookies $credentials = json_decode($credentials_json); // validate signature if ($credentials->signature_version == 1) { if ($credentials->signature_order && is_array($credentials->signature_order)) { $base_string = ''; // build base string from values ordered by signature_order foreach ($credentials->signature_order as $key) { if (isset($credentials->{$key})) { $base_string .= $credentials->{$key}; } else { print "missing signature parameter: {$key}"; } } // hex encode an HMAC-SHA1 string $signature = base64_encode(hash_hmac('sha1', $base_string, SETTING::linkedInSecret, true)); // check if our signature matches the cookie's if ($signature == $credentials->signature) { //Signature is authentic, use the stuff require_once 'linkedin_3.3.0.class.php'; $linkedin = new LinkedIn(array('appKey' => SETTING::linkedInAPI, 'appSecret' => SETTING::linkedInSecret, 'callbackUrl' => NULL)); $tokens = $linkedin->exchangeToken($credentials->access_token); //Find member_id $sql = "SELECT id, nonce FROM Users WHERE linkedin_id = '" . $credentials->member_id . "'"; $result = mysql_query($sql); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); $userId = $row["id"]; $this->setSession($row["id"], $row["nonce"]); //UPDATE LinkedinToken $sql = "UPDATE Users SET linkedin_token = '" . $tokens["linkedin"]["oauth_token"] . "', linkedin_token_secret = '" . $tokens["linkedin"]["oauth_token_secret"] . "' WHERE " . $this->USER_ID . " = " . $userId; $query = mysql_query($sql); } //No member found, check if user already exists based upon usernam = email if (mysql_num_rows($result) == 0) { //print_r($tokens); $linkedin->setTokenAccess($tokens["linkedin"]); $result = $linkedin->profile("~:(email-address)?format=json"); $result = json_decode($result["linkedin"], true); $sql = "SELECT id, nonce FROM Users WHERE " . $this->USER_NAME . " = '" . $result["emailAddress"] . "'"; $query = mysql_query($sql); if (mysql_num_rows($query) == 1) { //Combination is known $row = mysql_fetch_assoc($query); //print_r($row); $userId = $row["id"]; $this->setSession($row["id"], $row["nonce"]); //UPDATE LinkedinToken $sql = "UPDATE Users SET linkedin_token = '" . $tokens["linkedin"]["oauth_token"] . "', linkedin_token_secret = '" . $tokens["linkedin"]["oauth_token_secret"] . "', linkedin_id = '" . $credentials->member_id . "' WHERE " . $this->USER_ID . " = " . $userId; $query = mysql_query($sql); //Perform import of LinkedIn data require_once "user.class.php"; $user = new user($userId, $this->errorClass, $this->notificationClass); $user->getLinkedInData(); } else { //Combination is not known, create new profile if stated if ($this->repository->get_data("linkedinRegister") == 1) { $email = $result["emailAddress"]; $nonce = $this->create_nonce(); $user_ip = $this->repository->get_data('userIPv4'); $email_hash = $this->hash_password($email, $nonce); //Define the reference number for the user $sql = "SELECT MAX(`reference_number`) as maximum FROM Users WHERE created_on >= '" . date("Y") . "-01-01' AND created_on <= '" . date("Y") . "-12-31'"; $result = mysql_fetch_assoc(mysql_query($sql)); $reference_number = $result["maximum"] + 1; //Create public profile hash $profile_hash = $this->hash_password($reference_number, $nonce); //INSERT NEW USER TO DB $query = sprintf("INSERT INTO " . $this->USER_TABLE . " (" . $this->USER_NAME . ", " . $this->USER_IP_REGISTER . ", " . $this->USER_CREATION . ", confirm_hash, nonce, account_status, reference_number, profile_hash) VALUES ('%s','%s', NOW(), '%s','%s', 0,'%s','%s')", $email, $user_ip, $email_hash, $nonce, $reference_number, $profile_hash); $result = mysql_query($query); if (!$result) { $this->errorClass->add_error(202); } else { //INSERT Clientnr to DB $sql = "SELECT * FROM Users WHERE id = " . mysql_insert_id(); $result = mysql_query($sql); $user = mysql_fetch_assoc($result); $date = strtotime($user["created_on"]); $sql = "UPDATE Users SET client_number = \"K" . date('ym', $date) . "" . sprintf('%04d', $user["reference_number"]) . "\" WHERE id = " . $user["id"]; $result = mysql_query($sql); $this->setSession($user["id"], $nonce); //UPDATE LinkedinToken $sql = "UPDATE Users SET linkedin_token = '" . $tokens["linkedin"]["oauth_token"] . "', linkedin_token_secret = '" . $tokens["linkedin"]["oauth_token_secret"] . "', linkedin_id = '" . $credentials->member_id . "' WHERE " . $this->USER_ID . " = " . $user["id"]; $query = mysql_query($sql); //Perform import of LinkedIn data require_once "user.class.php"; $user = new user($user["id"], $this->errorClass, $this->notificationClass); $user->getLinkedInData(); header("Location:" . Setting::baseUrl . "/users/complete_account.php"); exit; } } else { $this->notificationClass->add_note("Het emailadres die je gebruikt bij LinkedIn is niet bij ons bekend. Log in met je emailadres en wachtwoord en koppel je profiel met LinkedIn in je accountinstellingen of <a href=\"index.php?linkedinLogin=1&linkedinRegister=1\">registreer</a> met je LinkedIn account"); } } } //print "signature validation succeeded"; } else { print "signature validation failed"; } } else { print "signature order missing"; } } else { print "unknown cookie version"; } } }
echo $_SERVER['PHP_SELF']; ?> " method="get"> <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE; ?> " id="<?php echo LINKEDIN::_GET_TYPE; ?> " value="revoke" /> <input type="submit" value="Revoke Authorization" /> </form> <?php $response = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url)'); if ($response['success'] === TRUE) { $response['linkedin'] = new SimpleXMLElement($response['linkedin']); echo "<pre>" . print_r($response['linkedin'], TRUE) . "</pre>"; } else { // request failed echo "Error retrieving profile information:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>"; } } else { // user isn't connected ?> <form id="linkedin_connect_form" action="<?php echo $_SERVER['PHP_SELF']; ?> " method="get"> <input type="hidden" name="<?php
function index() { $API_CONFIG = $this->config->item('LINKEDIN_KEYS'); define('DEMO_GROUP', '4010474'); define('DEMO_GROUP_NAME', 'Simple LI Demo'); define('PORT_HTTP', '80'); define('PORT_HTTP_SSL', '443'); $_REQUEST[LINKEDIN::_GET_TYPE] = isset($_REQUEST[LINKEDIN::_GET_TYPE]) ? $_REQUEST[LINKEDIN::_GET_TYPE] : ''; switch ($_REQUEST[LINKEDIN::_GET_TYPE]) { case 'initiate': // check for the correct http protocol (i.e. is this script being served via http or https) if ($this->input->server('HTTPS') == 'on') { $protocol = 'https'; } else { $protocol = 'http'; } // set the callback url $API_CONFIG['callbackUrl'] = $protocol . '://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != PORT_HTTP || $_SERVER['SERVER_PORT'] != PORT_HTTP_SSL ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1'; $OBJ_linkedin = new LinkedIn($API_CONFIG); // check for response from LinkedIn $_GET[LINKEDIN::_GET_RESPONSE] = isset($_GET[LINKEDIN::_GET_RESPONSE]) ? $_GET[LINKEDIN::_GET_RESPONSE] : ''; if (!$_GET[LINKEDIN::_GET_RESPONSE]) { // LinkedIn hasn't sent us a response, the user is initiating the connection // send a request for a LinkedIn access token $response = $OBJ_linkedin->retrieveTokenRequest(); if ($response['success'] === TRUE) { // store the request token //$_SESSION['oauth']['linkedin']['request'] = $response['linkedin']; $response['linkedin']['request'] = $response['linkedin']; $this->session->set_userdata($response['linkedin']); // redirect the user to the LinkedIn authentication/authorisation page to initiate validation. header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']); } else { // bad token request echo "Request token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } } else { $sess = $this->session->all_userdata(); // LinkedIn has sent a response, user has granted permission, take the temp access token, the user's secret and the verifier to request the user's real secret key $response = $OBJ_linkedin->retrieveTokenAccess($sess['request']['oauth_token'], $sess['request']['oauth_token_secret'], $_GET['oauth_verifier']); //$response = $OBJ_linkedin->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']); if ($response['success'] === TRUE) { // the request went through without an error, gather user's 'access' tokens //$sess['access'] = $response['linkedin']; $this->session->set_userdata('access', $response['linkedin']); $this->session->set_userdata('authorized', TRUE); // set the user as authorized for future quick reference //save the shit to the db $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($this->session->userdata('access')); $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON); $userResponse = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url,email-address)'); if ($userResponse['success'] === TRUE) { $userData = json_decode($userResponse['linkedin'], true); $this->load->model('user'); $this->load->model('billing'); if (!$this->user->exist($userData['id'])) { $userId = $this->user->create($userData); $userId = $this->billing->create(FALSE, $userId); $this->session->set_userdata('user_id', $userId); } else { $user = $this->user->get_by_id($userData['id']); $this->session->set_userdata('user_id', $user[0]->id); } } redirect('/builder/get_resume_data', 'refresh'); // redirect the user back to the demo page //header('Location: ' . $_SERVER['PHP_SELF']); } else { echo "Access token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } } break; case 'revoke': // check the session /* if(!$this->oauth_session_exists()) { throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.'); } */ $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($this->session->userdata('access')); $response = $OBJ_linkedin->revoke(); if ($response['success'] === TRUE) { // revocation successful, clear session $this->session->sess_destroy(); redirect('/marketing', 'refresh'); } else { // revocation failed echo "Error revoking user's token:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } break; default: } $isLoggedIn = $this->session->userdata('authorized') ? $this->session->userdata('authorized') : FALSE; if ($isLoggedIn) { redirect('/builder/get_resume_data', 'refresh'); } $this->load->model('resume'); $resumeData = $this->resume->get_by_id(1); $resumeJsonData = json_encode($resumeData); $viewData = array('isLoggedIn' => $isLoggedIn, 'json_data' => $resumeJsonData); $this->load->view('marketing/home', $viewData); }
private function loadLinkedInFriends() { // If we have loaded the user's LinkedIn friends already in the last 12 hours, just reuse them $cacheQ = $this->db->prepare('SELECT facebook_id, linkedin_id, twitter_id, name FROM temp_friend WHERE temp_friends_id = (SELECT id FROM temp_friends WHERE linkedin_id = :linkedin_id AND time > DATE_SUB(NOW(), INTERVAL 12 HOUR) ORDER BY time DESC LIMIT 1)'); $cacheQ->execute(array(':linkedin_id' => $this->userDetails['id'])); $cache = $cacheQ->fetchAll(PDO::FETCH_ASSOC); $this->printCachedFriendsIfSet($cache); // Load friends from LinkedIn $API_CONFIG = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => ''); $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess(unserialize($this->userDetails['access_token'])); try { $linkedInFriends = $OBJ_linkedin->profile('id=' . $this->userDetails['id'] . '/connections:(id,first-name,last-name)'); } catch (ErrorException $e) { $this->printAccessTokenError($e); } if ($linkedInFriends['success'] === TRUE) { $linkedInFriends['linkedin'] = new SimpleXMLElement($linkedInFriends['linkedin']); } // Catch LinkedIn error if ($linkedInFriends['success'] !== TRUE || $linkedInFriends['linkedin']->getName() != 'connections') { $this->printAccessTokenError('Success !== TRUE'); } // No friends? :-( if (count($linkedInFriends['linkedin']->children()) == 0) { $json['result'] = 'false'; echo json_encode($json); exit; } // Cache the LinkedIn friends so we don't have to query the LinkedIn API again soon $insert = $this->db->prepare('INSERT INTO temp_friends (time, linkedin_id) VALUES (NOW(), :linkedin_id)'); $insert->execute(array(':linkedin_id' => $this->userDetails['id'])); $tempFriendsId = $this->db->lastInsertId(); $friendIds = array(); foreach ($linkedInFriends['linkedin']->person as $friend) { $id = (string) $friend->id; $friendIds[] = $this->db->quote($id); $json['friends'][$id]['linkedInId'] = $id; $json['friends'][$id]['name'] = $friend->{'first-name'} . ' ' . $friend->{'last-name'}; } $extraInfoQ = $this->db->prepare('SELECT f.id as facebookId, l.id as linkedInId, t.id as twitterId FROM linkedin l, person p LEFT JOIN facebook f ON p.id = f.person_id LEFT JOIN twitter t ON p.id = t.person_id WHERE p.id = l.person_id AND l.id IN (' . implode(',', $friendIds) . ')'); $extraInfoQ->execute(); $extraInfo = $extraInfoQ->fetchAll(PDO::FETCH_ASSOC); $json = $this->updateTemporaryFriends($json, $extraInfo, $tempFriendsId); // Delete old caches of friend list $clearQ = $this->db->prepare('DELETE FROM temp_friends WHERE linkedin_id = :linkedin_id AND time < DATE_SUB(NOW(), INTERVAL 12 HOUR)'); $clearQ->execute(array(':linkedin_id' => $this->userDetails['id'])); // Output successful result $json['result'] = 'true'; $json['time'] = Debug::getInstance()->getTimeElapsed(); echo json_encode($json); exit; }
function get_li_profile() { $API_CONFIG = array('appKey' => bb_get_option('li_app_id'), 'appSecret' => bb_get_option('li_secret'), 'callbackUrl' => NULL); $me = null; try { $_SESSION['oauth']['linkedin']['authorized'] = isset($_SESSION['oauth']['linkedin']['authorized']) ? $_SESSION['oauth']['linkedin']['authorized'] : FALSE; if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) { //bb_die("Authorized, accessing profile"); $OBJ_linkedin = new LinkedIn($API_CONFIG); //bb_die($_SESSION['oauth']['linkedin']['access']); $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']); $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_XML); // if successful authorization proceed to retrieve user information $response = $OBJ_linkedin->profile('~:(id,first-name,last-name,industry,picture-url,headline,public-profile-url)'); if ($response['success'] === TRUE) { $response['linkedin'] = new SimpleXMLElement($response['linkedin']); $me = $response['linkedin']; } else { bb_die("profiled request failed."); } } } catch (LinkedInException $e) { error_log($e); } return $me; }
public function linkedin() { try { $API_CONFIG = array('appKey' => '75wpz389ifrzbq', 'appSecret' => 'ZYEG6gBlFhhUAkfR', 'callbackUrl' => NULL); define('DEMO_GROUP', '4010474'); define('DEMO_GROUP_NAME', 'Simple LI Demo'); define('PORT_HTTP', '80'); define('PORT_HTTP_SSL', '443'); $_GET['lType'] = isset($_GET['lType']) ? $_GET['lType'] : ''; switch ($_GET['lType']) { case 'initiate': if ($_SERVER['HTTPS'] == 'on') { $protocol = 'https'; } else { $protocol = 'http'; } $API_CONFIG['callbackUrl'] = $protocol . '://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != PORT_HTTP || $_SERVER['SERVER_PORT'] != PORT_HTTP_SSL ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1'; $OBJ_linkedin = new LinkedIn($API_CONFIG); $_GET[LINKEDIN::_GET_RESPONSE] = isset($_GET[LINKEDIN::_GET_RESPONSE]) ? $_GET[LINKEDIN::_GET_RESPONSE] : ''; if (!$_GET[LINKEDIN::_GET_RESPONSE]) { $response = $OBJ_linkedin->retrieveTokenRequest(); if ($response['success'] === TRUE) { $_SESSION['oauth']['linkedin']['request'] = $response['linkedin']; header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']); } else { echo "Request token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } } else { $response = $OBJ_linkedin->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']); if ($response['success'] === TRUE) { $_SESSION['oauth']['linkedin']['access'] = $response['linkedin']; $_SESSION['oauth']['linkedin']['authorized'] = TRUE; header('Location: ' . $_SERVER['PHP_SELF']); } else { echo "Access token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } } break; case 'revoke': if (!oauth_session_exists()) { throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.'); } $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']); $response = $OBJ_linkedin->revoke(); if ($response['success'] === TRUE) { session_unset(); $_SESSION = array(); if (session_destroy()) { header('Location: ' . $_SERVER['PHP_SELF']); } else { echo "Error clearing user's session"; } } else { echo "Error revoking user's token:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } break; default: $_SESSION['oauth']['linkedin']['authorized'] = isset($_SESSION['oauth']['linkedin']['authorized']) ? $_SESSION['oauth']['linkedin']['authorized'] : FALSE; if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) { $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']); $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_XML); $response = $OBJ_linkedin->group(DEMO_GROUP, ':(relation-to-viewer:(membership-state))'); if ($response['success'] === TRUE) { $result = new SimpleXMLElement($response['linkedin']); $membership = $result->{'relation-to-viewer'}->{'membership-state'}->code; $in_demo_group = $membership == 'non-member' || $membership == 'blocked' ? FALSE : TRUE; } else { echo "Error retrieving group membership information: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>"; } } else { } if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) { $response = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url)'); if ($response['success'] === TRUE) { $response['linkedin'] = new SimpleXMLElement($response['linkedin']); echo "<pre>" . print_r($response['linkedin'], TRUE) . "</pre>"; } else { echo "Error retrieving profile information:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>"; } } else { } break; } } catch (LinkedInException $e) { echo $e->getMessage(); } $this->setErrorMessage('success', 'Registered & Login Successfully'); }
/** * * * @return array */ function linkedin() { App::import("Vendor", "Users.linkedin/linkedin_3.2.0.class"); $response = array(); $user_profile = array(); $ldnToken = ''; $ldnSecret = ''; $API_CONFIG = array('appKey' => LINKEDIN_API_KEY, 'appSecret' => LINKEDIN_SECRET_KEY, 'callbackUrl' => NULL); if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { $protocol = 'https'; } else { $protocol = 'http'; } $API_CONFIG['callbackUrl'] = Router::url(array('plugin' => 'users', 'controller' => 'users', 'action' => 'login', 'linkedin'), true) . '?' . LINKEDIN::_GET_TYPE . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1'; $OBJ_linkedin = new LinkedIn($API_CONFIG); // check for response from LinkedIn $_GET[LINKEDIN::_GET_RESPONSE] = isset($_GET[LINKEDIN::_GET_RESPONSE]) ? $_GET[LINKEDIN::_GET_RESPONSE] : ''; if (!$_GET[LINKEDIN::_GET_RESPONSE]) { // LinkedIn hasn't sent us a response, the user is initiating the connection // send a request for a LinkedIn access token $response = $OBJ_linkedin->retrieveTokenRequest(); if ($response['success'] === TRUE) { // store the request token $_SESSION['oauth']['linkedin']['request'] = $response['linkedin']; // redirect the user to the LinkedIn authentication/authorisation page to initiate validation. $response['url'] = LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']; } else { // bad token request $response['Request_Token_Failed_Response'] = $response; $response['Request_Token_Failed_Linkedin'] = $OBJ_linkedin; } } else { // LinkedIn has sent a response, user has granted permission, take the temp access token, the user's secret and the verifier to request the user's real secret key $response = $OBJ_linkedin->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']); if ($response['success'] === TRUE) { // the request went through without an error, gather user's 'access' tokens $_SESSION['oauth']['linkedin']['access'] = $response['linkedin']; // set the user as authorized for future quick reference $_SESSION['oauth']['linkedin']['authorized'] = TRUE; // redirect the user back to the demo page //header('Location: ' . $_SERVER['PHP_SELF']); $response = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url)'); if ($response['success'] === TRUE) { $user_profile = new SimpleXMLElement($response['linkedin']); $ldnSecret = $_SESSION['oauth']['linkedin']['request']['oauth_token_secret']; $ldnToken = $_SESSION['oauth']['linkedin']['request']['oauth_token']; } else { // request failed $user_profile = ''; $ldnSecret = $_SESSION['oauth']['linkedin']['request']['oauth_token_secret']; $ldnToken = $_SESSION['oauth']['linkedin']['request']['oauth_token']; } } else { // bad token access $response['Request_Token_Failed_Response'] = $response; $response['Request_Token_Failed_Linkedin'] = $OBJ_linkedin; } } $response['user_profile'] = $user_profile; return $response; }
<?php header('Content-type: application/json'); require '../config/keys.php'; require '../lib/linkedin/linkedin_3.2.0.class.php'; $API_CONFIG = $linkedin['config']; $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($linkedin['access']); $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON); $json = $OBJ_linkedin->profile('~:(first-name,last-name,formatted-name,industry,skills,summary,specialties,positions,picture-url,educations,interests,headline,phone-numbers,email-address,member-url-resources)'); $info = json_decode($json['linkedin']); $node = array('name' => $info->formattedName, 'headline' => $info->headline, 'picture_url' => $info->pictureUrl, 'summary' => $info->summary, 'work_history' => $info->positions->values, 'meta' => 'Powered by LinkedIn', 'profile_url' => 'http://www.linkedin.com/in/njhamann'); if ($json['success'] === TRUE) { if (isset($_GET['raw']) && $_GET['raw'] == '1') { echo json_encode($info); } else { echo json_encode($node); } }
/** * Similar to onAuthenticate, except we already have a logged in user, we're just linking accounts * * @param array $options * @return void */ public function link($options = array()) { $jsession = App::get('session'); // Set up linkedin configuration $linkedin_config['appKey'] = $this->params->get('api_key'); $linkedin_config['appSecret'] = $this->params->get('app_secret'); // Create Object $linkedin_client = new LinkedIn($linkedin_config); if (!Request::getVar('oauth_verifier', NULL)) { // User didn't authorize our app, or, clicked cancel App::redirect(Route::url('index.php?option=com_members&id=' . User::get('id') . '&active=account'), Lang::txt('PLG_AUTHENTICATION_LINKEDIN_MUST_AUTHORIZE_TO_LOGIN', App::get('sitename')), 'error'); } // LinkedIn has sent a response, user has granted permission, take the temp access token, // the user's secret and the verifier to request the user's real secret key $request = $jsession->get('linkedin.oauth.request'); $reply = $linkedin_client->retrieveTokenAccess($request['oauth_token'], $request['oauth_token_secret'], Request::getVar('oauth_verifier')); if ($reply['success'] === TRUE) { // The request went through without an error, gather user's 'access' tokens $jsession->set('linkedin.oauth.access', $reply['linkedin']); // Set the user as authorized for future quick reference $jsession->set('linkedin.oauth.authorized', TRUE); } else { return new Exception(Lang::txt('Access token retrieval failed'), 500); } if ($jsession->get('linkedin.oauth.authorized') == TRUE) { $linkedin_client->setTokenAccess($jsession->get('linkedin.oauth.access')); // Get the linked in profile $profile = $linkedin_client->profile('~:(id,first-name,last-name,email-address)'); $profile = $profile['linkedin']; // Parse the profile XML $profile = new SimpleXMLElement($profile); // Get the profile values $li_id = $profile->{'id'}; $username = (string) $li_id; // (make sure this is unique) $hzad = \Hubzero\Auth\Domain::getInstance('authentication', 'linkedin', ''); // Create the link if (\Hubzero\Auth\Link::getInstance($hzad->id, $username)) { // This linkedin account is already linked to another hub account App::redirect(Route::url('index.php?option=com_members&id=' . User::get('id') . '&active=account'), Lang::txt('PLG_AUTHENTICATION_LINKEDIN_ACCOUNT_ALREADY_LINKED'), 'error'); } else { $hzal = \Hubzero\Auth\Link::find_or_create('authentication', 'linkedin', null, $username); $hzal->user_id = User::get('id'); $hzal->email = (string) $profile->{'email-address'}; $hzal->update(); } } else { // User didn't authorize our app, or, clicked cancel App::redirect(Route::url('index.php?option=com_members&id=' . User::get('id') . '&active=account'), Lang::txt('PLG_AUTHENTICATION_LINKEDIN_MUST_AUTHORIZE_TO_LINK', Config::get('sitename')), 'error'); } }
function getLinkedinProfile($req_type) { $session = LinkedinHelper::oauth_session_exists(); $app = JFactory::getApplication(); // include the LinkedIn class require_once 'linkedin_3.1.1.class.php'; // display constants $API_CONFIG = array('appKey' => 'r7xckk3gxdfg', 'appSecret' => 'fJQh57Ex2Qg7YyPi', 'callbackUrl' => NULL); define('CONNECTION_COUNT', 20); define('PORT_HTTP', '80'); define('PORT_HTTP_SSL', '443'); define('UPDATE_COUNT', 10); // set index //$_REQUEST[LINKEDIN::_GET_TYPE] = (isset($_REQUEST[LINKEDIN::_GET_TYPE])) ? $_REQUEST[LINKEDIN::_GET_TYPE] : ''; switch ($req_type) { case 'initiate': /** * Handle user initiated LinkedIn connection, create the LinkedIn object. */ // check for the correct http protocol (i.e. is this script being served via http or https) if (isset($_SERVER['HTTPS'])) { if ($_SERVER['HTTPS'] == 'on') { $protocol = 'https'; } else { $protocol = 'http'; } } else { $protocol = 'http'; } // set the callback url $API_CONFIG['callbackUrl'] = $protocol . '://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != PORT_HTTP || $_SERVER['SERVER_PORT'] != PORT_HTTP_SSL ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'] . '?' . $req_type . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1'; // $API_CONFIG['callbackUrl'] = JRoute::_('index.php?option=com_jobboard&view=user') . '&' . $req_type . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1'; // echo $API_CONFIG['callbackUrl'];die; $OBJ_linkedin = new LinkedIn($API_CONFIG); // check for response from LinkedIn $_GET[LINKEDIN::_GET_RESPONSE] = isset($_GET[LINKEDIN::_GET_RESPONSE]) ? $_GET[LINKEDIN::_GET_RESPONSE] : ''; if (!$_GET[LINKEDIN::_GET_RESPONSE]) { // LinkedIn hasn't sent us a response, the user is initiating the connection // send a request for a LinkedIn access token $response = $OBJ_linkedin->retrieveTokenRequest(); //echo 'response: '.'<pre>'.print_r($response, true).'</pre>'; if ($response['success'] === TRUE) { // store the request token $session_oauth = $session->get('oauth'); $session_oauth['oauth']['linkedin']['request'] = $response['linkedin']; $session->set('oauth', $session_oauth); //redirect the user to the LinkedIn authentication/authorisation page to initiate validation. $app->redirect(LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']); } else { $profile_assoc = array(); $profile_assoc['response'] = false; $profile_assoc['msg'] = "Request token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>"; return $profile_assoc; // bad token request } } else { // LinkedIn has sent a response // user has cancelled LinkedIn authentication if (JRequest::getString('oauth_problem') == 'user_refused') { $app->redirect('index.php?option=com_jobboard&view=user&task=addcv', JText::_('COM_JOBBOARD_IMPORTLINKEDINCANCELLED')); } // user has granted permission, take the temp access token, the user's secret and the verifier to request the user's real secret key $session_oauth = $session->get('oauth'); $response = $OBJ_linkedin->retrieveTokenAccess($session_oauth['oauth']['linkedin']['request']['oauth_token'], $session_oauth['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']); if ($response['success'] === TRUE) { // the request went through without an error, gather user's 'access' tokens $session_oauth['oauth']['linkedin']['access'] = $response['linkedin']; // set the user as authorized for future quick reference $session_oauth['oauth']['linkedin']['authorized'] = TRUE; $session->set('oauth', $session_oauth); } else { // bad token access echo "Access token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } } $response = $OBJ_linkedin->profile('~:(id,first-name,last-name,summary,educations,positions,skills)'); if ($response['success'] === TRUE) { $profile = new SimpleXMLElement($response['linkedin']); $profile_json = json_encode($profile); $profile_assoc = array_unique(json_decode($profile_json, TRUE), SORT_REGULAR); $profile_assoc['response'] = $response['success']; } else { // profile retrieval failed $profile_assoc = array(); $profile_assoc['response'] = false; } return $profile_assoc; break; case 'revoke': /** * Handle authorization revocation. */ $session_oauth = $session->get('oauth'); $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($session_oauth['oauth']['linkedin']['access']); $response = $OBJ_linkedin->revoke(); if ($response['success'] === TRUE) { // revocation successful, clear session if ($session->clear('oauth')) { // session destroyed //header('Location: ' . $_SERVER['PHP_SELF']); } else { // session not destroyed echo "Error clearing user's session"; } } else { // revocation failed echo "Error revoking user's token:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } break; default: // nothing being passed back, display demo page // check PHP version if (version_compare(PHP_VERSION, '5.0.0', '<')) { throw new LinkedInException('You must be running version 5.x or greater of PHP to use this library.'); } // check for cURL if (extension_loaded('curl')) { $curl_version = curl_version(); $curl_version = $curl_version['version']; } else { throw new LinkedInException('You must load the cURL extension to use this library.'); } $session_oauth = $session->get('oauth'); if (!isset($session_oauth['oauth']['linkedin']['authorized'])) { $session_oauth['oauth']['linkedin']['authorized'] = FALSE; $session->set('oauth', $session_oauth); } if ($session_oauth['oauth']['linkedin']['authorized'] === TRUE) { // user is already connected $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($session_oauth['oauth']['linkedin']['access']); ?> <?php //$response = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url)'); $response = $OBJ_linkedin->profile('~:(id,first-name,last-name,summary,educations,positions,skills)'); if ($response['success'] === TRUE) { //$response['linkedin'] = new SimpleXMLElement($response['linkedin']); // echo "<pre>" . print_r($response['linkedin'], TRUE) . "</pre>"; $profile = new SimpleXMLElement($response['linkedin']); $profile_json = json_encode($profile); return json_decode($profile_json, TRUE); } else { // profile retrieval failed echo "Error retrieving profile information:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>"; } } else { // user isn't connected ?> <?php } ?> <?php break; } }
function test($ltype = '', $response = '', $oauth_token = '', $oauth_verfier = '') { $this->data['success'] = FALSE; function oauth_session_exists() { if (is_array($_SESSION) && array_key_exists('oauth', $_SESSION)) { return TRUE; } else { return FALSE; } } try { // include the LinkedIn class //require_once('linkedin_3.2.0.class.php'); // start the session // if(!session_start()) { // throw new LinkedInException('This script requires session support, which appears to be disabled according to session_start().'); // } // display constants if (isset($_REQUEST['invitation_key'])) { $this->data['invitation_key_val'] = $_REQUEST['invitation_key']; } elseif ($this->input->post('invitation_key')) { $this->data['invitation_key_val'] = $this->input->post('invitation_key'); } else { $this->data['invitation_key_val'] = ''; } if (isset($_REQUEST['email_val'])) { $this->data['email_val'] = $_REQUEST['email_val']; } elseif ($this->input->post('email_val')) { $this->data['email_val'] = $this->input->post('email_val'); } else { $this->data['email_val'] = ''; } $API_CONFIG = array('appKey' => 'ctfw9ywn6vrm', 'appSecret' => 'T2G5ccnIfGytPAdt', 'callbackUrl' => NULL); define('DEMO_GROUP', '4010474'); define('DEMO_GROUP_NAME', 'Simple LI Demo'); define('PORT_HTTP', '80'); define('PORT_HTTP_SSL', '443'); // set index //echo "<script type='text/javascript'>console.log('@".LINKEDIN::_GET_TYPE."".print_r($this->uri)."')</script>"; $_REQUEST[LINKEDIN::_GET_TYPE] = isset($_REQUEST[LINKEDIN::_GET_TYPE]) ? $_REQUEST[LINKEDIN::_GET_TYPE] : ''; //echo "<script type='text/javascript'>console.log('@".$_REQUEST[LINKEDIN::_GET_TYPE]."')</script>"; switch ($_REQUEST[LINKEDIN::_GET_TYPE]) { case 'initiate': /** * Handle user initiated LinkedIn connection, create the LinkedIn object. */ // check for the correct http protocol (i.e. is this script being served via http or https) if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { $protocol = 'https'; } else { $protocol = 'http'; } // set the callback url $API_CONFIG['callbackUrl'] = $protocol . '://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != PORT_HTTP || $_SERVER['SERVER_PORT'] != PORT_HTTP_SSL ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1'; $OBJ_linkedin = new LinkedIn($API_CONFIG); // check for response from LinkedIn $_GET[LINKEDIN::_GET_RESPONSE] = isset($_GET[LINKEDIN::_GET_RESPONSE]) ? $_GET[LINKEDIN::_GET_RESPONSE] : ''; if (!$_GET[LINKEDIN::_GET_RESPONSE]) { // LinkedIn hasn't sent us a response, the user is initiating the connection // send a request for a LinkedIn access token $response = $OBJ_linkedin->retrieveTokenRequest(); if ($response['success'] === TRUE) { // store the request token $_SESSION['oauth']['linkedin']['request'] = $response['linkedin']; // redirect the user to the LinkedIn authentication/authorisation page to initiate validation. header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']); } else { // bad token request echo "Request token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } } else { // LinkedIn has sent a response, user has granted permission, take the temp access token, the user's secret and the verifier to request the user's real secret key $response = $OBJ_linkedin->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']); if ($response['success'] === TRUE) { // the request went through without an error, gather user's 'access' tokens $_SESSION['oauth']['linkedin']['access'] = $response['linkedin']; $this->data['success'] = TRUE; $this->data['status'] = TRUE; $response['linkedin'] = new SimpleXMLElement($response['linkedin']); // set the user as authorized for future quick reference $_SESSION['oauth']['linkedin']['authorized'] = TRUE; // redirect the user back to the demo page header('Location: ' . $_SERVER['PHP_SELF']); } else { // bad token access echo "Access token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } } break; default: // nothing being passed back, display demo page // check PHP version if (version_compare(PHP_VERSION, '5.0.0', '<')) { throw new LinkedInException('You must be running version 5.x or greater of PHP to use this library.'); } // check for cURL if (extension_loaded('curl')) { $curl_version = curl_version(); $curl_version = $curl_version['version']; } else { throw new LinkedInException('You must load the cURL extension to use this library.'); } $_SESSION['oauth']['linkedin']['authorized'] = isset($_SESSION['oauth']['linkedin']['authorized']) ? $_SESSION['oauth']['linkedin']['authorized'] : FALSE; if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) { $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']); $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_XML); } else { } if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) { // user is already connected $application_key = $OBJ_linkedin->getApplicationKey(); $this->data['success'] = FALSE; $response = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url)'); $this->data['response'] = $response; if ($response['success'] === TRUE) { $this->data['success'] = TRUE; $this->data['status'] = TRUE; $response['linkedin'] = new SimpleXMLElement($response['linkedin']); //var_dump($response['linkedin']); $this->data['response'] = $response['linkedin']; } else { $this->data['status'] = FALSE; // request failed } } else { // user isn't connected } break; } } catch (LinkedInException $e) { // exception raised by library call $e->getMessage(); } $this->data['invitation_key'] = array('name' => 'invitation_key', 'id' => 'invitation_key', 'value' => $this->data['invitation_key_val'], 'type' => 'hidden'); $this->data['first_name'] = array('name' => 'first_name', 'id' => 'first_name', 'type' => 'text', 'value' => $this->form_validation->set_value('first_name'), 'placeholder' => 'First Name', 'required' => 'required'); $this->data['last_name'] = array('name' => 'last_name', 'id' => 'last_name', 'type' => 'text', 'value' => $this->form_validation->set_value('last_name'), 'placeholder' => 'Last Name', 'required' => 'required'); $this->data['email'] = array('name' => 'email', 'id' => 'email', 'type' => 'text', 'value' => $this->data['email_val'], 'placeholder' => 'Email', 'required' => 'required', 'readonly' => 'readonly'); $this->data['password'] = array('name' => 'password', 'id' => 'password', 'type' => 'password', 'value' => $this->form_validation->set_value('password'), 'placeholder' => 'Password', 'required' => 'required'); $this->data['password_confirm'] = array('name' => 'password_confirm', 'id' => 'password_confirm', 'type' => 'password', 'value' => $this->form_validation->set_value('password_confirm'), 'placeholder' => 'Confirm Password', 'required' => 'required'); // Render View //$this->load->view('auth/create_user', $this->data); $this->data['main_content'] = '/auth/signup'; $this->load->view('includes/tmpl_singlebox', $this->data); }