public function ilogin() { $url_POST = 'https://www.linkedin.com/uas/oauth2/accessToken'; if (isset($_GET['code']) && isset($_GET['state'])) { // step 2 // handle response code from linked in $code = $_GET['code']; $fields = array('code' => $code, 'grant_type' => urlencode('authorization_code'), 'redirect_uri' => urlencode('http://localhost/vnup/c/user/user/ilogin'), 'client_id' => urlencode($this->inClientId), 'client_secret' => urlencode($this->inClientSecret)); $response = HttpCallUtils::makeHttpCall($url_POST, $fields, 'POST', null); $accessTokenObject = json_decode($response, true); // array data $user = HttpCallUtils::fetchBasicProfile($accessTokenObject['access_token']); $data['user_login'] = substr($user->emailAddress, 0, strpos($user->emailAddress, '@')); $data['user_email'] = $user->emailAddress; $data['user_image'] = isset($user->pictureUrl) ? $user->pictureUrl : 'default_user.png'; $data['user_pass'] = $this->wp_hasher->HashPassword('12345'); $data['first_name'] = $user->firstName; $data['last_name'] = $user->lastName; $data['in_access_token'] = $accessTokenObject['access_token']; $data['in_token_expire'] = $accessTokenObject['expires_in']; $userObject = $this->user_model->get_user($data); if ($userObject == null) { $id = $this->user_model->insert_user($data); // send Email cause this is new user $this->sendmail($data['user_email'], 'WELCOME', array('name' => $data['first_name'] . ' ' . $data['last_name'])); } else { if ($userObject['ID'] > 0) { $id = $this->user_model->update_user($data); } } // UPDATE SESSION USER DATA $userSessionData = array(); $userSessionData['user_email'] = $data['user_email']; $userSessionData['user_login'] = $data['user_login']; $userSessionData['user_first_name'] = $data['first_name']; $userSessionData['user_last_name'] = $data['last_name']; $userSessionData['user_id'] = $id; $this->session->set_userdata($userSessionData); // HANDLE COOKIE DATA $this->handleCookie($id, false); // REDIRECT TO CURRENT PAGE redirect($_SESSION['redirect_to']); } }
public static function fetchBasicProfile($access_token) { return HttpCallUtils::fetchLinkinProfile('', '', array(), $access_token); }