"authorization_code", 'code' => $_REQUEST['code'], 'redirect_uri' => $LinkedIn['callback'], 'client_id' => $LinkedIn['id'], 'client_secret' => $LinkedIn['secret']); //traverse array and prepare data for posting (key1=value1) foreach ($post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted $post_string = implode('&', $post_items); //create cURL connection $conn1 = curl_init('https://www.linkedin.com/oauth/v2/accessToken'); //set options curl_setopt($conn1, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($conn1, CURLOPT_RETURNTRANSFER, true); curl_setopt($conn1, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($conn1, CURLOPT_FOLLOWLOCATION, 1); //set data to be posted curl_setopt($conn1, CURLOPT_POSTFIELDS, $post_string); //perform our request $result1 = curl_exec($conn1); $info1 = curl_getinfo($conn1); if ($info1['http_code'] === 200) { $my_token = json_decode($result1, TRUE); $access_token = $my_token['access_token']; $expires_in = $my_token['expires_in']; curl_close($conn1); } else { //show information regarding the error $errorMessage = "Error: LinkedIn server response code: " . $info1['http_code'] . " - "; $errorMessage .= curl_error($conn1); curl_close($conn1); http_response_code(500); die($errorMessage); } // Call to API $conn2 = curl_init(); curl_setopt($conn2, CURLOPT_URL, "https://api.linkedin.com/v1/people/~:(first-name,last-name,email-address,id)?format=json"); curl_setopt($conn2, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . $access_token )); curl_setopt($conn2, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($conn2); $info2 = curl_getinfo($conn2); if ($info2['http_code'] === 200) { $data = json_decode($result, TRUE); curl_close($conn2); if (isset($data['errorCode'])) { $errorMessage = $data['message']; die($errorMessage); } $typedId = $data['id']; $user = $userHandler->findUserByIdentity(RAP\Identity::LINKEDIN, $typedId); if ($user === null) { $user = new RAP\User(); $identity = new RAP\Identity(RAP\Identity::LINKEDIN); $identity->email = $data['emailAddress']; $identity->name = $data['firstName']; $identity->surname = $data['lastName']; $identity->typedId = $typedId; $user->addIdentity($identity); $userHandler->saveUser($user); } $callbackHandler->manageLoginRedirect($user, $session); } else { //show information regarding the error $errorMessage = "Error: LinkedIn server response code: " . $info2['http_code'] . " - "; $errorMessage = $errorMessage . curl_error($conn2); curl_close($conn2); die($errorMessage); } ?>