3 require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))) .
'/oauth/libextinc/OAuth.php');
22 const AUTHID =
'authlinkedin:AuthId';
37 assert(is_array(
$info));
43 if (!array_key_exists(
'key',
$config))
44 throw new Exception(
'LinkedIn authentication source is not properly configured: missing [key]');
48 if (!array_key_exists(
'secret',
$config))
49 throw new Exception(
'LinkedIn authentication source is not properly configured: missing [secret]');
51 $this->secret =
$config[
'secret'];
53 if (array_key_exists(
'attributes',
$config)) {
54 $this->attributes =
$config[
'attributes'];
57 $this->attributes =
'id,first-name,last-name,headline,summary,specialties,picture-url,email-address';
81 $requestToken = $consumer->getRequestToken(
82 'https://api.linkedin.com/uas/oauth/requestToken',
83 array(
'oauth_callback' =>
SimpleSAML\Module::getModuleUrl(
'authlinkedin') .
'/linkback.php?stateid=' . $stateID)
87 "Got a request token from the OAuth service provider [" .
88 $requestToken->key .
"] with the secret [" . $requestToken->secret .
"]" 91 $state[
'authlinkedin:requestToken'] = $requestToken;
97 $consumer->getAuthorizeRequest(
'https://www.linkedin.com/uas/oauth/authenticate', $requestToken);
103 $requestToken =
$state[
'authlinkedin:requestToken'];
108 "oauth: Using this request token [" .
109 $requestToken->key .
"] with the secret [" . $requestToken->secret .
"]" 113 $accessToken = $consumer->getAccessToken(
114 'https://api.linkedin.com/uas/oauth/accessToken', $requestToken,
115 array(
'oauth_verifier' =>
$state[
'authlinkedin:oauth_verifier'])
119 "Got an access token from the OAuth service provider [" .
120 $accessToken->key .
"] with the secret [" . $accessToken->secret .
"]" 123 $userdata = $consumer->getUserInfo(
124 'https://api.linkedin.com/v1/people/~:(' . $this->attributes .
')',
126 array(
'http' => array(
'header' =>
'x-li-format: json'))
133 if (array_key_exists(
'id', $userdata)) {
134 $attributes[
'linkedin_targetedID'] = array(
'http://linkedin.com!' . $userdata[
'id']);
135 $attributes[
'linkedin_user'] = array($userdata[
'id'] .
'@linkedin.com');
170 protected function flatten($array, $prefix =
'')
173 foreach ($array as
$key => $value) {
174 if (is_array($value)) {
static getStateId(&$state, $rawId=false)
Retrieve the ID of a state array.
__construct($info, $config)
Constructor for this authentication source.
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Attribute-related utility methods.
flatten($array, $prefix='')
takes an associative array, traverses it and returns the keys concatenated with a dot ...
const AUTHID
The key of the AuthId field in the state.
authenticate(&$state)
Log-in using LinkedIn platform Documentation at: http://developer.linkedin.com/docs/DOC-1008.
static saveState(&$state, $stage, $rawId=false)
Save the state.
const STAGE_INIT
The string used to identify our states.