ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
sspmod_authlinkedin_Auth_Source_LinkedIn Class Reference
+ Inheritance diagram for sspmod_authlinkedin_Auth_Source_LinkedIn:
+ Collaboration diagram for sspmod_authlinkedin_Auth_Source_LinkedIn:

Public Member Functions

 __construct ($info, $config)
 Constructor for this authentication source. More...
 
 authenticate (&$state)
 Log-in using LinkedIn platform Documentation at: http://developer.linkedin.com/docs/DOC-1008. More...
 
 finalStep (&$state)
 
- Public Member Functions inherited from SimpleSAML_Auth_Source
 __construct ($info, &$config)
 Constructor for an authentication source. More...
 
 getAuthId ()
 Retrieve the ID of this authentication source. More...
 
 authenticate (&$state)
 Process a request. More...
 
 reauthenticate (array &$state)
 Reauthenticate an user. More...
 
 initLogin ($return, $errorURL=null, array $params=array())
 Start authentication. More...
 
 logout (&$state)
 Log out from this authentication source. More...
 

Data Fields

const STAGE_INIT = 'authlinkedin:init'
 The string used to identify our states. More...
 
const AUTHID = 'authlinkedin:AuthId'
 The key of the AuthId field in the state. More...
 

Protected Member Functions

 flatten ($array, $prefix='')
 takes an associative array, traverses it and returns the keys concatenated with a dot More...
 
- Protected Member Functions inherited from SimpleSAML_Auth_Source
 addLogoutCallback ($assoc, $state)
 Add a logout callback association. More...
 
 callLogoutCallback ($assoc)
 Call a logout callback based on association. More...
 

Private Attributes

 $key
 
 $secret
 
 $attributes
 

Additional Inherited Members

- Static Public Member Functions inherited from SimpleSAML_Auth_Source
static getSourcesOfType ($type)
 Get sources of a specific type. More...
 
static completeAuth (&$state)
 Complete authentication. More...
 
static loginCompleted ($state)
 Called when a login operation has finished. More...
 
static completeLogout (&$state)
 Complete logout. More...
 
static getById ($authId, $type=null)
 Retrieve authentication source. More...
 
static logoutCallback ($state)
 Called when the authentication source receives an external logout request. More...
 
static getSources ()
 Retrieve list of authentication sources. More...
 
- Static Protected Member Functions inherited from SimpleSAML_Auth_Source
static validateSource ($source, $id)
 Make sure that the first element of an auth source is its identifier. More...
 
- Protected Attributes inherited from SimpleSAML_Auth_Source
 $authId
 

Detailed Description

Definition at line 11 of file LinkedIn.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_authlinkedin_Auth_Source_LinkedIn::__construct (   $info,
  $config 
)

Constructor for this authentication source.

Parameters
array$infoInformation about this authentication source.
array$configConfiguration.

Definition at line 35 of file LinkedIn.php.

References $config, and $info.

36  {
37  assert(is_array($info));
38  assert(is_array($config));
39 
40  // Call the parent constructor first, as required by the interface
41  parent::__construct($info, $config);
42 
43  if (!array_key_exists('key', $config))
44  throw new Exception('LinkedIn authentication source is not properly configured: missing [key]');
45 
46  $this->key = $config['key'];
47 
48  if (!array_key_exists('secret', $config))
49  throw new Exception('LinkedIn authentication source is not properly configured: missing [secret]');
50 
51  $this->secret = $config['secret'];
52 
53  if (array_key_exists('attributes', $config)) {
54  $this->attributes = $config['attributes'];
55  } else {
56  // Default values if the attributes are not set in config (ref https://developer.linkedin.com/docs/fields)
57  $this->attributes = 'id,first-name,last-name,headline,summary,specialties,picture-url,email-address';
58  }
59  }
$config
Definition: bootstrap.php:15
$info
Definition: index.php:5

Member Function Documentation

◆ authenticate()

sspmod_authlinkedin_Auth_Source_LinkedIn::authenticate ( $state)

Log-in using LinkedIn platform Documentation at: http://developer.linkedin.com/docs/DOC-1008.

Parameters
array&$stateInformation about the current authentication.

Definition at line 68 of file LinkedIn.php.

References SimpleSAML_Auth_Source\$authId, $state, SimpleSAML\Logger\debug(), SimpleSAML_Auth_State\getStateId(), and SimpleSAML_Auth_State\saveState().

69  {
70  assert(is_array($state));
71 
72  // We are going to need the authId in order to retrieve this authentication source later
73  $state[self::AUTHID] = $this->authId;
74 
76  SimpleSAML\Logger::debug('authlinkedin auth state id = ' . $stateID);
77 
78  $consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
79 
80  // Get the request token
81  $requestToken = $consumer->getRequestToken(
82  'https://api.linkedin.com/uas/oauth/requestToken',
83  array('oauth_callback' => SimpleSAML\Module::getModuleUrl('authlinkedin') . '/linkback.php?stateid=' . $stateID)
84  );
85 
87  "Got a request token from the OAuth service provider [" .
88  $requestToken->key . "] with the secret [" . $requestToken->secret . "]"
89  );
90 
91  $state['authlinkedin:requestToken'] = $requestToken;
92 
93  // Update the state
94  SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
95 
96  // Authorize the request token
97  $consumer->getAuthorizeRequest('https://www.linkedin.com/uas/oauth/authenticate', $requestToken);
98  }
static getStateId(&$state, $rawId=false)
Retrieve the ID of a state array.
Definition: State.php:145
static debug($string)
Definition: Logger.php:211
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
Attribute-related utility methods.
static saveState(&$state, $stage, $rawId=false)
Save the state.
Definition: State.php:194
+ Here is the call graph for this function:

◆ finalStep()

sspmod_authlinkedin_Auth_Source_LinkedIn::finalStep ( $state)

Definition at line 101 of file LinkedIn.php.

References $attributes, $state, SimpleSAML\Logger\debug(), and flatten().

102  {
103  $requestToken = $state['authlinkedin:requestToken'];
104 
105  $consumer = new sspmod_oauth_Consumer($this->key, $this->secret);
106 
108  "oauth: Using this request token [" .
109  $requestToken->key . "] with the secret [" . $requestToken->secret . "]"
110  );
111 
112  // Replace the request token with an access token (via GET method)
113  $accessToken = $consumer->getAccessToken(
114  'https://api.linkedin.com/uas/oauth/accessToken', $requestToken,
115  array('oauth_verifier' => $state['authlinkedin:oauth_verifier'])
116  );
117 
119  "Got an access token from the OAuth service provider [" .
120  $accessToken->key . "] with the secret [" . $accessToken->secret . "]"
121  );
122 
123  $userdata = $consumer->getUserInfo(
124  'https://api.linkedin.com/v1/people/~:(' . $this->attributes . ')',
125  $accessToken,
126  array('http' => array('header' => 'x-li-format: json'))
127  );
128 
129  $attributes = $this->flatten($userdata, 'linkedin.');
130 
131  // TODO: pass accessToken: key, secret + expiry as attributes?
132 
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');
136  }
137 
138  SimpleSAML\Logger::debug('LinkedIn Returned Attributes: '. implode(", ",array_keys($attributes)));
139 
140  $state['Attributes'] = $attributes;
141  }
static debug($string)
Definition: Logger.php:211
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
flatten($array, $prefix='')
takes an associative array, traverses it and returns the keys concatenated with a dot ...
Definition: LinkedIn.php:170
+ Here is the call graph for this function:

◆ flatten()

sspmod_authlinkedin_Auth_Source_LinkedIn::flatten (   $array,
  $prefix = '' 
)
protected

takes an associative array, traverses it and returns the keys concatenated with a dot

e.g.:

[ 'linkedin' => [ 'location' => [ 'id' => '123456' 'country' => [ 'code' => 'de' ] ] ]

become:

[ 'linkedin.location.id' => [0 => '123456'], 'linkedin.location.country.code' => [0 => 'de'] ]

Parameters
array$array
string$prefix
Returns
array the array with the new concatenated keys

Definition at line 170 of file LinkedIn.php.

References $key, and $result.

Referenced by finalStep().

171  {
172  $result = array();
173  foreach ($array as $key => $value) {
174  if (is_array($value)) {
175  $result = $result + $this->flatten($value, $prefix . $key . '.');
176  } else {
177  $result[$prefix . $key] = array($value);
178  }
179  }
180  return $result;
181  }
$result
flatten($array, $prefix='')
takes an associative array, traverses it and returns the keys concatenated with a dot ...
Definition: LinkedIn.php:170
+ Here is the caller graph for this function:

Field Documentation

◆ $attributes

sspmod_authlinkedin_Auth_Source_LinkedIn::$attributes
private

Definition at line 26 of file LinkedIn.php.

Referenced by finalStep().

◆ $key

sspmod_authlinkedin_Auth_Source_LinkedIn::$key
private

Definition at line 24 of file LinkedIn.php.

Referenced by flatten().

◆ $secret

sspmod_authlinkedin_Auth_Source_LinkedIn::$secret
private

Definition at line 25 of file LinkedIn.php.

◆ AUTHID

const sspmod_authlinkedin_Auth_Source_LinkedIn::AUTHID = 'authlinkedin:AuthId'

The key of the AuthId field in the state.

Definition at line 22 of file LinkedIn.php.

◆ STAGE_INIT

const sspmod_authlinkedin_Auth_Source_LinkedIn::STAGE_INIT = 'authlinkedin:init'

The string used to identify our states.

Definition at line 17 of file LinkedIn.php.


The documentation for this class was generated from the following file: