Skip to content
Snippets Groups Projects
Commit a823e71e authored by Michal Procházka's avatar Michal Procházka Committed by Thijs Kinkhorst
Browse files

Configurable LinkedIn attributes (#449)

- Attributes which can be get from LinkedIn are now configurable
- By default these attributes are requested: id,first-name,last-name,headline,summary,specialties,picture-url,email-address
- Added email-address attribute into the default set
- Fixed link to the documentation
parent 6f0ca916
No related branches found
No related tags found
No related merge requests found
...@@ -212,10 +212,13 @@ $config = array( ...@@ -212,10 +212,13 @@ $config = array(
// LinkedIn OAuth Authentication API. // LinkedIn OAuth Authentication API.
// Register your application to get an API key here: // Register your application to get an API key here:
// https://www.linkedin.com/secure/developer // https://www.linkedin.com/secure/developer
// Attributes definition:
// https://developer.linkedin.com/docs/fields
'linkedin' => array( 'linkedin' => array(
'authlinkedin:LinkedIn', 'authlinkedin:LinkedIn',
'key' => 'xxxxxxxxxxxxxxxx', 'key' => 'xxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxx', 'secret' => 'xxxxxxxxxxxxxxxx',
'attributes' => 'id,first-name,last-name,headline,summary,specialties,picture-url,email-address',
), ),
*/ */
......
Using the LinkedIn authentication source with SimpleSAMLphp Using the LinkedIn authentication source with SimpleSAMLphp
=========================================================== ===========================================================
Remember to configure `authsources.php`, with both Consumer key and secret. Remember to configure `authsources.php`, with both Consumer key and secret. Optionally you can set which attributes are requested from LinkedIn, the list of available attributes can be found here <https://developer.linkedin.com/docs/fields>.
To get an API key and a secret, register the application at: To get an API key and a secret, register the application at:
......
...@@ -22,6 +22,7 @@ class sspmod_authlinkedin_Auth_Source_LinkedIn extends SimpleSAML_Auth_Source { ...@@ -22,6 +22,7 @@ class sspmod_authlinkedin_Auth_Source_LinkedIn extends SimpleSAML_Auth_Source {
private $key; private $key;
private $secret; private $secret;
private $attributes;
/** /**
...@@ -46,6 +47,13 @@ class sspmod_authlinkedin_Auth_Source_LinkedIn extends SimpleSAML_Auth_Source { ...@@ -46,6 +47,13 @@ class sspmod_authlinkedin_Auth_Source_LinkedIn extends SimpleSAML_Auth_Source {
throw new Exception('LinkedIn authentication source is not properly configured: missing [secret]'); throw new Exception('LinkedIn authentication source is not properly configured: missing [secret]');
$this->secret = $config['secret']; $this->secret = $config['secret'];
if (array_key_exists('attributes', $config)) {
$this->attributes = $config['attributes'];
} else {
// Default values if the attributes are not set in config (ref https://developer.linkedin.com/docs/fields)
$this->attributes = 'id,first-name,last-name,headline,summary,specialties,picture-url,email-address';
}
} }
...@@ -97,8 +105,7 @@ class sspmod_authlinkedin_Auth_Source_LinkedIn extends SimpleSAML_Auth_Source { ...@@ -97,8 +105,7 @@ class sspmod_authlinkedin_Auth_Source_LinkedIn extends SimpleSAML_Auth_Source {
SimpleSAML\Logger::debug("Got an access token from the OAuth service provider [" . SimpleSAML\Logger::debug("Got an access token from the OAuth service provider [" .
$accessToken->key . "] with the secret [" . $accessToken->secret . "]"); $accessToken->key . "] with the secret [" . $accessToken->secret . "]");
// TODO: configure attributes (http://developer.linkedin.com/docs/DOC-1061) from config? Limited options via LinkedIn $userdata = $consumer->getUserInfo('https://api.linkedin.com/v1/people/~:(' . $this->attributes . ')', $accessToken, array('http' => array('header' => 'x-li-format: json')));
$userdata = $consumer->getUserInfo('https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,summary,specialties,picture-url)', $accessToken, array('http' => array('header' => 'x-li-format: json')));
$attributes = array(); $attributes = array();
foreach($userdata AS $key => $value) { foreach($userdata AS $key => $value) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment