Blame view

common/components/nodge/eauth/src/services/LinkedinOAuth1Service.php 1.93 KB
b0f143c3   Yarik   first 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
  <?php
  /**
   * LinkedinOAuthService 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 nodge\eauth\oauth1\Service;
  
  /**
   * LinkedIn provider class.
   *
   * @package application.extensions.eauth.services
   */
  class LinkedinOAuth1Service extends Service
  {
  
  	protected $name = 'linkedin';
  	protected $title = 'LinkedIn';
  	protected $type = 'OAuth1';
  	protected $jsArguments = ['popup' => ['width' => 900, 'height' => 550]];
  
  	protected $providerOptions = [
  		'request' => 'https://api.linkedin.com/uas/oauth/requestToken',
  		'authorize' => 'https://www.linkedin.com/uas/oauth/authenticate', // https://www.linkedin.com/uas/oauth/authorize
  		'access' => 'https://api.linkedin.com/uas/oauth/accessToken',
  	];
  	protected $baseApiUrl = 'http://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'];
  
  		return true;
  	}
  
  	/**
  	 * Returns the error array.
  	 *
  	 * @param array $response
  	 * @return array the error array with 2 keys: code and message. Should be null if no errors.
  	 */
  	protected function fetchResponseError($response)
  	{
  		if (isset($response['error-code'])) {
  			return [
  				'code' => $response['error-code'],
  				'message' => $response['message'],
  			];
  		} else if (isset($response['errorCode'])) {
  			return [
  				'code' => $response['errorCode'],
  				'message' => $response['message'],
  			];
  		}
  		return null;
  	}
  }