Enh: Add LinkedIn auth

This will implement the ability to use LinkedIn auth to login.
This commit is contained in:
Sarah Tsumayoi 2017-11-10 15:44:14 -08:00 committed by GitHub
parent b0e2999eea
commit 4aeabc87f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,116 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\user\authclient;
use yii\authclient\OAuth2;
use yii\web\HttpException;
use Yii;
class LinkedIn extends \yii\authclient\clients\LinkedIn
{
/**
* @inheritdoc
*/
protected function defaultViewOptions()
{
return [
'popupWidth' => 860,
'popupHeight' => 480,
'cssIcon' => 'fa fa-linkedin',
'buttonBackgroundColor' => '#395697',
];
}
/**
* {@inheritdoc}
*/
public $authUrl = 'https://www.linkedin.com/oauth/v2/authorization';
/**
* {@inheritdoc}
*/
public $tokenUrl = 'https://www.linkedin.com/oauth/v2/accessToken';
/**
* {@inheritdoc}
*/
public $apiBaseUrl = 'https://api.linkedin.com/v1';
/**
* {@inheritdoc}
*/
public $attributeNames = [
'id',
'email-address',
'first-name',
'last-name',
'public-profile-url',
];
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
if ($this->scope === null) {
$this->scope = implode(' ', [
'r_basicprofile',
'r_emailaddress',
]);
}
}
/**
* {@inheritdoc}
*/
protected function defaultNormalizeUserAttributeMap()
{
return [
'email' => 'email-address',
'first_name' => 'first-name',
'last_name' => 'last-name',
];
}
/**
* {@inheritdoc}
*/
protected function initUserAttributes()
{
return $this->api('people/~:(' . implode(',', $this->attributeNames) . ')', 'GET');
}
/**
* {@inheritdoc}
*/
public function applyAccessTokenToRequest($request, $accessToken)
{
$data = $request->getData();
$data['oauth2_access_token'] = $accessToken->getToken();
$request->setData($data);
}
/**
* {@inheritdoc}
*/
protected function defaultName()
{
return 'linkedin';
}
/**
* {@inheritdoc}
*/
protected function defaultTitle()
{
return 'LinkedIn';
}
}