Skip to content

Commit

Permalink
Added missing provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed Apr 8, 2024
1 parent 8711f50 commit 8e74ad6
Showing 1 changed file with 86 additions and 0 deletions.
@@ -0,0 +1,86 @@
<?php
/*!
* Hybridauth
* https://hybridauth.github.io | https://github.com/hybridauth/hybridauth
* (c) 2017 Hybridauth authors | https://hybridauth.github.io/license.html
*/

namespace Hybridauth\Provider;

use Hybridauth\Adapter\OAuth2;
use Hybridauth\Data;
use Hybridauth\Exception\UnexpectedApiResponseException;
use Hybridauth\User;

/**
* LinkedIn OAuth2 provider adapter.
*/
class LinkedInOpenID extends OAuth2
{
/**
* {@inheritdoc}
*/
protected $scope = 'openid profile email';

/**
* {@inheritdoc}
*/
protected $apiBaseUrl = 'https://api.linkedin.com/v2/';

/**
* {@inheritdoc}
*/
protected $authorizeUrl = 'https://www.linkedin.com/oauth/v2/authorization';

/**
* {@inheritdoc}
*/
protected $accessTokenUrl = 'https://www.linkedin.com/oauth/v2/accessToken';

/**
* {@inheritdoc}
*/
protected $apiDocumentation = 'https://docs.microsoft.com/en-us/linkedin/shared/authentication/authentication';

/**
* {@inheritdoc}
*/
protected function initialize()
{
parent::initialize();

if ($this->isRefreshTokenAvailable()) {
$this->tokenRefreshParameters += [
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret
];
}
}

/**
* {@inheritdoc}
*/
public function getUserProfile()
{

$response = $this->apiRequest('/userinfo', 'GET', []);
$data = new Data\Collection($response);

if (!$data->exists('sub')) {
throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
}

$userProfile = new User\Profile();

$userProfile->firstName = $data->get('given_name');
$userProfile->lastName = $data->get('family_name');
$userProfile->identifier = $data->get('sub');
$userProfile->email = $data->get('email');
$userProfile->emailVerified = $data->get('email_verified');
$userProfile->displayName = $data->get('name');
$userProfile->photoURL = $data->get('picture');

return $userProfile;
}

}

0 comments on commit 8e74ad6

Please sign in to comment.