1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
Route::get('login/linkedin', function()
{
$lk_credentials = Config::get('linkedin.public0');
$provider = new LinkedIn($lk_credentials);
//var_dump($lk_credentials, $provider);
//exit();
if(!Input::has('code')){
//exit('debug');
$provider->authorize();
}else{
try{
$code = Input::get('code');
if(strlen($code) == 0) return Redirect::to('/')->with('message', 'There was an error communicating with LinkedIn');
$t = $provider->getAccessToken('authorization_code', array('code' => $code));
Session::put('authorization_code', $code);
session(['authorization_code' => $code]);
}catch(Exception $e){
return 'Unable to get access token';
}
try{
$userDetails = $provider->getUserDetails($t);
$resource = '/v1/people/~:(id,emailAddress,firstName,lastName,pictureUrl,dateOfBirth,location)';
$params = array(
'oauth2_access_token' => $t->accessToken,
'format' => 'json',
);
$url = 'https://api.linkedin.com' . $resource . '?' . http_build_query($params);
$context = stream_context_create(array('http' => array('method' => 'GET')));
$response = file_get_contents($url, false, $context);
$data = json_decode($response);
Session::put('data', $data);
session(['data' => $data]);
//return redirect('/')->with('data',$data);
}catch(Exception $e){
return 'Unable to get user details';
}
try{
$params = array(
'grant_type' => 'authorization_code',
'code' => Session::get('authorization_code'),
'redirect_uri' => url('login/linkedin'),
'client_id' => '*****************',
'client_secret' => '***************',
);
//$url = 'https://www.linkedin.com/uas/oauth2/accessToken?'.http_build_query($params);
$postdata = http_build_query($params);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($postdata) . "\r\n",
'content' => $postdata,
)
);
$context = stream_context_create($opts);
$url = 'http://www.linkedin.com/uas/oauth2/accessToken?';
$result = file_get_contents($url, false, $context);
var_dump($result);
exit();
$token = json_decode($result);
return redirect('/')->with('data',$data);
}catch(Exception $e){
return 'Unable to get Request Token';
}
}
}); |
Partager