@@ -12,47 +12,47 @@ |
||
12 | 12 | */ |
13 | 13 | interface HttpClientInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * Send request to the remote server |
|
17 | - * |
|
18 | - * Returns the result (Raw response from the server) on success, FALSE on failure |
|
19 | - * |
|
20 | - * @param string $uri |
|
21 | - * @param string $method |
|
22 | - * @param array $parameters |
|
23 | - * @param array $headers |
|
24 | - * @param bool $multipart |
|
25 | - * |
|
26 | - * @return mixed |
|
27 | - */ |
|
28 | - public function request($uri, $method = 'GET', $parameters = [], $headers = [], $multipart = false); |
|
15 | + /** |
|
16 | + * Send request to the remote server |
|
17 | + * |
|
18 | + * Returns the result (Raw response from the server) on success, FALSE on failure |
|
19 | + * |
|
20 | + * @param string $uri |
|
21 | + * @param string $method |
|
22 | + * @param array $parameters |
|
23 | + * @param array $headers |
|
24 | + * @param bool $multipart |
|
25 | + * |
|
26 | + * @return mixed |
|
27 | + */ |
|
28 | + public function request($uri, $method = 'GET', $parameters = [], $headers = [], $multipart = false); |
|
29 | 29 | |
30 | - /** |
|
31 | - * Returns raw response from the server on success, FALSE on failure |
|
32 | - * |
|
33 | - * @return mixed |
|
34 | - */ |
|
35 | - public function getResponseBody(); |
|
30 | + /** |
|
31 | + * Returns raw response from the server on success, FALSE on failure |
|
32 | + * |
|
33 | + * @return mixed |
|
34 | + */ |
|
35 | + public function getResponseBody(); |
|
36 | 36 | |
37 | - /** |
|
38 | - * Retriever the headers returned in the response |
|
39 | - * |
|
40 | - * @return array |
|
41 | - */ |
|
42 | - public function getResponseHeader(); |
|
37 | + /** |
|
38 | + * Retriever the headers returned in the response |
|
39 | + * |
|
40 | + * @return array |
|
41 | + */ |
|
42 | + public function getResponseHeader(); |
|
43 | 43 | |
44 | - /** |
|
45 | - * Returns latest request HTTP status code |
|
46 | - * |
|
47 | - * @return int |
|
48 | - */ |
|
49 | - public function getResponseHttpCode(); |
|
44 | + /** |
|
45 | + * Returns latest request HTTP status code |
|
46 | + * |
|
47 | + * @return int |
|
48 | + */ |
|
49 | + public function getResponseHttpCode(); |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns latest error encountered by the client |
|
53 | - * This can be either a code or error message |
|
54 | - * |
|
55 | - * @return mixed |
|
56 | - */ |
|
57 | - public function getResponseClientError(); |
|
51 | + /** |
|
52 | + * Returns latest error encountered by the client |
|
53 | + * This can be either a code or error message |
|
54 | + * |
|
55 | + * @return mixed |
|
56 | + */ |
|
57 | + public function getResponseClientError(); |
|
58 | 58 | } |
@@ -14,87 +14,87 @@ |
||
14 | 14 | */ |
15 | 15 | class Util |
16 | 16 | { |
17 | - /** |
|
18 | - * Redirect handler. |
|
19 | - * |
|
20 | - * @var callable|null |
|
21 | - */ |
|
22 | - protected static $redirectHandler; |
|
17 | + /** |
|
18 | + * Redirect handler. |
|
19 | + * |
|
20 | + * @var callable|null |
|
21 | + */ |
|
22 | + protected static $redirectHandler; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Exit handler. |
|
26 | - * |
|
27 | - * @var callable|null |
|
28 | - */ |
|
29 | - protected static $exitHandler; |
|
24 | + /** |
|
25 | + * Exit handler. |
|
26 | + * |
|
27 | + * @var callable|null |
|
28 | + */ |
|
29 | + protected static $exitHandler; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Redirect to a given URL. |
|
33 | - * |
|
34 | - * In case your application need to perform certain required actions before Hybridauth redirect users |
|
35 | - * to IDPs websites, the default behaviour can be altered in one of two ways: |
|
36 | - * If callable $redirectHandler is defined, it will be called instead. |
|
37 | - * If callable $exitHandler is defined, it will be called instead of exit(). |
|
38 | - * |
|
39 | - * @param string $url |
|
40 | - * |
|
41 | - * @return mixed |
|
42 | - */ |
|
43 | - public static function redirect($url) |
|
44 | - { |
|
45 | - if (static::$redirectHandler) { |
|
46 | - return call_user_func(static::$redirectHandler, $url); |
|
47 | - } |
|
31 | + /** |
|
32 | + * Redirect to a given URL. |
|
33 | + * |
|
34 | + * In case your application need to perform certain required actions before Hybridauth redirect users |
|
35 | + * to IDPs websites, the default behaviour can be altered in one of two ways: |
|
36 | + * If callable $redirectHandler is defined, it will be called instead. |
|
37 | + * If callable $exitHandler is defined, it will be called instead of exit(). |
|
38 | + * |
|
39 | + * @param string $url |
|
40 | + * |
|
41 | + * @return mixed |
|
42 | + */ |
|
43 | + public static function redirect($url) |
|
44 | + { |
|
45 | + if (static::$redirectHandler) { |
|
46 | + return call_user_func(static::$redirectHandler, $url); |
|
47 | + } |
|
48 | 48 | |
49 | - header(sprintf('Location: %s', $url)); |
|
49 | + header(sprintf('Location: %s', $url)); |
|
50 | 50 | |
51 | - if (static::$exitHandler) { |
|
52 | - return call_user_func(static::$exitHandler); |
|
53 | - } |
|
51 | + if (static::$exitHandler) { |
|
52 | + return call_user_func(static::$exitHandler); |
|
53 | + } |
|
54 | 54 | |
55 | - exit(1); |
|
56 | - } |
|
55 | + exit(1); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Redirect handler to which the regular redirect() will yield the action of redirecting users. |
|
60 | - * |
|
61 | - * @param callable $callback |
|
62 | - */ |
|
63 | - public static function setRedirectHandler($callback) |
|
64 | - { |
|
65 | - self::$redirectHandler = $callback; |
|
66 | - } |
|
58 | + /** |
|
59 | + * Redirect handler to which the regular redirect() will yield the action of redirecting users. |
|
60 | + * |
|
61 | + * @param callable $callback |
|
62 | + */ |
|
63 | + public static function setRedirectHandler($callback) |
|
64 | + { |
|
65 | + self::$redirectHandler = $callback; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Exit handler will be called instead of regular exit() when calling Util::redirect() method. |
|
70 | - * |
|
71 | - * @param callable $callback |
|
72 | - */ |
|
73 | - public static function setExitHandler($callback) |
|
74 | - { |
|
75 | - self::$exitHandler = $callback; |
|
76 | - } |
|
68 | + /** |
|
69 | + * Exit handler will be called instead of regular exit() when calling Util::redirect() method. |
|
70 | + * |
|
71 | + * @param callable $callback |
|
72 | + */ |
|
73 | + public static function setExitHandler($callback) |
|
74 | + { |
|
75 | + self::$exitHandler = $callback; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Returns the Current URL. |
|
80 | - * |
|
81 | - * @param bool $requestUri TRUE to use $_SERVER['REQUEST_URI'], FALSE for $_SERVER['PHP_SELF'] |
|
82 | - * |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public static function getCurrentUrl($requestUri = false) |
|
86 | - { |
|
87 | - $collection = new Data\Collection($_SERVER); |
|
78 | + /** |
|
79 | + * Returns the Current URL. |
|
80 | + * |
|
81 | + * @param bool $requestUri TRUE to use $_SERVER['REQUEST_URI'], FALSE for $_SERVER['PHP_SELF'] |
|
82 | + * |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public static function getCurrentUrl($requestUri = false) |
|
86 | + { |
|
87 | + $collection = new Data\Collection($_SERVER); |
|
88 | 88 | |
89 | - $protocol = 'http://'; |
|
89 | + $protocol = 'http://'; |
|
90 | 90 | |
91 | - if (($collection->get('HTTPS') && $collection->get('HTTPS') !== 'off') || |
|
92 | - $collection->get('HTTP_X_FORWARDED_PROTO') === 'https') { |
|
93 | - $protocol = 'https://'; |
|
94 | - } |
|
91 | + if (($collection->get('HTTPS') && $collection->get('HTTPS') !== 'off') || |
|
92 | + $collection->get('HTTP_X_FORWARDED_PROTO') === 'https') { |
|
93 | + $protocol = 'https://'; |
|
94 | + } |
|
95 | 95 | |
96 | - return $protocol . |
|
97 | - $collection->get('HTTP_HOST') . |
|
98 | - $collection->get($requestUri ? 'REQUEST_URI' : 'PHP_SELF'); |
|
99 | - } |
|
96 | + return $protocol . |
|
97 | + $collection->get('HTTP_HOST') . |
|
98 | + $collection->get($requestUri ? 'REQUEST_URI' : 'PHP_SELF'); |
|
99 | + } |
|
100 | 100 | } |
@@ -93,8 +93,8 @@ |
||
93 | 93 | $protocol = 'https://'; |
94 | 94 | } |
95 | 95 | |
96 | - return $protocol . |
|
97 | - $collection->get('HTTP_HOST') . |
|
96 | + return $protocol. |
|
97 | + $collection->get('HTTP_HOST'). |
|
98 | 98 | $collection->get($requestUri ? 'REQUEST_URI' : 'PHP_SELF'); |
99 | 99 | } |
100 | 100 | } |
@@ -17,97 +17,97 @@ |
||
17 | 17 | */ |
18 | 18 | class Paypal extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = 'openid profile email address'; |
|
24 | - |
|
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $apiBaseUrl = 'https://api.paypal.com/'; |
|
29 | - |
|
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $authorizeUrl = 'https://www.paypal.com/signin/authorize'; |
|
34 | - |
|
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://api.paypal.com/v1/oauth2/token'; |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://developer.paypal.com/docs/api/overview/#'; |
|
44 | - |
|
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - protected function initialize() |
|
49 | - { |
|
50 | - parent::initialize(); |
|
51 | - |
|
52 | - $this->AuthorizeUrlParameters += [ |
|
53 | - 'flowEntry' => 'static' |
|
54 | - ]; |
|
55 | - |
|
56 | - $this->tokenExchangeHeaders = [ |
|
57 | - 'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret) |
|
58 | - ]; |
|
59 | - |
|
60 | - $this->tokenRefreshHeaders = [ |
|
61 | - 'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret) |
|
62 | - ]; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * {@inheritdoc} |
|
67 | - * |
|
68 | - * See: https://developer.paypal.com/docs/api/identity/v1/ |
|
69 | - * See: https://developer.paypal.com/docs/connect-with-paypal/integrate/ |
|
70 | - */ |
|
71 | - public function getUserProfile() |
|
72 | - { |
|
73 | - $headers = [ |
|
74 | - 'Content-Type' => 'application/json', |
|
75 | - ]; |
|
76 | - |
|
77 | - $parameters = [ |
|
78 | - 'schema' => 'paypalv1.1' |
|
79 | - ]; |
|
80 | - |
|
81 | - $response = $this->apiRequest('v1/identity/oauth2/userinfo', 'GET', $parameters, $headers); |
|
82 | - $data = new Data\Collection($response); |
|
83 | - |
|
84 | - if (!$data->exists('user_id')) { |
|
85 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
86 | - } |
|
87 | - |
|
88 | - $userProfile = new User\Profile(); |
|
89 | - $userProfile->identifier = $data->get('user_id'); |
|
90 | - $userProfile->firstName = $data->get('given_name'); |
|
91 | - $userProfile->lastName = $data->get('family_name'); |
|
92 | - $userProfile->displayName = $data->get('name'); |
|
93 | - $userProfile->address = $data->filter('address')->get('street_address'); |
|
94 | - $userProfile->city = $data->filter('address')->get('locality'); |
|
95 | - $userProfile->country = $data->filter('address')->get('country'); |
|
96 | - $userProfile->region = $data->filter('address')->get('region'); |
|
97 | - $userProfile->zip = $data->filter('address')->get('postal_code'); |
|
98 | - |
|
99 | - $emails = $data->filter('emails')->toArray(); |
|
100 | - foreach ($emails as $email) { |
|
101 | - $email = new Data\Collection($email); |
|
102 | - if ($email->get('confirmed')) { |
|
103 | - $userProfile->emailVerified = $email->get('value'); |
|
104 | - } |
|
105 | - |
|
106 | - if ($email->get('primary')) { |
|
107 | - $userProfile->email = $email->get('value'); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - return $userProfile; |
|
112 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = 'openid profile email address'; |
|
24 | + |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $apiBaseUrl = 'https://api.paypal.com/'; |
|
29 | + |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $authorizeUrl = 'https://www.paypal.com/signin/authorize'; |
|
34 | + |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://api.paypal.com/v1/oauth2/token'; |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://developer.paypal.com/docs/api/overview/#'; |
|
44 | + |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + protected function initialize() |
|
49 | + { |
|
50 | + parent::initialize(); |
|
51 | + |
|
52 | + $this->AuthorizeUrlParameters += [ |
|
53 | + 'flowEntry' => 'static' |
|
54 | + ]; |
|
55 | + |
|
56 | + $this->tokenExchangeHeaders = [ |
|
57 | + 'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret) |
|
58 | + ]; |
|
59 | + |
|
60 | + $this->tokenRefreshHeaders = [ |
|
61 | + 'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret) |
|
62 | + ]; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * {@inheritdoc} |
|
67 | + * |
|
68 | + * See: https://developer.paypal.com/docs/api/identity/v1/ |
|
69 | + * See: https://developer.paypal.com/docs/connect-with-paypal/integrate/ |
|
70 | + */ |
|
71 | + public function getUserProfile() |
|
72 | + { |
|
73 | + $headers = [ |
|
74 | + 'Content-Type' => 'application/json', |
|
75 | + ]; |
|
76 | + |
|
77 | + $parameters = [ |
|
78 | + 'schema' => 'paypalv1.1' |
|
79 | + ]; |
|
80 | + |
|
81 | + $response = $this->apiRequest('v1/identity/oauth2/userinfo', 'GET', $parameters, $headers); |
|
82 | + $data = new Data\Collection($response); |
|
83 | + |
|
84 | + if (!$data->exists('user_id')) { |
|
85 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
86 | + } |
|
87 | + |
|
88 | + $userProfile = new User\Profile(); |
|
89 | + $userProfile->identifier = $data->get('user_id'); |
|
90 | + $userProfile->firstName = $data->get('given_name'); |
|
91 | + $userProfile->lastName = $data->get('family_name'); |
|
92 | + $userProfile->displayName = $data->get('name'); |
|
93 | + $userProfile->address = $data->filter('address')->get('street_address'); |
|
94 | + $userProfile->city = $data->filter('address')->get('locality'); |
|
95 | + $userProfile->country = $data->filter('address')->get('country'); |
|
96 | + $userProfile->region = $data->filter('address')->get('region'); |
|
97 | + $userProfile->zip = $data->filter('address')->get('postal_code'); |
|
98 | + |
|
99 | + $emails = $data->filter('emails')->toArray(); |
|
100 | + foreach ($emails as $email) { |
|
101 | + $email = new Data\Collection($email); |
|
102 | + if ($email->get('confirmed')) { |
|
103 | + $userProfile->emailVerified = $email->get('value'); |
|
104 | + } |
|
105 | + |
|
106 | + if ($email->get('primary')) { |
|
107 | + $userProfile->email = $email->get('value'); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + return $userProfile; |
|
112 | + } |
|
113 | 113 | } |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | ]; |
55 | 55 | |
56 | 56 | $this->tokenExchangeHeaders = [ |
57 | - 'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret) |
|
57 | + 'Authorization' => 'Basic '.base64_encode($this->clientId.':'.$this->clientSecret) |
|
58 | 58 | ]; |
59 | 59 | |
60 | 60 | $this->tokenRefreshHeaders = [ |
61 | - 'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret) |
|
61 | + 'Authorization' => 'Basic '.base64_encode($this->clientId.':'.$this->clientSecret) |
|
62 | 62 | ]; |
63 | 63 | } |
64 | 64 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $response = $this->apiRequest('v1/identity/oauth2/userinfo', 'GET', $parameters, $headers); |
82 | 82 | $data = new Data\Collection($response); |
83 | 83 | |
84 | - if (!$data->exists('user_id')) { |
|
84 | + if ( ! $data->exists('user_id')) { |
|
85 | 85 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
86 | 86 | } |
87 | 87 |
@@ -17,52 +17,52 @@ |
||
17 | 17 | */ |
18 | 18 | class Dribbble extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $apiBaseUrl = 'https://api.dribbble.com/v2/'; |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $apiBaseUrl = 'https://api.dribbble.com/v2/'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $authorizeUrl = 'https://dribbble.com/oauth/authorize'; |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $authorizeUrl = 'https://dribbble.com/oauth/authorize'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $accessTokenUrl = 'https://dribbble.com/oauth/token'; |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $accessTokenUrl = 'https://dribbble.com/oauth/token'; |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $apiDocumentation = 'http://developer.dribbble.com/v2/oauth/'; |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $apiDocumentation = 'http://developer.dribbble.com/v2/oauth/'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - public function getUserProfile() |
|
44 | - { |
|
45 | - $response = $this->apiRequest('user'); |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + public function getUserProfile() |
|
44 | + { |
|
45 | + $response = $this->apiRequest('user'); |
|
46 | 46 | |
47 | - $data = new Data\Collection($response); |
|
47 | + $data = new Data\Collection($response); |
|
48 | 48 | |
49 | - if (!$data->exists('id')) { |
|
50 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
51 | - } |
|
49 | + if (!$data->exists('id')) { |
|
50 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
51 | + } |
|
52 | 52 | |
53 | - $userProfile = new User\Profile(); |
|
53 | + $userProfile = new User\Profile(); |
|
54 | 54 | |
55 | - $userProfile->identifier = $data->get('id'); |
|
56 | - $userProfile->profileURL = $data->get('html_url'); |
|
57 | - $userProfile->photoURL = $data->get('avatar_url'); |
|
58 | - $userProfile->description = $data->get('bio'); |
|
59 | - $userProfile->region = $data->get('location'); |
|
60 | - $userProfile->displayName = $data->get('name'); |
|
55 | + $userProfile->identifier = $data->get('id'); |
|
56 | + $userProfile->profileURL = $data->get('html_url'); |
|
57 | + $userProfile->photoURL = $data->get('avatar_url'); |
|
58 | + $userProfile->description = $data->get('bio'); |
|
59 | + $userProfile->region = $data->get('location'); |
|
60 | + $userProfile->displayName = $data->get('name'); |
|
61 | 61 | |
62 | - $userProfile->displayName = $userProfile->displayName ?: $data->get('username'); |
|
62 | + $userProfile->displayName = $userProfile->displayName ?: $data->get('username'); |
|
63 | 63 | |
64 | - $userProfile->webSiteURL = $data->filter('links')->get('web'); |
|
64 | + $userProfile->webSiteURL = $data->filter('links')->get('web'); |
|
65 | 65 | |
66 | - return $userProfile; |
|
67 | - } |
|
66 | + return $userProfile; |
|
67 | + } |
|
68 | 68 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | |
52 | 52 | $data = new Data\Collection($response); |
53 | 53 | |
54 | - if (!$data->exists('id')) { |
|
54 | + if ( ! $data->exists('id')) { |
|
55 | 55 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
56 | 56 | } |
57 | 57 |
@@ -17,226 +17,226 @@ |
||
17 | 17 | */ |
18 | 18 | class ORCID extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = '/authenticate'; |
|
24 | - |
|
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $apiBaseUrl = 'https://pub.orcid.org/v2.1/'; |
|
29 | - |
|
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $authorizeUrl = 'https://orcid.org/oauth/authorize'; |
|
34 | - |
|
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://orcid.org/oauth/token'; |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://members.orcid.org/api/'; |
|
44 | - |
|
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - protected function validateAccessTokenExchange($response) |
|
49 | - { |
|
50 | - $data = parent::validateAccessTokenExchange($response); |
|
51 | - $this->storeData('orcid', $data->get('orcid')); |
|
52 | - return $data; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * {@inheritdoc} |
|
57 | - */ |
|
58 | - public function getUserProfile() |
|
59 | - { |
|
60 | - $response = $this->apiRequest($this->getStoredData('orcid') . '/record'); |
|
61 | - $data = new Data\Collection($response['record']); |
|
62 | - |
|
63 | - if (!$data->exists('orcid-identifier')) { |
|
64 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
65 | - } |
|
66 | - |
|
67 | - $profile = new User\Profile(); |
|
68 | - |
|
69 | - $profile = $this->getDetails($profile, $data); |
|
70 | - $profile = $this->getBiography($profile, $data); |
|
71 | - $profile = $this->getWebsite($profile, $data); |
|
72 | - $profile = $this->getName($profile, $data); |
|
73 | - $profile = $this->getEmail($profile, $data); |
|
74 | - $profile = $this->getLanguage($profile, $data); |
|
75 | - $profile = $this->getAddress($profile, $data); |
|
76 | - |
|
77 | - return $profile; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Get profile details. |
|
82 | - * |
|
83 | - * @param User\Profile $profile |
|
84 | - * @param Data\Collection $data |
|
85 | - * |
|
86 | - * @return User\Profile |
|
87 | - */ |
|
88 | - protected function getDetails(User\Profile $profile, Data\Collection $data) |
|
89 | - { |
|
90 | - $data = new Data\Collection($data->get('orcid-identifier')); |
|
91 | - |
|
92 | - $profile->identifier = $data->get('path'); |
|
93 | - $profile->profileURL = $data->get('uri'); |
|
94 | - |
|
95 | - return $profile; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Get profile biography. |
|
100 | - * |
|
101 | - * @param User\Profile $profile |
|
102 | - * @param Data\Collection $data |
|
103 | - * |
|
104 | - * @return User\Profile |
|
105 | - */ |
|
106 | - protected function getBiography(User\Profile $profile, Data\Collection $data) |
|
107 | - { |
|
108 | - $data = new Data\Collection($data->get('person')); |
|
109 | - $data = new Data\Collection($data->get('biography')); |
|
110 | - |
|
111 | - $profile->description = $data->get('content'); |
|
112 | - |
|
113 | - return $profile; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Get profile website. |
|
118 | - * |
|
119 | - * @param User\Profile $profile |
|
120 | - * @param Data\Collection $data |
|
121 | - * |
|
122 | - * @return User\Profile |
|
123 | - */ |
|
124 | - protected function getWebsite(User\Profile $profile, Data\Collection $data) |
|
125 | - { |
|
126 | - $data = new Data\Collection($data->get('person')); |
|
127 | - $data = new Data\Collection($data->get('researcher-urls')); |
|
128 | - $data = new Data\Collection($data->get('researcher-url')); |
|
129 | - |
|
130 | - if ($data->exists(0)) { |
|
131 | - $data = new Data\Collection($data->get(0)); |
|
132 | - } |
|
133 | - |
|
134 | - $profile->webSiteURL = $data->get('url'); |
|
135 | - |
|
136 | - return $profile; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Get profile name. |
|
141 | - * |
|
142 | - * @param User\Profile $profile |
|
143 | - * @param Data\Collection $data |
|
144 | - * |
|
145 | - * @return User\Profile |
|
146 | - */ |
|
147 | - protected function getName(User\Profile $profile, Data\Collection $data) |
|
148 | - { |
|
149 | - $data = new Data\Collection($data->get('person')); |
|
150 | - $data = new Data\Collection($data->get('name')); |
|
151 | - |
|
152 | - if ($data->exists('credit-name')) { |
|
153 | - $profile->displayName = $data->get('credit-name'); |
|
154 | - } else { |
|
155 | - $profile->displayName = $data->get('given-names') . ' ' . $data->get('family-name'); |
|
156 | - } |
|
157 | - |
|
158 | - $profile->firstName = $data->get('given-names'); |
|
159 | - $profile->lastName = $data->get('family-name'); |
|
160 | - |
|
161 | - return $profile; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Get profile email. |
|
166 | - * |
|
167 | - * @param User\Profile $profile |
|
168 | - * @param Data\Collection $data |
|
169 | - * |
|
170 | - * @return User\Profile |
|
171 | - */ |
|
172 | - protected function getEmail(User\Profile $profile, Data\Collection $data) |
|
173 | - { |
|
174 | - $data = new Data\Collection($data->get('person')); |
|
175 | - $data = new Data\Collection($data->get('emails')); |
|
176 | - $data = new Data\Collection($data->get('email')); |
|
177 | - |
|
178 | - if (!$data->exists(0)) { |
|
179 | - $email = $data; |
|
180 | - } else { |
|
181 | - $email = new Data\Collection($data->get(0)); |
|
182 | - |
|
183 | - $i = 1; |
|
184 | - while ($email->get('@attributes')['primary'] == 'false') { |
|
185 | - $email = new Data\Collection($data->get($i)); |
|
186 | - $i++; |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - if ($email->get('@attributes')['primary'] == 'false') { |
|
191 | - return $profile; |
|
192 | - } |
|
193 | - |
|
194 | - $profile->email = $email->get('email'); |
|
195 | - |
|
196 | - if ($email->get('@attributes')['verified'] == 'true') { |
|
197 | - $profile->emailVerified = $email->get('email'); |
|
198 | - } |
|
199 | - |
|
200 | - return $profile; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Get profile language. |
|
205 | - * |
|
206 | - * @param User\Profile $profile |
|
207 | - * @param Data\Collection $data |
|
208 | - * |
|
209 | - * @return User\Profile |
|
210 | - */ |
|
211 | - protected function getLanguage(User\Profile $profile, Data\Collection $data) |
|
212 | - { |
|
213 | - $data = new Data\Collection($data->get('preferences')); |
|
214 | - |
|
215 | - $profile->language = $data->get('locale'); |
|
216 | - |
|
217 | - return $profile; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Get profile address. |
|
222 | - * |
|
223 | - * @param User\Profile $profile |
|
224 | - * @param Data\Collection $data |
|
225 | - * |
|
226 | - * @return User\Profile |
|
227 | - */ |
|
228 | - protected function getAddress(User\Profile $profile, Data\Collection $data) |
|
229 | - { |
|
230 | - $data = new Data\Collection($data->get('person')); |
|
231 | - $data = new Data\Collection($data->get('addresses')); |
|
232 | - $data = new Data\Collection($data->get('address')); |
|
233 | - |
|
234 | - if ($data->exists(0)) { |
|
235 | - $data = new Data\Collection($data->get(0)); |
|
236 | - } |
|
237 | - |
|
238 | - $profile->country = $data->get('country'); |
|
239 | - |
|
240 | - return $profile; |
|
241 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = '/authenticate'; |
|
24 | + |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $apiBaseUrl = 'https://pub.orcid.org/v2.1/'; |
|
29 | + |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $authorizeUrl = 'https://orcid.org/oauth/authorize'; |
|
34 | + |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://orcid.org/oauth/token'; |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://members.orcid.org/api/'; |
|
44 | + |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + protected function validateAccessTokenExchange($response) |
|
49 | + { |
|
50 | + $data = parent::validateAccessTokenExchange($response); |
|
51 | + $this->storeData('orcid', $data->get('orcid')); |
|
52 | + return $data; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * {@inheritdoc} |
|
57 | + */ |
|
58 | + public function getUserProfile() |
|
59 | + { |
|
60 | + $response = $this->apiRequest($this->getStoredData('orcid') . '/record'); |
|
61 | + $data = new Data\Collection($response['record']); |
|
62 | + |
|
63 | + if (!$data->exists('orcid-identifier')) { |
|
64 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
65 | + } |
|
66 | + |
|
67 | + $profile = new User\Profile(); |
|
68 | + |
|
69 | + $profile = $this->getDetails($profile, $data); |
|
70 | + $profile = $this->getBiography($profile, $data); |
|
71 | + $profile = $this->getWebsite($profile, $data); |
|
72 | + $profile = $this->getName($profile, $data); |
|
73 | + $profile = $this->getEmail($profile, $data); |
|
74 | + $profile = $this->getLanguage($profile, $data); |
|
75 | + $profile = $this->getAddress($profile, $data); |
|
76 | + |
|
77 | + return $profile; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Get profile details. |
|
82 | + * |
|
83 | + * @param User\Profile $profile |
|
84 | + * @param Data\Collection $data |
|
85 | + * |
|
86 | + * @return User\Profile |
|
87 | + */ |
|
88 | + protected function getDetails(User\Profile $profile, Data\Collection $data) |
|
89 | + { |
|
90 | + $data = new Data\Collection($data->get('orcid-identifier')); |
|
91 | + |
|
92 | + $profile->identifier = $data->get('path'); |
|
93 | + $profile->profileURL = $data->get('uri'); |
|
94 | + |
|
95 | + return $profile; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Get profile biography. |
|
100 | + * |
|
101 | + * @param User\Profile $profile |
|
102 | + * @param Data\Collection $data |
|
103 | + * |
|
104 | + * @return User\Profile |
|
105 | + */ |
|
106 | + protected function getBiography(User\Profile $profile, Data\Collection $data) |
|
107 | + { |
|
108 | + $data = new Data\Collection($data->get('person')); |
|
109 | + $data = new Data\Collection($data->get('biography')); |
|
110 | + |
|
111 | + $profile->description = $data->get('content'); |
|
112 | + |
|
113 | + return $profile; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Get profile website. |
|
118 | + * |
|
119 | + * @param User\Profile $profile |
|
120 | + * @param Data\Collection $data |
|
121 | + * |
|
122 | + * @return User\Profile |
|
123 | + */ |
|
124 | + protected function getWebsite(User\Profile $profile, Data\Collection $data) |
|
125 | + { |
|
126 | + $data = new Data\Collection($data->get('person')); |
|
127 | + $data = new Data\Collection($data->get('researcher-urls')); |
|
128 | + $data = new Data\Collection($data->get('researcher-url')); |
|
129 | + |
|
130 | + if ($data->exists(0)) { |
|
131 | + $data = new Data\Collection($data->get(0)); |
|
132 | + } |
|
133 | + |
|
134 | + $profile->webSiteURL = $data->get('url'); |
|
135 | + |
|
136 | + return $profile; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Get profile name. |
|
141 | + * |
|
142 | + * @param User\Profile $profile |
|
143 | + * @param Data\Collection $data |
|
144 | + * |
|
145 | + * @return User\Profile |
|
146 | + */ |
|
147 | + protected function getName(User\Profile $profile, Data\Collection $data) |
|
148 | + { |
|
149 | + $data = new Data\Collection($data->get('person')); |
|
150 | + $data = new Data\Collection($data->get('name')); |
|
151 | + |
|
152 | + if ($data->exists('credit-name')) { |
|
153 | + $profile->displayName = $data->get('credit-name'); |
|
154 | + } else { |
|
155 | + $profile->displayName = $data->get('given-names') . ' ' . $data->get('family-name'); |
|
156 | + } |
|
157 | + |
|
158 | + $profile->firstName = $data->get('given-names'); |
|
159 | + $profile->lastName = $data->get('family-name'); |
|
160 | + |
|
161 | + return $profile; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Get profile email. |
|
166 | + * |
|
167 | + * @param User\Profile $profile |
|
168 | + * @param Data\Collection $data |
|
169 | + * |
|
170 | + * @return User\Profile |
|
171 | + */ |
|
172 | + protected function getEmail(User\Profile $profile, Data\Collection $data) |
|
173 | + { |
|
174 | + $data = new Data\Collection($data->get('person')); |
|
175 | + $data = new Data\Collection($data->get('emails')); |
|
176 | + $data = new Data\Collection($data->get('email')); |
|
177 | + |
|
178 | + if (!$data->exists(0)) { |
|
179 | + $email = $data; |
|
180 | + } else { |
|
181 | + $email = new Data\Collection($data->get(0)); |
|
182 | + |
|
183 | + $i = 1; |
|
184 | + while ($email->get('@attributes')['primary'] == 'false') { |
|
185 | + $email = new Data\Collection($data->get($i)); |
|
186 | + $i++; |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + if ($email->get('@attributes')['primary'] == 'false') { |
|
191 | + return $profile; |
|
192 | + } |
|
193 | + |
|
194 | + $profile->email = $email->get('email'); |
|
195 | + |
|
196 | + if ($email->get('@attributes')['verified'] == 'true') { |
|
197 | + $profile->emailVerified = $email->get('email'); |
|
198 | + } |
|
199 | + |
|
200 | + return $profile; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Get profile language. |
|
205 | + * |
|
206 | + * @param User\Profile $profile |
|
207 | + * @param Data\Collection $data |
|
208 | + * |
|
209 | + * @return User\Profile |
|
210 | + */ |
|
211 | + protected function getLanguage(User\Profile $profile, Data\Collection $data) |
|
212 | + { |
|
213 | + $data = new Data\Collection($data->get('preferences')); |
|
214 | + |
|
215 | + $profile->language = $data->get('locale'); |
|
216 | + |
|
217 | + return $profile; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Get profile address. |
|
222 | + * |
|
223 | + * @param User\Profile $profile |
|
224 | + * @param Data\Collection $data |
|
225 | + * |
|
226 | + * @return User\Profile |
|
227 | + */ |
|
228 | + protected function getAddress(User\Profile $profile, Data\Collection $data) |
|
229 | + { |
|
230 | + $data = new Data\Collection($data->get('person')); |
|
231 | + $data = new Data\Collection($data->get('addresses')); |
|
232 | + $data = new Data\Collection($data->get('address')); |
|
233 | + |
|
234 | + if ($data->exists(0)) { |
|
235 | + $data = new Data\Collection($data->get(0)); |
|
236 | + } |
|
237 | + |
|
238 | + $profile->country = $data->get('country'); |
|
239 | + |
|
240 | + return $profile; |
|
241 | + } |
|
242 | 242 | } |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function getUserProfile() |
59 | 59 | { |
60 | - $response = $this->apiRequest($this->getStoredData('orcid') . '/record'); |
|
60 | + $response = $this->apiRequest($this->getStoredData('orcid').'/record'); |
|
61 | 61 | $data = new Data\Collection($response['record']); |
62 | 62 | |
63 | - if (!$data->exists('orcid-identifier')) { |
|
63 | + if ( ! $data->exists('orcid-identifier')) { |
|
64 | 64 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
65 | 65 | } |
66 | 66 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | if ($data->exists('credit-name')) { |
153 | 153 | $profile->displayName = $data->get('credit-name'); |
154 | 154 | } else { |
155 | - $profile->displayName = $data->get('given-names') . ' ' . $data->get('family-name'); |
|
155 | + $profile->displayName = $data->get('given-names').' '.$data->get('family-name'); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | $profile->firstName = $data->get('given-names'); |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | $data = new Data\Collection($data->get('emails')); |
176 | 176 | $data = new Data\Collection($data->get('email')); |
177 | 177 | |
178 | - if (!$data->exists(0)) { |
|
178 | + if ( ! $data->exists(0)) { |
|
179 | 179 | $email = $data; |
180 | 180 | } else { |
181 | 181 | $email = new Data\Collection($data->get(0)); |
@@ -21,91 +21,91 @@ |
||
21 | 21 | */ |
22 | 22 | class BitBucket extends OAuth2 |
23 | 23 | { |
24 | - /** |
|
25 | - * {@inheritdoc} |
|
26 | - */ |
|
27 | - protected $scope = 'email'; |
|
28 | - |
|
29 | - /** |
|
30 | - * {@inheritdoc} |
|
31 | - */ |
|
32 | - protected $apiBaseUrl = 'https://api.bitbucket.org/2.0/'; |
|
33 | - |
|
34 | - /** |
|
35 | - * {@inheritdoc} |
|
36 | - */ |
|
37 | - protected $authorizeUrl = 'https://bitbucket.org/site/oauth2/authorize'; |
|
38 | - |
|
39 | - /** |
|
40 | - * {@inheritdoc} |
|
41 | - */ |
|
42 | - protected $accessTokenUrl = 'https://bitbucket.org/site/oauth2/access_token'; |
|
43 | - |
|
44 | - /** |
|
45 | - * {@inheritdoc} |
|
46 | - */ |
|
47 | - protected $apiDocumentation = 'https://developer.atlassian.com/bitbucket/concepts/oauth2.html'; |
|
48 | - |
|
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function getUserProfile() |
|
53 | - { |
|
54 | - $response = $this->apiRequest('user'); |
|
55 | - |
|
56 | - $data = new Data\Collection($response); |
|
57 | - |
|
58 | - if (!$data->exists('uuid')) { |
|
59 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
60 | - } |
|
61 | - |
|
62 | - $userProfile = new User\Profile(); |
|
63 | - |
|
64 | - $userProfile->identifier = $data->get('uuid'); |
|
65 | - $userProfile->profileURL = 'https://bitbucket.org/' . $data->get('username') . '/'; |
|
66 | - $userProfile->displayName = $data->get('display_name'); |
|
67 | - $userProfile->email = $data->get('email'); |
|
68 | - $userProfile->webSiteURL = $data->get('website'); |
|
69 | - $userProfile->region = $data->get('location'); |
|
70 | - |
|
71 | - $userProfile->displayName = $userProfile->displayName ?: $data->get('username'); |
|
72 | - |
|
73 | - if (empty($userProfile->email) && strpos($this->scope, 'email') !== false) { |
|
74 | - try { |
|
75 | - // user email is not mandatory so keep it quiet |
|
76 | - $userProfile = $this->requestUserEmail($userProfile); |
|
77 | - } catch (\Exception $e) { |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - return $userProfile; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Request user email |
|
86 | - * |
|
87 | - * @param $userProfile |
|
88 | - * |
|
89 | - * @return User\Profile |
|
90 | - * |
|
91 | - * @throws \Exception |
|
92 | - */ |
|
93 | - protected function requestUserEmail($userProfile) |
|
94 | - { |
|
95 | - $response = $this->apiRequest('user/emails'); |
|
96 | - |
|
97 | - foreach ($response->values as $idx => $item) { |
|
98 | - if (!empty($item->is_primary) && $item->is_primary == true) { |
|
99 | - $userProfile->email = $item->email; |
|
100 | - |
|
101 | - if (!empty($item->is_confirmed) && $item->is_confirmed == true) { |
|
102 | - $userProfile->emailVerified = $userProfile->email; |
|
103 | - } |
|
104 | - |
|
105 | - break; |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - return $userProfile; |
|
110 | - } |
|
24 | + /** |
|
25 | + * {@inheritdoc} |
|
26 | + */ |
|
27 | + protected $scope = 'email'; |
|
28 | + |
|
29 | + /** |
|
30 | + * {@inheritdoc} |
|
31 | + */ |
|
32 | + protected $apiBaseUrl = 'https://api.bitbucket.org/2.0/'; |
|
33 | + |
|
34 | + /** |
|
35 | + * {@inheritdoc} |
|
36 | + */ |
|
37 | + protected $authorizeUrl = 'https://bitbucket.org/site/oauth2/authorize'; |
|
38 | + |
|
39 | + /** |
|
40 | + * {@inheritdoc} |
|
41 | + */ |
|
42 | + protected $accessTokenUrl = 'https://bitbucket.org/site/oauth2/access_token'; |
|
43 | + |
|
44 | + /** |
|
45 | + * {@inheritdoc} |
|
46 | + */ |
|
47 | + protected $apiDocumentation = 'https://developer.atlassian.com/bitbucket/concepts/oauth2.html'; |
|
48 | + |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function getUserProfile() |
|
53 | + { |
|
54 | + $response = $this->apiRequest('user'); |
|
55 | + |
|
56 | + $data = new Data\Collection($response); |
|
57 | + |
|
58 | + if (!$data->exists('uuid')) { |
|
59 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
60 | + } |
|
61 | + |
|
62 | + $userProfile = new User\Profile(); |
|
63 | + |
|
64 | + $userProfile->identifier = $data->get('uuid'); |
|
65 | + $userProfile->profileURL = 'https://bitbucket.org/' . $data->get('username') . '/'; |
|
66 | + $userProfile->displayName = $data->get('display_name'); |
|
67 | + $userProfile->email = $data->get('email'); |
|
68 | + $userProfile->webSiteURL = $data->get('website'); |
|
69 | + $userProfile->region = $data->get('location'); |
|
70 | + |
|
71 | + $userProfile->displayName = $userProfile->displayName ?: $data->get('username'); |
|
72 | + |
|
73 | + if (empty($userProfile->email) && strpos($this->scope, 'email') !== false) { |
|
74 | + try { |
|
75 | + // user email is not mandatory so keep it quiet |
|
76 | + $userProfile = $this->requestUserEmail($userProfile); |
|
77 | + } catch (\Exception $e) { |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + return $userProfile; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Request user email |
|
86 | + * |
|
87 | + * @param $userProfile |
|
88 | + * |
|
89 | + * @return User\Profile |
|
90 | + * |
|
91 | + * @throws \Exception |
|
92 | + */ |
|
93 | + protected function requestUserEmail($userProfile) |
|
94 | + { |
|
95 | + $response = $this->apiRequest('user/emails'); |
|
96 | + |
|
97 | + foreach ($response->values as $idx => $item) { |
|
98 | + if (!empty($item->is_primary) && $item->is_primary == true) { |
|
99 | + $userProfile->email = $item->email; |
|
100 | + |
|
101 | + if (!empty($item->is_confirmed) && $item->is_confirmed == true) { |
|
102 | + $userProfile->emailVerified = $userProfile->email; |
|
103 | + } |
|
104 | + |
|
105 | + break; |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + return $userProfile; |
|
110 | + } |
|
111 | 111 | } |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | |
56 | 56 | $data = new Data\Collection($response); |
57 | 57 | |
58 | - if (!$data->exists('uuid')) { |
|
58 | + if ( ! $data->exists('uuid')) { |
|
59 | 59 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
60 | 60 | } |
61 | 61 | |
62 | 62 | $userProfile = new User\Profile(); |
63 | 63 | |
64 | 64 | $userProfile->identifier = $data->get('uuid'); |
65 | - $userProfile->profileURL = 'https://bitbucket.org/' . $data->get('username') . '/'; |
|
65 | + $userProfile->profileURL = 'https://bitbucket.org/'.$data->get('username').'/'; |
|
66 | 66 | $userProfile->displayName = $data->get('display_name'); |
67 | 67 | $userProfile->email = $data->get('email'); |
68 | 68 | $userProfile->webSiteURL = $data->get('website'); |
@@ -95,10 +95,10 @@ discard block |
||
95 | 95 | $response = $this->apiRequest('user/emails'); |
96 | 96 | |
97 | 97 | foreach ($response->values as $idx => $item) { |
98 | - if (!empty($item->is_primary) && $item->is_primary == true) { |
|
98 | + if ( ! empty($item->is_primary) && $item->is_primary == true) { |
|
99 | 99 | $userProfile->email = $item->email; |
100 | 100 | |
101 | - if (!empty($item->is_confirmed) && $item->is_confirmed == true) { |
|
101 | + if ( ! empty($item->is_confirmed) && $item->is_confirmed == true) { |
|
102 | 102 | $userProfile->emailVerified = $userProfile->email; |
103 | 103 | } |
104 | 104 |
@@ -17,75 +17,75 @@ |
||
17 | 17 | */ |
18 | 18 | class Reddit extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = 'identity'; |
|
24 | - |
|
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $apiBaseUrl = 'https://oauth.reddit.com/api/v1/'; |
|
29 | - |
|
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $authorizeUrl = 'https://ssl.reddit.com/api/v1/authorize'; |
|
34 | - |
|
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://ssl.reddit.com/api/v1/access_token'; |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://github.com/reddit/reddit/wiki/OAuth2'; |
|
44 | - |
|
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - protected function initialize() |
|
49 | - { |
|
50 | - parent::initialize(); |
|
51 | - |
|
52 | - $this->AuthorizeUrlParameters += [ |
|
53 | - 'duration' => 'permanent' |
|
54 | - ]; |
|
55 | - |
|
56 | - $this->tokenExchangeParameters = [ |
|
57 | - 'client_id' => $this->clientId, |
|
58 | - 'grant_type' => 'authorization_code', |
|
59 | - 'redirect_uri' => $this->callback |
|
60 | - ]; |
|
61 | - |
|
62 | - $this->tokenExchangeHeaders = [ |
|
63 | - 'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret) |
|
64 | - ]; |
|
65 | - |
|
66 | - $this->tokenRefreshHeaders = $this->tokenExchangeHeaders; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * {@inheritdoc} |
|
71 | - */ |
|
72 | - public function getUserProfile() |
|
73 | - { |
|
74 | - $response = $this->apiRequest('me.json'); |
|
75 | - |
|
76 | - $data = new Data\Collection($response); |
|
77 | - |
|
78 | - if (!$data->exists('id')) { |
|
79 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
80 | - } |
|
81 | - |
|
82 | - $userProfile = new User\Profile(); |
|
83 | - |
|
84 | - $userProfile->identifier = $data->get('id'); |
|
85 | - $userProfile->displayName = $data->get('name'); |
|
86 | - $userProfile->profileURL = 'https://www.reddit.com/user/' . $data->get('name') . '/'; |
|
87 | - $userProfile->photoURL = $data->get('icon_img'); |
|
88 | - |
|
89 | - return $userProfile; |
|
90 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = 'identity'; |
|
24 | + |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $apiBaseUrl = 'https://oauth.reddit.com/api/v1/'; |
|
29 | + |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $authorizeUrl = 'https://ssl.reddit.com/api/v1/authorize'; |
|
34 | + |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://ssl.reddit.com/api/v1/access_token'; |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://github.com/reddit/reddit/wiki/OAuth2'; |
|
44 | + |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + protected function initialize() |
|
49 | + { |
|
50 | + parent::initialize(); |
|
51 | + |
|
52 | + $this->AuthorizeUrlParameters += [ |
|
53 | + 'duration' => 'permanent' |
|
54 | + ]; |
|
55 | + |
|
56 | + $this->tokenExchangeParameters = [ |
|
57 | + 'client_id' => $this->clientId, |
|
58 | + 'grant_type' => 'authorization_code', |
|
59 | + 'redirect_uri' => $this->callback |
|
60 | + ]; |
|
61 | + |
|
62 | + $this->tokenExchangeHeaders = [ |
|
63 | + 'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret) |
|
64 | + ]; |
|
65 | + |
|
66 | + $this->tokenRefreshHeaders = $this->tokenExchangeHeaders; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * {@inheritdoc} |
|
71 | + */ |
|
72 | + public function getUserProfile() |
|
73 | + { |
|
74 | + $response = $this->apiRequest('me.json'); |
|
75 | + |
|
76 | + $data = new Data\Collection($response); |
|
77 | + |
|
78 | + if (!$data->exists('id')) { |
|
79 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
80 | + } |
|
81 | + |
|
82 | + $userProfile = new User\Profile(); |
|
83 | + |
|
84 | + $userProfile->identifier = $data->get('id'); |
|
85 | + $userProfile->displayName = $data->get('name'); |
|
86 | + $userProfile->profileURL = 'https://www.reddit.com/user/' . $data->get('name') . '/'; |
|
87 | + $userProfile->photoURL = $data->get('icon_img'); |
|
88 | + |
|
89 | + return $userProfile; |
|
90 | + } |
|
91 | 91 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | ]; |
61 | 61 | |
62 | 62 | $this->tokenExchangeHeaders = [ |
63 | - 'Authorization' => 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret) |
|
63 | + 'Authorization' => 'Basic '.base64_encode($this->clientId.':'.$this->clientSecret) |
|
64 | 64 | ]; |
65 | 65 | |
66 | 66 | $this->tokenRefreshHeaders = $this->tokenExchangeHeaders; |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | $data = new Data\Collection($response); |
77 | 77 | |
78 | - if (!$data->exists('id')) { |
|
78 | + if ( ! $data->exists('id')) { |
|
79 | 79 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
80 | 80 | } |
81 | 81 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | $userProfile->identifier = $data->get('id'); |
85 | 85 | $userProfile->displayName = $data->get('name'); |
86 | - $userProfile->profileURL = 'https://www.reddit.com/user/' . $data->get('name') . '/'; |
|
86 | + $userProfile->profileURL = 'https://www.reddit.com/user/'.$data->get('name').'/'; |
|
87 | 87 | $userProfile->photoURL = $data->get('icon_img'); |
88 | 88 | |
89 | 89 | return $userProfile; |
@@ -17,52 +17,52 @@ |
||
17 | 17 | */ |
18 | 18 | class WordPress extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $apiBaseUrl = 'https://public-api.wordpress.com/rest/v1/'; |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $apiBaseUrl = 'https://public-api.wordpress.com/rest/v1/'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $authorizeUrl = 'https://public-api.wordpress.com/oauth2/authenticate'; |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $authorizeUrl = 'https://public-api.wordpress.com/oauth2/authenticate'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $accessTokenUrl = 'https://public-api.wordpress.com/oauth2/token'; |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $accessTokenUrl = 'https://public-api.wordpress.com/oauth2/token'; |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $apiDocumentation = 'https://developer.wordpress.com/docs/api/'; |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $apiDocumentation = 'https://developer.wordpress.com/docs/api/'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - public function getUserProfile() |
|
44 | - { |
|
45 | - $response = $this->apiRequest('me/'); |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + public function getUserProfile() |
|
44 | + { |
|
45 | + $response = $this->apiRequest('me/'); |
|
46 | 46 | |
47 | - $data = new Data\Collection($response); |
|
47 | + $data = new Data\Collection($response); |
|
48 | 48 | |
49 | - if (!$data->exists('ID')) { |
|
50 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
51 | - } |
|
49 | + if (!$data->exists('ID')) { |
|
50 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
51 | + } |
|
52 | 52 | |
53 | - $userProfile = new User\Profile(); |
|
53 | + $userProfile = new User\Profile(); |
|
54 | 54 | |
55 | - $userProfile->identifier = $data->get('ID'); |
|
56 | - $userProfile->displayName = $data->get('display_name'); |
|
57 | - $userProfile->photoURL = $data->get('avatar_URL'); |
|
58 | - $userProfile->profileURL = $data->get('profile_URL'); |
|
59 | - $userProfile->email = $data->get('email'); |
|
60 | - $userProfile->language = $data->get('language'); |
|
55 | + $userProfile->identifier = $data->get('ID'); |
|
56 | + $userProfile->displayName = $data->get('display_name'); |
|
57 | + $userProfile->photoURL = $data->get('avatar_URL'); |
|
58 | + $userProfile->profileURL = $data->get('profile_URL'); |
|
59 | + $userProfile->email = $data->get('email'); |
|
60 | + $userProfile->language = $data->get('language'); |
|
61 | 61 | |
62 | - $userProfile->displayName = $userProfile->displayName ?: $data->get('username'); |
|
62 | + $userProfile->displayName = $userProfile->displayName ?: $data->get('username'); |
|
63 | 63 | |
64 | - $userProfile->emailVerified = $data->get('email_verified') ? $data->get('email') : ''; |
|
64 | + $userProfile->emailVerified = $data->get('email_verified') ? $data->get('email') : ''; |
|
65 | 65 | |
66 | - return $userProfile; |
|
67 | - } |
|
66 | + return $userProfile; |
|
67 | + } |
|
68 | 68 | } |
@@ -46,7 +46,7 @@ |
||
46 | 46 | |
47 | 47 | $data = new Data\Collection($response); |
48 | 48 | |
49 | - if (!$data->exists('ID')) { |
|
49 | + if ( ! $data->exists('ID')) { |
|
50 | 50 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
51 | 51 | } |
52 | 52 |
@@ -14,13 +14,13 @@ |
||
14 | 14 | */ |
15 | 15 | class AOLOpenID extends OpenID |
16 | 16 | { |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - */ |
|
20 | - protected $openidIdentifier = 'http://openid.aol.com/'; |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + */ |
|
20 | + protected $openidIdentifier = 'http://openid.aol.com/'; |
|
21 | 21 | |
22 | - /** |
|
23 | - * {@inheritdoc} |
|
24 | - */ |
|
25 | - protected $apiDocumentation = ''; // Not available |
|
22 | + /** |
|
23 | + * {@inheritdoc} |
|
24 | + */ |
|
25 | + protected $apiDocumentation = ''; // Not available |
|
26 | 26 | } |