Blame view

common/components/nodge/eauth/src/services/LinkedinOAuth2Service.php 2.11 KB
14a09168   Alex Savenko   init commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  <?php

  /**

   * LinkedinOAuth2Service class file.

   *

   * Register application: https://www.linkedin.com/secure/developer

   * Note: Integration URL should be filled with a valid callback url.

   *

   * @author Maxim Zemskov <nodge@yandex.ru>

   * @link http://github.com/Nodge/yii2-eauth/

   * @license http://www.opensource.org/licenses/bsd-license.php

   */

  

  namespace common\components\nodge\eauth\src\services;

  

  use OAuth\OAuth2\Service\ServiceInterface;

  use nodge\eauth\oauth2\Service;

  

  /**

   * LinkedIn provider class.

   *

   * @package application.extensions.eauth.services

   */

  class LinkedinOAuth2Service extends Service

  {

  

  	/**

  	 * Defined scopes

  	 *

  	 * @link http://developer.linkedin.com/documents/authentication#granting

  	 */

  	const SCOPE_R_BASICPROFILE = 'r_basicprofile';

  	const SCOPE_R_FULLPROFILE = 'r_fullprofile';

  	const SCOPE_R_EMAILADDRESS = 'r_emailaddress';

  	const SCOPE_R_NETWORK = 'r_network';

  	const SCOPE_R_CONTACTINFO = 'r_contactinfo';

  	const SCOPE_RW_NUS = 'rw_nus';

  	const SCOPE_RW_GROUPS = 'rw_groups';

  	const SCOPE_W_MESSAGES = 'w_messages';

  

  	protected $name = 'linkedin_oauth2';

  	protected $title = 'LinkedIn';

  	protected $type = 'OAuth2';

  	protected $jsArguments = ['popup' => ['width' => 900, 'height' => 550]];

  

  	protected $scopes = [self::SCOPE_R_BASICPROFILE];

  	protected $providerOptions = [

  		'authorize' => 'https://www.linkedin.com/uas/oauth2/authorization',

  		'access_token' => 'https://www.linkedin.com/uas/oauth2/accessToken',

  	];

  	protected $baseApiUrl = 'https://api.linkedin.com/v1/';

  

  	protected function fetchAttributes()

  	{

  		$info = $this->makeSignedRequest('people/~:(id,first-name,last-name,public-profile-url)', [

  			'query' => [

  				'format' => 'json',

  			],

  		]);

  

  		$this->attributes['id'] = $info['id'];

  		$this->attributes['name'] = $info['firstName'] . ' ' . $info['lastName'];

  		$this->attributes['url'] = $info['publicProfileUrl'];

  		$this->attributes['email'] = $info['emailAddress'];

  		return true;

  	}

  

  	/**

  	 * @return int

  	 */

  	public function getAuthorizationMethod()

  	{

  		return ServiceInterface::AUTHORIZATION_METHOD_QUERY_STRING_V2;

  	}

  }