@@ -17,58 +17,58 @@ |
||
17 | 17 | */ |
18 | 18 | class Pinterest extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = 'read_public'; |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = 'read_public'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $apiBaseUrl = 'https://api.pinterest.com/v1/'; |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $apiBaseUrl = 'https://api.pinterest.com/v1/'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $authorizeUrl = 'https://api.pinterest.com/oauth'; |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $authorizeUrl = 'https://api.pinterest.com/oauth'; |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://api.pinterest.com/v1/oauth/token'; |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://api.pinterest.com/v1/oauth/token'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://developers.pinterest.com/docs/api/overview/'; |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://developers.pinterest.com/docs/api/overview/'; |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function getUserProfile() |
|
49 | - { |
|
50 | - $response = $this->apiRequest('me'); |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function getUserProfile() |
|
49 | + { |
|
50 | + $response = $this->apiRequest('me'); |
|
51 | 51 | |
52 | - $data = new Data\Collection($response); |
|
52 | + $data = new Data\Collection($response); |
|
53 | 53 | |
54 | - $data = $data->filter('data'); |
|
54 | + $data = $data->filter('data'); |
|
55 | 55 | |
56 | - if (!$data->exists('id')) { |
|
57 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
58 | - } |
|
56 | + if (!$data->exists('id')) { |
|
57 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
58 | + } |
|
59 | 59 | |
60 | - $userProfile = new User\Profile(); |
|
60 | + $userProfile = new User\Profile(); |
|
61 | 61 | |
62 | - $userProfile->identifier = $data->get('id'); |
|
63 | - $userProfile->description = $data->get('bio'); |
|
64 | - $userProfile->photoURL = $data->get('image'); |
|
65 | - $userProfile->displayName = $data->get('username'); |
|
66 | - $userProfile->firstName = $data->get('first_name'); |
|
67 | - $userProfile->lastName = $data->get('last_name'); |
|
68 | - $userProfile->profileURL = "https://pinterest.com/{$data->get('username')}"; |
|
62 | + $userProfile->identifier = $data->get('id'); |
|
63 | + $userProfile->description = $data->get('bio'); |
|
64 | + $userProfile->photoURL = $data->get('image'); |
|
65 | + $userProfile->displayName = $data->get('username'); |
|
66 | + $userProfile->firstName = $data->get('first_name'); |
|
67 | + $userProfile->lastName = $data->get('last_name'); |
|
68 | + $userProfile->profileURL = "https://pinterest.com/{$data->get('username')}"; |
|
69 | 69 | |
70 | - $userProfile->data = (array)$data->get('counts'); |
|
70 | + $userProfile->data = (array)$data->get('counts'); |
|
71 | 71 | |
72 | - return $userProfile; |
|
73 | - } |
|
72 | + return $userProfile; |
|
73 | + } |
|
74 | 74 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | $data = $data->filter('data'); |
55 | 55 | |
56 | - if (!$data->exists('id')) { |
|
56 | + if ( ! $data->exists('id')) { |
|
57 | 57 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
58 | 58 | } |
59 | 59 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $userProfile->lastName = $data->get('last_name'); |
68 | 68 | $userProfile->profileURL = "https://pinterest.com/{$data->get('username')}"; |
69 | 69 | |
70 | - $userProfile->data = (array)$data->get('counts'); |
|
70 | + $userProfile->data = (array) $data->get('counts'); |
|
71 | 71 | |
72 | 72 | return $userProfile; |
73 | 73 | } |
@@ -17,56 +17,56 @@ |
||
17 | 17 | */ |
18 | 18 | class GitLab extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $scope = 'api'; |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $scope = 'api'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $apiBaseUrl = 'https://gitlab.com/api/v3/'; |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $apiBaseUrl = 'https://gitlab.com/api/v3/'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $authorizeUrl = 'https://gitlab.com/oauth/authorize'; |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $authorizeUrl = 'https://gitlab.com/oauth/authorize'; |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://gitlab.com/oauth/token'; |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://gitlab.com/oauth/token'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://docs.gitlab.com/ee/api/oauth2.html'; |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://docs.gitlab.com/ee/api/oauth2.html'; |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function getUserProfile() |
|
49 | - { |
|
50 | - $response = $this->apiRequest('user'); |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function getUserProfile() |
|
49 | + { |
|
50 | + $response = $this->apiRequest('user'); |
|
51 | 51 | |
52 | - $data = new Data\Collection($response); |
|
52 | + $data = new Data\Collection($response); |
|
53 | 53 | |
54 | - if (!$data->exists('id')) { |
|
55 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
56 | - } |
|
54 | + if (!$data->exists('id')) { |
|
55 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
56 | + } |
|
57 | 57 | |
58 | - $userProfile = new User\Profile(); |
|
58 | + $userProfile = new User\Profile(); |
|
59 | 59 | |
60 | - $userProfile->identifier = $data->get('id'); |
|
61 | - $userProfile->displayName = $data->get('name'); |
|
62 | - $userProfile->description = $data->get('bio'); |
|
63 | - $userProfile->photoURL = $data->get('avatar_url'); |
|
64 | - $userProfile->profileURL = $data->get('web_url'); |
|
65 | - $userProfile->email = $data->get('email'); |
|
66 | - $userProfile->webSiteURL = $data->get('website_url'); |
|
60 | + $userProfile->identifier = $data->get('id'); |
|
61 | + $userProfile->displayName = $data->get('name'); |
|
62 | + $userProfile->description = $data->get('bio'); |
|
63 | + $userProfile->photoURL = $data->get('avatar_url'); |
|
64 | + $userProfile->profileURL = $data->get('web_url'); |
|
65 | + $userProfile->email = $data->get('email'); |
|
66 | + $userProfile->webSiteURL = $data->get('website_url'); |
|
67 | 67 | |
68 | - $userProfile->displayName = $userProfile->displayName ?: $data->get('username'); |
|
68 | + $userProfile->displayName = $userProfile->displayName ?: $data->get('username'); |
|
69 | 69 | |
70 | - return $userProfile; |
|
71 | - } |
|
70 | + return $userProfile; |
|
71 | + } |
|
72 | 72 | } |
@@ -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,124 +17,124 @@ |
||
17 | 17 | */ |
18 | 18 | class Foursquare extends OAuth2 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $apiBaseUrl = 'https://api.foursquare.com/v2/'; |
|
24 | - |
|
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $authorizeUrl = 'https://foursquare.com/oauth2/authenticate'; |
|
29 | - |
|
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $accessTokenUrl = 'https://foursquare.com/oauth2/access_token'; |
|
34 | - |
|
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenName = 'oauth_token'; |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://developer.foursquare.com/overview/auth'; |
|
44 | - |
|
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - protected function initialize() |
|
49 | - { |
|
50 | - parent::initialize(); |
|
51 | - |
|
52 | - $apiVersion = $this->config->get('api_version') ?: '20140201'; |
|
53 | - |
|
54 | - $this->apiRequestParameters = [ |
|
55 | - 'oauth_token' => $this->getStoredData('access_token'), |
|
56 | - 'v' => $apiVersion, |
|
57 | - ]; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * {@inheritdoc} |
|
62 | - */ |
|
63 | - public function getUserProfile() |
|
64 | - { |
|
65 | - $response = $this->apiRequest('users/self'); |
|
66 | - |
|
67 | - $data = new Data\Collection($response); |
|
68 | - |
|
69 | - if (!$data->exists('response')) { |
|
70 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
71 | - } |
|
72 | - |
|
73 | - $userProfile = new User\Profile(); |
|
74 | - |
|
75 | - $data = $data->filter('response')->filter('user'); |
|
76 | - |
|
77 | - $userProfile->identifier = $data->get('id'); |
|
78 | - $userProfile->firstName = $data->get('firstName'); |
|
79 | - $userProfile->lastName = $data->get('lastName'); |
|
80 | - $userProfile->gender = $data->get('gender'); |
|
81 | - $userProfile->city = $data->get('homeCity'); |
|
82 | - $userProfile->email = $data->filter('contact')->get('email'); |
|
83 | - $userProfile->emailVerified = $userProfile->email; |
|
84 | - $userProfile->profileURL = 'https://www.foursquare.com/user/' . $userProfile->identifier; |
|
85 | - $userProfile->displayName = trim($userProfile->firstName . ' ' . $userProfile->lastName); |
|
86 | - |
|
87 | - if ($data->exists('photo')) { |
|
88 | - $photoSize = $this->config->get('photo_size') ?: '150x150'; |
|
89 | - |
|
90 | - $userProfile->photoURL = $data->filter('photo')->get('prefix'); |
|
91 | - $userProfile->photoURL .= $photoSize . $data->filter('photo')->get('suffix'); |
|
92 | - } |
|
93 | - |
|
94 | - return $userProfile; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * {@inheritdoc} |
|
99 | - */ |
|
100 | - public function getUserContacts() |
|
101 | - { |
|
102 | - $response = $this->apiRequest('users/self/friends'); |
|
103 | - |
|
104 | - $data = new Data\Collection($response); |
|
105 | - |
|
106 | - if (!$data->exists('response')) { |
|
107 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
108 | - } |
|
109 | - |
|
110 | - $contacts = []; |
|
111 | - |
|
112 | - foreach ($data->filter('response')->filter('friends')->filter('items')->toArray() as $item) { |
|
113 | - $contacts[] = $this->fetchUserContact($item); |
|
114 | - } |
|
115 | - |
|
116 | - return $contacts; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param $item |
|
121 | - * |
|
122 | - * @return User\Contact |
|
123 | - */ |
|
124 | - protected function fetchUserContact($item) |
|
125 | - { |
|
126 | - $photoSize = $this->config->get('photo_size') ?: '150x150'; |
|
127 | - |
|
128 | - $item = new Data\Collection($item); |
|
129 | - |
|
130 | - $userContact = new User\Contact(); |
|
131 | - |
|
132 | - $userContact->identifier = $item->get('id'); |
|
133 | - $userContact->photoURL = $item->filter('photo')->get('prefix'); |
|
134 | - $userContact->photoURL .= $photoSize . $item->filter('photo')->get('suffix'); |
|
135 | - $userContact->displayName = trim($item->get('firstName') . ' ' . $item->get('lastName')); |
|
136 | - $userContact->email = $item->filter('contact')->get('email'); |
|
137 | - |
|
138 | - return $userContact; |
|
139 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $apiBaseUrl = 'https://api.foursquare.com/v2/'; |
|
24 | + |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $authorizeUrl = 'https://foursquare.com/oauth2/authenticate'; |
|
29 | + |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $accessTokenUrl = 'https://foursquare.com/oauth2/access_token'; |
|
34 | + |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenName = 'oauth_token'; |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://developer.foursquare.com/overview/auth'; |
|
44 | + |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + protected function initialize() |
|
49 | + { |
|
50 | + parent::initialize(); |
|
51 | + |
|
52 | + $apiVersion = $this->config->get('api_version') ?: '20140201'; |
|
53 | + |
|
54 | + $this->apiRequestParameters = [ |
|
55 | + 'oauth_token' => $this->getStoredData('access_token'), |
|
56 | + 'v' => $apiVersion, |
|
57 | + ]; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * {@inheritdoc} |
|
62 | + */ |
|
63 | + public function getUserProfile() |
|
64 | + { |
|
65 | + $response = $this->apiRequest('users/self'); |
|
66 | + |
|
67 | + $data = new Data\Collection($response); |
|
68 | + |
|
69 | + if (!$data->exists('response')) { |
|
70 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
71 | + } |
|
72 | + |
|
73 | + $userProfile = new User\Profile(); |
|
74 | + |
|
75 | + $data = $data->filter('response')->filter('user'); |
|
76 | + |
|
77 | + $userProfile->identifier = $data->get('id'); |
|
78 | + $userProfile->firstName = $data->get('firstName'); |
|
79 | + $userProfile->lastName = $data->get('lastName'); |
|
80 | + $userProfile->gender = $data->get('gender'); |
|
81 | + $userProfile->city = $data->get('homeCity'); |
|
82 | + $userProfile->email = $data->filter('contact')->get('email'); |
|
83 | + $userProfile->emailVerified = $userProfile->email; |
|
84 | + $userProfile->profileURL = 'https://www.foursquare.com/user/' . $userProfile->identifier; |
|
85 | + $userProfile->displayName = trim($userProfile->firstName . ' ' . $userProfile->lastName); |
|
86 | + |
|
87 | + if ($data->exists('photo')) { |
|
88 | + $photoSize = $this->config->get('photo_size') ?: '150x150'; |
|
89 | + |
|
90 | + $userProfile->photoURL = $data->filter('photo')->get('prefix'); |
|
91 | + $userProfile->photoURL .= $photoSize . $data->filter('photo')->get('suffix'); |
|
92 | + } |
|
93 | + |
|
94 | + return $userProfile; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * {@inheritdoc} |
|
99 | + */ |
|
100 | + public function getUserContacts() |
|
101 | + { |
|
102 | + $response = $this->apiRequest('users/self/friends'); |
|
103 | + |
|
104 | + $data = new Data\Collection($response); |
|
105 | + |
|
106 | + if (!$data->exists('response')) { |
|
107 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
108 | + } |
|
109 | + |
|
110 | + $contacts = []; |
|
111 | + |
|
112 | + foreach ($data->filter('response')->filter('friends')->filter('items')->toArray() as $item) { |
|
113 | + $contacts[] = $this->fetchUserContact($item); |
|
114 | + } |
|
115 | + |
|
116 | + return $contacts; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param $item |
|
121 | + * |
|
122 | + * @return User\Contact |
|
123 | + */ |
|
124 | + protected function fetchUserContact($item) |
|
125 | + { |
|
126 | + $photoSize = $this->config->get('photo_size') ?: '150x150'; |
|
127 | + |
|
128 | + $item = new Data\Collection($item); |
|
129 | + |
|
130 | + $userContact = new User\Contact(); |
|
131 | + |
|
132 | + $userContact->identifier = $item->get('id'); |
|
133 | + $userContact->photoURL = $item->filter('photo')->get('prefix'); |
|
134 | + $userContact->photoURL .= $photoSize . $item->filter('photo')->get('suffix'); |
|
135 | + $userContact->displayName = trim($item->get('firstName') . ' ' . $item->get('lastName')); |
|
136 | + $userContact->email = $item->filter('contact')->get('email'); |
|
137 | + |
|
138 | + return $userContact; |
|
139 | + } |
|
140 | 140 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | |
67 | 67 | $data = new Data\Collection($response); |
68 | 68 | |
69 | - if (!$data->exists('response')) { |
|
69 | + if ( ! $data->exists('response')) { |
|
70 | 70 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
71 | 71 | } |
72 | 72 | |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | $userProfile->city = $data->get('homeCity'); |
82 | 82 | $userProfile->email = $data->filter('contact')->get('email'); |
83 | 83 | $userProfile->emailVerified = $userProfile->email; |
84 | - $userProfile->profileURL = 'https://www.foursquare.com/user/' . $userProfile->identifier; |
|
85 | - $userProfile->displayName = trim($userProfile->firstName . ' ' . $userProfile->lastName); |
|
84 | + $userProfile->profileURL = 'https://www.foursquare.com/user/'.$userProfile->identifier; |
|
85 | + $userProfile->displayName = trim($userProfile->firstName.' '.$userProfile->lastName); |
|
86 | 86 | |
87 | 87 | if ($data->exists('photo')) { |
88 | 88 | $photoSize = $this->config->get('photo_size') ?: '150x150'; |
89 | 89 | |
90 | 90 | $userProfile->photoURL = $data->filter('photo')->get('prefix'); |
91 | - $userProfile->photoURL .= $photoSize . $data->filter('photo')->get('suffix'); |
|
91 | + $userProfile->photoURL .= $photoSize.$data->filter('photo')->get('suffix'); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | return $userProfile; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | |
104 | 104 | $data = new Data\Collection($response); |
105 | 105 | |
106 | - if (!$data->exists('response')) { |
|
106 | + if ( ! $data->exists('response')) { |
|
107 | 107 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
108 | 108 | } |
109 | 109 | |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | |
132 | 132 | $userContact->identifier = $item->get('id'); |
133 | 133 | $userContact->photoURL = $item->filter('photo')->get('prefix'); |
134 | - $userContact->photoURL .= $photoSize . $item->filter('photo')->get('suffix'); |
|
135 | - $userContact->displayName = trim($item->get('firstName') . ' ' . $item->get('lastName')); |
|
134 | + $userContact->photoURL .= $photoSize.$item->filter('photo')->get('suffix'); |
|
135 | + $userContact->displayName = trim($item->get('firstName').' '.$item->get('lastName')); |
|
136 | 136 | $userContact->email = $item->filter('contact')->get('email'); |
137 | 137 | |
138 | 138 | return $userContact; |
@@ -14,29 +14,29 @@ |
||
14 | 14 | */ |
15 | 15 | class StackExchangeOpenID extends OpenID |
16 | 16 | { |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - */ |
|
20 | - protected $openidIdentifier = 'https://openid.stackexchange.com/'; |
|
21 | - |
|
22 | - /** |
|
23 | - * {@inheritdoc} |
|
24 | - */ |
|
25 | - protected $apiDocumentation = 'https://openid.stackexchange.com/'; |
|
26 | - |
|
27 | - /** |
|
28 | - * {@inheritdoc} |
|
29 | - */ |
|
30 | - public function authenticateFinish() |
|
31 | - { |
|
32 | - parent::authenticateFinish(); |
|
33 | - |
|
34 | - $userProfile = $this->storage->get($this->providerId . '.user'); |
|
35 | - |
|
36 | - $userProfile->identifier = !empty($userProfile->identifier) ? $userProfile->identifier : $userProfile->email; |
|
37 | - $userProfile->emailVerified = $userProfile->email; |
|
38 | - |
|
39 | - // re store the user profile |
|
40 | - $this->storage->set($this->providerId . '.user', $userProfile); |
|
41 | - } |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + */ |
|
20 | + protected $openidIdentifier = 'https://openid.stackexchange.com/'; |
|
21 | + |
|
22 | + /** |
|
23 | + * {@inheritdoc} |
|
24 | + */ |
|
25 | + protected $apiDocumentation = 'https://openid.stackexchange.com/'; |
|
26 | + |
|
27 | + /** |
|
28 | + * {@inheritdoc} |
|
29 | + */ |
|
30 | + public function authenticateFinish() |
|
31 | + { |
|
32 | + parent::authenticateFinish(); |
|
33 | + |
|
34 | + $userProfile = $this->storage->get($this->providerId . '.user'); |
|
35 | + |
|
36 | + $userProfile->identifier = !empty($userProfile->identifier) ? $userProfile->identifier : $userProfile->email; |
|
37 | + $userProfile->emailVerified = $userProfile->email; |
|
38 | + |
|
39 | + // re store the user profile |
|
40 | + $this->storage->set($this->providerId . '.user', $userProfile); |
|
41 | + } |
|
42 | 42 | } |
@@ -31,12 +31,12 @@ |
||
31 | 31 | { |
32 | 32 | parent::authenticateFinish(); |
33 | 33 | |
34 | - $userProfile = $this->storage->get($this->providerId . '.user'); |
|
34 | + $userProfile = $this->storage->get($this->providerId.'.user'); |
|
35 | 35 | |
36 | - $userProfile->identifier = !empty($userProfile->identifier) ? $userProfile->identifier : $userProfile->email; |
|
36 | + $userProfile->identifier = ! empty($userProfile->identifier) ? $userProfile->identifier : $userProfile->email; |
|
37 | 37 | $userProfile->emailVerified = $userProfile->email; |
38 | 38 | |
39 | 39 | // re store the user profile |
40 | - $this->storage->set($this->providerId . '.user', $userProfile); |
|
40 | + $this->storage->set($this->providerId.'.user', $userProfile); |
|
41 | 41 | } |
42 | 42 | } |
@@ -38,70 +38,70 @@ |
||
38 | 38 | */ |
39 | 39 | class StackExchange extends OAuth2 |
40 | 40 | { |
41 | - /** |
|
42 | - * {@inheritdoc} |
|
43 | - */ |
|
44 | - protected $scope = null; |
|
45 | - |
|
46 | - /** |
|
47 | - * {@inheritdoc} |
|
48 | - */ |
|
49 | - protected $apiBaseUrl = 'https://api.stackexchange.com/2.2/'; |
|
50 | - |
|
51 | - /** |
|
52 | - * {@inheritdoc} |
|
53 | - */ |
|
54 | - protected $authorizeUrl = 'https://stackexchange.com/oauth'; |
|
55 | - |
|
56 | - /** |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - protected $accessTokenUrl = 'https://stackexchange.com/oauth/access_token'; |
|
60 | - |
|
61 | - /** |
|
62 | - * {@inheritdoc} |
|
63 | - */ |
|
64 | - protected $apiDocumentation = 'https://api.stackexchange.com/docs/authentication'; |
|
65 | - |
|
66 | - /** |
|
67 | - * {@inheritdoc} |
|
68 | - */ |
|
69 | - protected function initialize() |
|
70 | - { |
|
71 | - parent::initialize(); |
|
72 | - |
|
73 | - $apiKey = $this->config->get('api_key'); |
|
74 | - |
|
75 | - $this->apiRequestParameters = ['key' => $apiKey]; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * {@inheritdoc} |
|
80 | - */ |
|
81 | - public function getUserProfile() |
|
82 | - { |
|
83 | - $site = $this->config->get('site'); |
|
84 | - |
|
85 | - $response = $this->apiRequest('me', 'GET', [ |
|
86 | - 'site' => $site, |
|
87 | - 'access_token' => $this->getStoredData('access_token'), |
|
88 | - ]); |
|
89 | - |
|
90 | - if (!$response || !isset($response->items) || !isset($response->items[0])) { |
|
91 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
92 | - } |
|
93 | - |
|
94 | - $data = new Data\Collection($response->items[0]); |
|
95 | - |
|
96 | - $userProfile = new User\Profile(); |
|
97 | - |
|
98 | - $userProfile->identifier = strval($data->get('user_id')); |
|
99 | - $userProfile->displayName = $data->get('display_name'); |
|
100 | - $userProfile->photoURL = $data->get('profile_image'); |
|
101 | - $userProfile->profileURL = $data->get('link'); |
|
102 | - $userProfile->region = $data->get('location'); |
|
103 | - $userProfile->age = $data->get('age'); |
|
104 | - |
|
105 | - return $userProfile; |
|
106 | - } |
|
41 | + /** |
|
42 | + * {@inheritdoc} |
|
43 | + */ |
|
44 | + protected $scope = null; |
|
45 | + |
|
46 | + /** |
|
47 | + * {@inheritdoc} |
|
48 | + */ |
|
49 | + protected $apiBaseUrl = 'https://api.stackexchange.com/2.2/'; |
|
50 | + |
|
51 | + /** |
|
52 | + * {@inheritdoc} |
|
53 | + */ |
|
54 | + protected $authorizeUrl = 'https://stackexchange.com/oauth'; |
|
55 | + |
|
56 | + /** |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + protected $accessTokenUrl = 'https://stackexchange.com/oauth/access_token'; |
|
60 | + |
|
61 | + /** |
|
62 | + * {@inheritdoc} |
|
63 | + */ |
|
64 | + protected $apiDocumentation = 'https://api.stackexchange.com/docs/authentication'; |
|
65 | + |
|
66 | + /** |
|
67 | + * {@inheritdoc} |
|
68 | + */ |
|
69 | + protected function initialize() |
|
70 | + { |
|
71 | + parent::initialize(); |
|
72 | + |
|
73 | + $apiKey = $this->config->get('api_key'); |
|
74 | + |
|
75 | + $this->apiRequestParameters = ['key' => $apiKey]; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * {@inheritdoc} |
|
80 | + */ |
|
81 | + public function getUserProfile() |
|
82 | + { |
|
83 | + $site = $this->config->get('site'); |
|
84 | + |
|
85 | + $response = $this->apiRequest('me', 'GET', [ |
|
86 | + 'site' => $site, |
|
87 | + 'access_token' => $this->getStoredData('access_token'), |
|
88 | + ]); |
|
89 | + |
|
90 | + if (!$response || !isset($response->items) || !isset($response->items[0])) { |
|
91 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
92 | + } |
|
93 | + |
|
94 | + $data = new Data\Collection($response->items[0]); |
|
95 | + |
|
96 | + $userProfile = new User\Profile(); |
|
97 | + |
|
98 | + $userProfile->identifier = strval($data->get('user_id')); |
|
99 | + $userProfile->displayName = $data->get('display_name'); |
|
100 | + $userProfile->photoURL = $data->get('profile_image'); |
|
101 | + $userProfile->profileURL = $data->get('link'); |
|
102 | + $userProfile->region = $data->get('location'); |
|
103 | + $userProfile->age = $data->get('age'); |
|
104 | + |
|
105 | + return $userProfile; |
|
106 | + } |
|
107 | 107 | } |
@@ -87,7 +87,7 @@ |
||
87 | 87 | 'access_token' => $this->getStoredData('access_token'), |
88 | 88 | ]); |
89 | 89 | |
90 | - if (!$response || !isset($response->items) || !isset($response->items[0])) { |
|
90 | + if ( ! $response || ! isset($response->items) || ! isset($response->items[0])) { |
|
91 | 91 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
92 | 92 | } |
93 | 93 |
@@ -17,81 +17,81 @@ |
||
17 | 17 | */ |
18 | 18 | class Tumblr extends OAuth1 |
19 | 19 | { |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected $apiBaseUrl = 'https://api.tumblr.com/v2/'; |
|
24 | - |
|
25 | - /** |
|
26 | - * {@inheritdoc} |
|
27 | - */ |
|
28 | - protected $authorizeUrl = 'https://www.tumblr.com/oauth/authorize'; |
|
29 | - |
|
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected $requestTokenUrl = 'https://www.tumblr.com/oauth/request_token'; |
|
34 | - |
|
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - protected $accessTokenUrl = 'https://www.tumblr.com/oauth/access_token'; |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritdoc} |
|
42 | - */ |
|
43 | - protected $apiDocumentation = 'https://www.tumblr.com/docs/en/api/v2'; |
|
44 | - |
|
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function getUserProfile() |
|
49 | - { |
|
50 | - $response = $this->apiRequest('user/info'); |
|
51 | - |
|
52 | - $data = new Data\Collection($response); |
|
53 | - |
|
54 | - if (!$data->exists('response')) { |
|
55 | - throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
56 | - } |
|
57 | - |
|
58 | - $userProfile = new User\Profile(); |
|
59 | - |
|
60 | - $userProfile->displayName = $data->filter('response')->filter('user')->get('name'); |
|
61 | - |
|
62 | - foreach ($data->filter('response')->filter('user')->filter('blogs')->toArray() as $blog) { |
|
63 | - $blog = new Data\Collection($blog); |
|
64 | - |
|
65 | - if ($blog->get('primary') && $blog->exists('url')) { |
|
66 | - $userProfile->identifier = $blog->get('url'); |
|
67 | - $userProfile->profileURL = $blog->get('url'); |
|
68 | - $userProfile->webSiteURL = $blog->get('url'); |
|
69 | - $userProfile->description = strip_tags($blog->get('description')); |
|
70 | - |
|
71 | - $bloghostname = explode('://', $blog->get('url')); |
|
72 | - $bloghostname = substr($bloghostname[1], 0, -1); |
|
73 | - |
|
74 | - // store user's primary blog which will be used as target by setUserStatus |
|
75 | - $this->storeData('primary_blog', $bloghostname); |
|
76 | - |
|
77 | - break; |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - return $userProfile; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * {@inheritdoc} |
|
86 | - */ |
|
87 | - public function setUserStatus($status) |
|
88 | - { |
|
89 | - $status = is_string($status) |
|
90 | - ? ['type' => 'text', 'body' => $status] |
|
91 | - : $status; |
|
92 | - |
|
93 | - $response = $this->apiRequest('blog/' . $this->getStoredData('primary_blog') . '/post', 'POST', $status); |
|
94 | - |
|
95 | - return $response; |
|
96 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected $apiBaseUrl = 'https://api.tumblr.com/v2/'; |
|
24 | + |
|
25 | + /** |
|
26 | + * {@inheritdoc} |
|
27 | + */ |
|
28 | + protected $authorizeUrl = 'https://www.tumblr.com/oauth/authorize'; |
|
29 | + |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected $requestTokenUrl = 'https://www.tumblr.com/oauth/request_token'; |
|
34 | + |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + protected $accessTokenUrl = 'https://www.tumblr.com/oauth/access_token'; |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritdoc} |
|
42 | + */ |
|
43 | + protected $apiDocumentation = 'https://www.tumblr.com/docs/en/api/v2'; |
|
44 | + |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function getUserProfile() |
|
49 | + { |
|
50 | + $response = $this->apiRequest('user/info'); |
|
51 | + |
|
52 | + $data = new Data\Collection($response); |
|
53 | + |
|
54 | + if (!$data->exists('response')) { |
|
55 | + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
|
56 | + } |
|
57 | + |
|
58 | + $userProfile = new User\Profile(); |
|
59 | + |
|
60 | + $userProfile->displayName = $data->filter('response')->filter('user')->get('name'); |
|
61 | + |
|
62 | + foreach ($data->filter('response')->filter('user')->filter('blogs')->toArray() as $blog) { |
|
63 | + $blog = new Data\Collection($blog); |
|
64 | + |
|
65 | + if ($blog->get('primary') && $blog->exists('url')) { |
|
66 | + $userProfile->identifier = $blog->get('url'); |
|
67 | + $userProfile->profileURL = $blog->get('url'); |
|
68 | + $userProfile->webSiteURL = $blog->get('url'); |
|
69 | + $userProfile->description = strip_tags($blog->get('description')); |
|
70 | + |
|
71 | + $bloghostname = explode('://', $blog->get('url')); |
|
72 | + $bloghostname = substr($bloghostname[1], 0, -1); |
|
73 | + |
|
74 | + // store user's primary blog which will be used as target by setUserStatus |
|
75 | + $this->storeData('primary_blog', $bloghostname); |
|
76 | + |
|
77 | + break; |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + return $userProfile; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * {@inheritdoc} |
|
86 | + */ |
|
87 | + public function setUserStatus($status) |
|
88 | + { |
|
89 | + $status = is_string($status) |
|
90 | + ? ['type' => 'text', 'body' => $status] |
|
91 | + : $status; |
|
92 | + |
|
93 | + $response = $this->apiRequest('blog/' . $this->getStoredData('primary_blog') . '/post', 'POST', $status); |
|
94 | + |
|
95 | + return $response; |
|
96 | + } |
|
97 | 97 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | $data = new Data\Collection($response); |
53 | 53 | |
54 | - if (!$data->exists('response')) { |
|
54 | + if ( ! $data->exists('response')) { |
|
55 | 55 | throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); |
56 | 56 | } |
57 | 57 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | ? ['type' => 'text', 'body' => $status] |
91 | 91 | : $status; |
92 | 92 | |
93 | - $response = $this->apiRequest('blog/' . $this->getStoredData('primary_blog') . '/post', 'POST', $status); |
|
93 | + $response = $this->apiRequest('blog/'.$this->getStoredData('primary_blog').'/post', 'POST', $status); |
|
94 | 94 | |
95 | 95 | return $response; |
96 | 96 | } |
@@ -24,245 +24,245 @@ |
||
24 | 24 | */ |
25 | 25 | class Hybridauth |
26 | 26 | { |
27 | - /** |
|
28 | - * Hybridauth config. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $config; |
|
33 | - |
|
34 | - /** |
|
35 | - * Storage. |
|
36 | - * |
|
37 | - * @var StorageInterface |
|
38 | - */ |
|
39 | - protected $storage; |
|
40 | - |
|
41 | - /** |
|
42 | - * HttpClient. |
|
43 | - * |
|
44 | - * @var HttpClientInterface |
|
45 | - */ |
|
46 | - protected $httpClient; |
|
47 | - |
|
48 | - /** |
|
49 | - * Logger. |
|
50 | - * |
|
51 | - * @var LoggerInterface |
|
52 | - */ |
|
53 | - protected $logger; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param array|string $config Array with configuration or Path to PHP file that will return array |
|
57 | - * @param HttpClientInterface $httpClient |
|
58 | - * @param StorageInterface $storage |
|
59 | - * @param LoggerInterface $logger |
|
60 | - * |
|
61 | - * @throws InvalidArgumentException |
|
62 | - */ |
|
63 | - public function __construct( |
|
64 | - $config, |
|
65 | - HttpClientInterface $httpClient = null, |
|
66 | - StorageInterface $storage = null, |
|
67 | - LoggerInterface $logger = null |
|
68 | - ) { |
|
69 | - if (is_string($config) && file_exists($config)) { |
|
70 | - $config = include $config; |
|
71 | - } elseif (!is_array($config)) { |
|
72 | - throw new InvalidArgumentException('Hybridauth config does not exist on the given path.'); |
|
73 | - } |
|
74 | - |
|
75 | - $this->config = $config + [ |
|
76 | - 'debug_mode' => Logger::NONE, |
|
77 | - 'debug_file' => '', |
|
78 | - 'curl_options' => null, |
|
79 | - 'providers' => [] |
|
80 | - ]; |
|
81 | - $this->storage = $storage; |
|
82 | - $this->logger = $logger; |
|
83 | - $this->httpClient = $httpClient; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Instantiate the given provider and authentication or authorization protocol. |
|
88 | - * |
|
89 | - * If not authenticated yet, the user will be redirected to the provider's site for |
|
90 | - * authentication/authorisation, otherwise it will simply return an instance of |
|
91 | - * provider's adapter. |
|
92 | - * |
|
93 | - * @param string $name adapter's name (case insensitive) |
|
94 | - * |
|
95 | - * @return \Hybridauth\Adapter\AdapterInterface |
|
96 | - * @throws InvalidArgumentException |
|
97 | - * @throws UnexpectedValueException |
|
98 | - */ |
|
99 | - public function authenticate($name) |
|
100 | - { |
|
101 | - $adapter = $this->getAdapter($name); |
|
102 | - |
|
103 | - $adapter->authenticate(); |
|
104 | - |
|
105 | - return $adapter; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns a new instance of a provider's adapter by name |
|
110 | - * |
|
111 | - * @param string $name adapter's name (case insensitive) |
|
112 | - * |
|
113 | - * @return \Hybridauth\Adapter\AdapterInterface |
|
114 | - * @throws InvalidArgumentException |
|
115 | - * @throws UnexpectedValueException |
|
116 | - */ |
|
117 | - public function getAdapter($name) |
|
118 | - { |
|
119 | - $config = $this->getProviderConfig($name); |
|
120 | - |
|
121 | - $adapter = isset($config['adapter']) ? $config['adapter'] : sprintf('Hybridauth\\Provider\\%s', $name); |
|
122 | - |
|
123 | - if (!class_exists($adapter)) { |
|
124 | - $adapter = null; |
|
125 | - $fs = new \FilesystemIterator(__DIR__ . '/Provider/'); |
|
126 | - /** @var \SplFileInfo $file */ |
|
127 | - foreach ($fs as $file) { |
|
128 | - if (!$file->isDir()) { |
|
129 | - $provider = strtok($file->getFilename(), '.'); |
|
130 | - if ($name === mb_strtolower($provider)) { |
|
131 | - $adapter = sprintf('Hybridauth\\Provider\\%s', $provider); |
|
132 | - break; |
|
133 | - } |
|
134 | - } |
|
135 | - } |
|
136 | - if ($adapter === null) { |
|
137 | - throw new InvalidArgumentException('Unknown Provider.'); |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - return new $adapter($config, $this->httpClient, $this->storage, $this->logger); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Get provider config by name. |
|
146 | - * |
|
147 | - * @param string $name adapter's name (case insensitive) |
|
148 | - * |
|
149 | - * @throws UnexpectedValueException |
|
150 | - * @throws InvalidArgumentException |
|
151 | - * |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - public function getProviderConfig($name) |
|
155 | - { |
|
156 | - $name = strtolower($name); |
|
157 | - |
|
158 | - $providersConfig = array_change_key_case($this->config['providers'], CASE_LOWER); |
|
159 | - |
|
160 | - if (!isset($providersConfig[$name])) { |
|
161 | - throw new InvalidArgumentException('Unknown Provider.'); |
|
162 | - } |
|
163 | - |
|
164 | - if (!$providersConfig[$name]['enabled']) { |
|
165 | - throw new UnexpectedValueException('Disabled Provider.'); |
|
166 | - } |
|
167 | - |
|
168 | - $config = $providersConfig[$name]; |
|
169 | - $config += [ |
|
170 | - 'debug_mode' => $this->config['debug_mode'], |
|
171 | - 'debug_file' => $this->config['debug_file'], |
|
172 | - ]; |
|
173 | - |
|
174 | - if (!isset($config['callback']) && isset($this->config['callback'])) { |
|
175 | - $config['callback'] = $this->config['callback']; |
|
176 | - } |
|
177 | - |
|
178 | - return $config; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Returns a boolean of whether the user is connected with a provider |
|
183 | - * |
|
184 | - * @param string $name adapter's name (case insensitive) |
|
185 | - * |
|
186 | - * @return bool |
|
187 | - * @throws InvalidArgumentException |
|
188 | - * @throws UnexpectedValueException |
|
189 | - */ |
|
190 | - public function isConnectedWith($name) |
|
191 | - { |
|
192 | - return $this->getAdapter($name)->isConnected(); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Returns a list of enabled adapters names |
|
197 | - * |
|
198 | - * @return array |
|
199 | - */ |
|
200 | - public function getProviders() |
|
201 | - { |
|
202 | - $providers = []; |
|
203 | - |
|
204 | - foreach ($this->config['providers'] as $name => $config) { |
|
205 | - if ($config['enabled']) { |
|
206 | - $providers[] = $name; |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - return $providers; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Returns a list of currently connected adapters names |
|
215 | - * |
|
216 | - * @return array |
|
217 | - * @throws InvalidArgumentException |
|
218 | - * @throws UnexpectedValueException |
|
219 | - */ |
|
220 | - public function getConnectedProviders() |
|
221 | - { |
|
222 | - $providers = []; |
|
223 | - |
|
224 | - foreach ($this->getProviders() as $name) { |
|
225 | - if ($this->isConnectedWith($name)) { |
|
226 | - $providers[] = $name; |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - return $providers; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Returns a list of new instances of currently connected adapters |
|
235 | - * |
|
236 | - * @return \Hybridauth\Adapter\AdapterInterface[] |
|
237 | - * @throws InvalidArgumentException |
|
238 | - * @throws UnexpectedValueException |
|
239 | - */ |
|
240 | - public function getConnectedAdapters() |
|
241 | - { |
|
242 | - $adapters = []; |
|
243 | - |
|
244 | - foreach ($this->getProviders() as $name) { |
|
245 | - $adapter = $this->getAdapter($name); |
|
246 | - |
|
247 | - if ($adapter->isConnected()) { |
|
248 | - $adapters[$name] = $adapter; |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - return $adapters; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Disconnect all currently connected adapters at once |
|
257 | - */ |
|
258 | - public function disconnectAllAdapters() |
|
259 | - { |
|
260 | - foreach ($this->getProviders() as $name) { |
|
261 | - $adapter = $this->getAdapter($name); |
|
262 | - |
|
263 | - if ($adapter->isConnected()) { |
|
264 | - $adapter->disconnect(); |
|
265 | - } |
|
266 | - } |
|
267 | - } |
|
27 | + /** |
|
28 | + * Hybridauth config. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $config; |
|
33 | + |
|
34 | + /** |
|
35 | + * Storage. |
|
36 | + * |
|
37 | + * @var StorageInterface |
|
38 | + */ |
|
39 | + protected $storage; |
|
40 | + |
|
41 | + /** |
|
42 | + * HttpClient. |
|
43 | + * |
|
44 | + * @var HttpClientInterface |
|
45 | + */ |
|
46 | + protected $httpClient; |
|
47 | + |
|
48 | + /** |
|
49 | + * Logger. |
|
50 | + * |
|
51 | + * @var LoggerInterface |
|
52 | + */ |
|
53 | + protected $logger; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param array|string $config Array with configuration or Path to PHP file that will return array |
|
57 | + * @param HttpClientInterface $httpClient |
|
58 | + * @param StorageInterface $storage |
|
59 | + * @param LoggerInterface $logger |
|
60 | + * |
|
61 | + * @throws InvalidArgumentException |
|
62 | + */ |
|
63 | + public function __construct( |
|
64 | + $config, |
|
65 | + HttpClientInterface $httpClient = null, |
|
66 | + StorageInterface $storage = null, |
|
67 | + LoggerInterface $logger = null |
|
68 | + ) { |
|
69 | + if (is_string($config) && file_exists($config)) { |
|
70 | + $config = include $config; |
|
71 | + } elseif (!is_array($config)) { |
|
72 | + throw new InvalidArgumentException('Hybridauth config does not exist on the given path.'); |
|
73 | + } |
|
74 | + |
|
75 | + $this->config = $config + [ |
|
76 | + 'debug_mode' => Logger::NONE, |
|
77 | + 'debug_file' => '', |
|
78 | + 'curl_options' => null, |
|
79 | + 'providers' => [] |
|
80 | + ]; |
|
81 | + $this->storage = $storage; |
|
82 | + $this->logger = $logger; |
|
83 | + $this->httpClient = $httpClient; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Instantiate the given provider and authentication or authorization protocol. |
|
88 | + * |
|
89 | + * If not authenticated yet, the user will be redirected to the provider's site for |
|
90 | + * authentication/authorisation, otherwise it will simply return an instance of |
|
91 | + * provider's adapter. |
|
92 | + * |
|
93 | + * @param string $name adapter's name (case insensitive) |
|
94 | + * |
|
95 | + * @return \Hybridauth\Adapter\AdapterInterface |
|
96 | + * @throws InvalidArgumentException |
|
97 | + * @throws UnexpectedValueException |
|
98 | + */ |
|
99 | + public function authenticate($name) |
|
100 | + { |
|
101 | + $adapter = $this->getAdapter($name); |
|
102 | + |
|
103 | + $adapter->authenticate(); |
|
104 | + |
|
105 | + return $adapter; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns a new instance of a provider's adapter by name |
|
110 | + * |
|
111 | + * @param string $name adapter's name (case insensitive) |
|
112 | + * |
|
113 | + * @return \Hybridauth\Adapter\AdapterInterface |
|
114 | + * @throws InvalidArgumentException |
|
115 | + * @throws UnexpectedValueException |
|
116 | + */ |
|
117 | + public function getAdapter($name) |
|
118 | + { |
|
119 | + $config = $this->getProviderConfig($name); |
|
120 | + |
|
121 | + $adapter = isset($config['adapter']) ? $config['adapter'] : sprintf('Hybridauth\\Provider\\%s', $name); |
|
122 | + |
|
123 | + if (!class_exists($adapter)) { |
|
124 | + $adapter = null; |
|
125 | + $fs = new \FilesystemIterator(__DIR__ . '/Provider/'); |
|
126 | + /** @var \SplFileInfo $file */ |
|
127 | + foreach ($fs as $file) { |
|
128 | + if (!$file->isDir()) { |
|
129 | + $provider = strtok($file->getFilename(), '.'); |
|
130 | + if ($name === mb_strtolower($provider)) { |
|
131 | + $adapter = sprintf('Hybridauth\\Provider\\%s', $provider); |
|
132 | + break; |
|
133 | + } |
|
134 | + } |
|
135 | + } |
|
136 | + if ($adapter === null) { |
|
137 | + throw new InvalidArgumentException('Unknown Provider.'); |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + return new $adapter($config, $this->httpClient, $this->storage, $this->logger); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Get provider config by name. |
|
146 | + * |
|
147 | + * @param string $name adapter's name (case insensitive) |
|
148 | + * |
|
149 | + * @throws UnexpectedValueException |
|
150 | + * @throws InvalidArgumentException |
|
151 | + * |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + public function getProviderConfig($name) |
|
155 | + { |
|
156 | + $name = strtolower($name); |
|
157 | + |
|
158 | + $providersConfig = array_change_key_case($this->config['providers'], CASE_LOWER); |
|
159 | + |
|
160 | + if (!isset($providersConfig[$name])) { |
|
161 | + throw new InvalidArgumentException('Unknown Provider.'); |
|
162 | + } |
|
163 | + |
|
164 | + if (!$providersConfig[$name]['enabled']) { |
|
165 | + throw new UnexpectedValueException('Disabled Provider.'); |
|
166 | + } |
|
167 | + |
|
168 | + $config = $providersConfig[$name]; |
|
169 | + $config += [ |
|
170 | + 'debug_mode' => $this->config['debug_mode'], |
|
171 | + 'debug_file' => $this->config['debug_file'], |
|
172 | + ]; |
|
173 | + |
|
174 | + if (!isset($config['callback']) && isset($this->config['callback'])) { |
|
175 | + $config['callback'] = $this->config['callback']; |
|
176 | + } |
|
177 | + |
|
178 | + return $config; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Returns a boolean of whether the user is connected with a provider |
|
183 | + * |
|
184 | + * @param string $name adapter's name (case insensitive) |
|
185 | + * |
|
186 | + * @return bool |
|
187 | + * @throws InvalidArgumentException |
|
188 | + * @throws UnexpectedValueException |
|
189 | + */ |
|
190 | + public function isConnectedWith($name) |
|
191 | + { |
|
192 | + return $this->getAdapter($name)->isConnected(); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Returns a list of enabled adapters names |
|
197 | + * |
|
198 | + * @return array |
|
199 | + */ |
|
200 | + public function getProviders() |
|
201 | + { |
|
202 | + $providers = []; |
|
203 | + |
|
204 | + foreach ($this->config['providers'] as $name => $config) { |
|
205 | + if ($config['enabled']) { |
|
206 | + $providers[] = $name; |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + return $providers; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Returns a list of currently connected adapters names |
|
215 | + * |
|
216 | + * @return array |
|
217 | + * @throws InvalidArgumentException |
|
218 | + * @throws UnexpectedValueException |
|
219 | + */ |
|
220 | + public function getConnectedProviders() |
|
221 | + { |
|
222 | + $providers = []; |
|
223 | + |
|
224 | + foreach ($this->getProviders() as $name) { |
|
225 | + if ($this->isConnectedWith($name)) { |
|
226 | + $providers[] = $name; |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + return $providers; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Returns a list of new instances of currently connected adapters |
|
235 | + * |
|
236 | + * @return \Hybridauth\Adapter\AdapterInterface[] |
|
237 | + * @throws InvalidArgumentException |
|
238 | + * @throws UnexpectedValueException |
|
239 | + */ |
|
240 | + public function getConnectedAdapters() |
|
241 | + { |
|
242 | + $adapters = []; |
|
243 | + |
|
244 | + foreach ($this->getProviders() as $name) { |
|
245 | + $adapter = $this->getAdapter($name); |
|
246 | + |
|
247 | + if ($adapter->isConnected()) { |
|
248 | + $adapters[$name] = $adapter; |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + return $adapters; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Disconnect all currently connected adapters at once |
|
257 | + */ |
|
258 | + public function disconnectAllAdapters() |
|
259 | + { |
|
260 | + foreach ($this->getProviders() as $name) { |
|
261 | + $adapter = $this->getAdapter($name); |
|
262 | + |
|
263 | + if ($adapter->isConnected()) { |
|
264 | + $adapter->disconnect(); |
|
265 | + } |
|
266 | + } |
|
267 | + } |
|
268 | 268 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | ) { |
69 | 69 | if (is_string($config) && file_exists($config)) { |
70 | 70 | $config = include $config; |
71 | - } elseif (!is_array($config)) { |
|
71 | + } elseif ( ! is_array($config)) { |
|
72 | 72 | throw new InvalidArgumentException('Hybridauth config does not exist on the given path.'); |
73 | 73 | } |
74 | 74 | |
@@ -120,12 +120,12 @@ discard block |
||
120 | 120 | |
121 | 121 | $adapter = isset($config['adapter']) ? $config['adapter'] : sprintf('Hybridauth\\Provider\\%s', $name); |
122 | 122 | |
123 | - if (!class_exists($adapter)) { |
|
123 | + if ( ! class_exists($adapter)) { |
|
124 | 124 | $adapter = null; |
125 | - $fs = new \FilesystemIterator(__DIR__ . '/Provider/'); |
|
125 | + $fs = new \FilesystemIterator(__DIR__.'/Provider/'); |
|
126 | 126 | /** @var \SplFileInfo $file */ |
127 | 127 | foreach ($fs as $file) { |
128 | - if (!$file->isDir()) { |
|
128 | + if ( ! $file->isDir()) { |
|
129 | 129 | $provider = strtok($file->getFilename(), '.'); |
130 | 130 | if ($name === mb_strtolower($provider)) { |
131 | 131 | $adapter = sprintf('Hybridauth\\Provider\\%s', $provider); |
@@ -157,11 +157,11 @@ discard block |
||
157 | 157 | |
158 | 158 | $providersConfig = array_change_key_case($this->config['providers'], CASE_LOWER); |
159 | 159 | |
160 | - if (!isset($providersConfig[$name])) { |
|
160 | + if ( ! isset($providersConfig[$name])) { |
|
161 | 161 | throw new InvalidArgumentException('Unknown Provider.'); |
162 | 162 | } |
163 | 163 | |
164 | - if (!$providersConfig[$name]['enabled']) { |
|
164 | + if ( ! $providersConfig[$name]['enabled']) { |
|
165 | 165 | throw new UnexpectedValueException('Disabled Provider.'); |
166 | 166 | } |
167 | 167 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | 'debug_file' => $this->config['debug_file'], |
172 | 172 | ]; |
173 | 173 | |
174 | - if (!isset($config['callback']) && isset($this->config['callback'])) { |
|
174 | + if ( ! isset($config['callback']) && isset($this->config['callback'])) { |
|
175 | 175 | $config['callback'] = $this->config['callback']; |
176 | 176 | } |
177 | 177 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if (version_compare(PHP_VERSION, '5.4.0', '<')) { |
10 | - throw new Exception('Hybridauth 3 requires PHP version 5.4 or higher.'); |
|
10 | + throw new Exception('Hybridauth 3 requires PHP version 5.4 or higher.'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -21,33 +21,33 @@ discard block |
||
21 | 21 | * @return void |
22 | 22 | */ |
23 | 23 | spl_autoload_register( |
24 | - function ($class) { |
|
25 | - // project-specific namespace prefix. Will only kicks in for Hybridauth's namespace. |
|
26 | - $prefix = 'Hybridauth\\'; |
|
24 | + function ($class) { |
|
25 | + // project-specific namespace prefix. Will only kicks in for Hybridauth's namespace. |
|
26 | + $prefix = 'Hybridauth\\'; |
|
27 | 27 | |
28 | - // base directory for the namespace prefix. |
|
29 | - $base_dir = __DIR__; // By default, it points to this same folder. |
|
30 | - // You may change this path if having trouble detecting the path to |
|
31 | - // the source files. |
|
28 | + // base directory for the namespace prefix. |
|
29 | + $base_dir = __DIR__; // By default, it points to this same folder. |
|
30 | + // You may change this path if having trouble detecting the path to |
|
31 | + // the source files. |
|
32 | 32 | |
33 | - // does the class use the namespace prefix? |
|
34 | - $len = strlen($prefix); |
|
35 | - if (strncmp($prefix, $class, $len) !== 0) { |
|
36 | - // no, move to the next registered autoloader. |
|
37 | - return; |
|
38 | - } |
|
33 | + // does the class use the namespace prefix? |
|
34 | + $len = strlen($prefix); |
|
35 | + if (strncmp($prefix, $class, $len) !== 0) { |
|
36 | + // no, move to the next registered autoloader. |
|
37 | + return; |
|
38 | + } |
|
39 | 39 | |
40 | - // get the relative class name. |
|
41 | - $relative_class = substr($class, $len); |
|
40 | + // get the relative class name. |
|
41 | + $relative_class = substr($class, $len); |
|
42 | 42 | |
43 | - // replace the namespace prefix with the base directory, replace namespace |
|
44 | - // separators with directory separators in the relative class name, append |
|
45 | - // with .php |
|
46 | - $file = $base_dir . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) . '.php'; |
|
43 | + // replace the namespace prefix with the base directory, replace namespace |
|
44 | + // separators with directory separators in the relative class name, append |
|
45 | + // with .php |
|
46 | + $file = $base_dir . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) . '.php'; |
|
47 | 47 | |
48 | - // if the file exists, require it |
|
49 | - if (file_exists($file)) { |
|
50 | - require $file; |
|
51 | - } |
|
52 | - } |
|
48 | + // if the file exists, require it |
|
49 | + if (file_exists($file)) { |
|
50 | + require $file; |
|
51 | + } |
|
52 | + } |
|
53 | 53 | ); |
@@ -21,12 +21,12 @@ discard block |
||
21 | 21 | * @return void |
22 | 22 | */ |
23 | 23 | spl_autoload_register( |
24 | - function ($class) { |
|
24 | + function($class) { |
|
25 | 25 | // project-specific namespace prefix. Will only kicks in for Hybridauth's namespace. |
26 | 26 | $prefix = 'Hybridauth\\'; |
27 | 27 | |
28 | 28 | // base directory for the namespace prefix. |
29 | - $base_dir = __DIR__; // By default, it points to this same folder. |
|
29 | + $base_dir = __DIR__; // By default, it points to this same folder. |
|
30 | 30 | // You may change this path if having trouble detecting the path to |
31 | 31 | // the source files. |
32 | 32 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | // replace the namespace prefix with the base directory, replace namespace |
44 | 44 | // separators with directory separators in the relative class name, append |
45 | 45 | // with .php |
46 | - $file = $base_dir . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) . '.php'; |
|
46 | + $file = $base_dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $relative_class).'.php'; |
|
47 | 47 | |
48 | 48 | // if the file exists, require it |
49 | 49 | if (file_exists($file)) { |
@@ -12,39 +12,39 @@ |
||
12 | 12 | */ |
13 | 13 | interface StorageInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * Retrieve a item from storage |
|
17 | - * |
|
18 | - * @param string $key |
|
19 | - * |
|
20 | - * @return mixed |
|
21 | - */ |
|
22 | - public function get($key); |
|
15 | + /** |
|
16 | + * Retrieve a item from storage |
|
17 | + * |
|
18 | + * @param string $key |
|
19 | + * |
|
20 | + * @return mixed |
|
21 | + */ |
|
22 | + public function get($key); |
|
23 | 23 | |
24 | - /** |
|
25 | - * Add or Update an item to storage |
|
26 | - * |
|
27 | - * @param string $key |
|
28 | - * @param string $value |
|
29 | - */ |
|
30 | - public function set($key, $value); |
|
24 | + /** |
|
25 | + * Add or Update an item to storage |
|
26 | + * |
|
27 | + * @param string $key |
|
28 | + * @param string $value |
|
29 | + */ |
|
30 | + public function set($key, $value); |
|
31 | 31 | |
32 | - /** |
|
33 | - * Delete an item from storage |
|
34 | - * |
|
35 | - * @param string $key |
|
36 | - */ |
|
37 | - public function delete($key); |
|
32 | + /** |
|
33 | + * Delete an item from storage |
|
34 | + * |
|
35 | + * @param string $key |
|
36 | + */ |
|
37 | + public function delete($key); |
|
38 | 38 | |
39 | - /** |
|
40 | - * Delete a item from storage |
|
41 | - * |
|
42 | - * @param string $key |
|
43 | - */ |
|
44 | - public function deleteMatch($key); |
|
39 | + /** |
|
40 | + * Delete a item from storage |
|
41 | + * |
|
42 | + * @param string $key |
|
43 | + */ |
|
44 | + public function deleteMatch($key); |
|
45 | 45 | |
46 | - /** |
|
47 | - * Clear all items in storage |
|
48 | - */ |
|
49 | - public function clear(); |
|
46 | + /** |
|
47 | + * Clear all items in storage |
|
48 | + */ |
|
49 | + public function clear(); |
|
50 | 50 | } |