When a new user arrives and want to authenticate here is whats happens:
1. You redirect him to whatever url getLoginUrl() returns.
2. The user logs in on www.linkedin.com and authorize your application.
3. The user returns to your site with a *code* in the the $_REQUEST.
4. You call isAuthenticated() or getAccessToken()
5. If we don't have an access token (only a *code*), getAccessToken() will call fetchNewAccessToken()
6. fetchNewAccessToken() gets the *code* from the $_REQUEST and calls getAccessTokenFromCode()
7. getAccessTokenFromCode() makes a request to www.linkedin.com and exchanges the *code* for an access token
8. When you have the access token you should store it in a database and/or query the API.
9. When you make a second request to the API we have the access token in memory, so we don't go through all these
authentication steps again.
public function indexAction() { $linkedIn = new LinkedIn($this->getServiceLocator()->get('config')['linkedin_keys']['aapId'], $this->getServiceLocator()->get('config')['linkedin_keys']['app_secret']); if ($linkedIn->isAuthenticated()) { //we know that the user is authenticated now. Start query the API $user = $linkedIn->api('v1/people/~:(id,firstName,lastName,emailAddress)'); //Check user exist or not $api = new Api(); $api_url = $this->getServiceLocator()->get('Config')['api_url']['value']; $url = $api_url . "/api/useractivity/"; $data = array('op' => 'check_exist_user', 'user_name' => $user['emailAddress'], 'email' => $user['emailAddress']); $res = $api->curl($url, $data, "POST"); //Set value in session $lk_login = new Container('linkedin'); $lk_login->first_name = $user['firstName']; $lk_login->last_name = $user['lastName']; $lk_login->user_name = $user['emailAddress']; $lk_login->email = $user['emailAddress']; $lk_login->social_id = $user['id']; // END :- Set value in session //$facebook1->destroySession(); die; // For new user if ($res->getStatusCode() != 200) { $redirectUrl = 'register/index#register-a'; return $this->redirect()->toUrl($redirectUrl); } else { $auth = new FrontEndAuth(); $session = new Container('frontend'); $content = json_decode($res->getBody(), true); $session->status_id = $content['status_id']; $session->userid = $content['id']; if ($content['status_id'] != 3) { $session->first_name = $content['first_name']; $session->last_name = $content['last_name']; $session->email = $content['email']; $session->user_name = $content['user_name']; $session->user_type_id = $content['user_type_id']; $session->user_data = $content; $session->last_login = $content['last_login_prev']; $auth->wordpress_login($fbuname); //$redirectUrl = ($session->user_type_id == 4)?array('controller' => 'practitioner', 'action' => 'list'):array('controller' => 'practitioner', 'action' => 'dashboard'); $redirectUrl = $session->user_type_id == 4 ? 'list' : 'dashboard'; $url = "practitioner/" . $redirectUrl; return $this->redirect()->toUrl($url); } else { return $this->redirect()->toRoute('login', array('action' => 'index')); } } } elseif ($linkedIn->hasError()) { echo "User canceled the login."; exit; } //if not authenticated $url = $linkedIn->getLoginUrl(); return $this->redirect()->toUrl($url); die; }
public function getRequest() { return parent::getRequest(); }
public function testGetErrorWithMissingDescription() { $linkedIn = new LinkedIn(self::APP_ID, self::APP_SECRET); unset($_GET['error']); unset($_GET['error_description']); $_GET['error'] = 'foo'; $this->assertEquals('foo', $linkedIn->getError()->getName()); $this->assertNull($linkedIn->getError()->getDescription()); }
/** * LinkedInLaravel constructor. * * @param string $app_id * @param string $app_secret */ public function __construct($app_id, $app_secret) { parent::__construct($app_id, $app_secret); }