1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* SocialConnect project |
4
|
|
|
* @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace SocialConnect\Provider; |
8
|
|
|
|
9
|
|
|
use SocialConnect\Common\Http\Client\ClientInterface; |
10
|
|
|
use SocialConnect\Provider\Session\SessionInterface; |
11
|
|
|
|
12
|
|
|
abstract class AbstractBaseProvider |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Consumer |
16
|
|
|
*/ |
17
|
|
|
protected $consumer; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
protected $scope = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $fields = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ClientInterface |
31
|
|
|
*/ |
32
|
|
|
protected $httpClient; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $redirectUri; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var SessionInterface |
41
|
|
|
*/ |
42
|
|
|
protected $session; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
protected $options = []; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param ClientInterface $httpClient |
51
|
|
|
* @param SessionInterface $session |
52
|
|
|
* @param array $parameters |
53
|
|
|
*/ |
54
|
303 |
|
public function __construct(ClientInterface $httpClient, SessionInterface $session, Consumer $consumer, array $parameters) |
55
|
|
|
{ |
56
|
303 |
|
$this->httpClient = $httpClient; |
57
|
303 |
|
$this->session = $session; |
58
|
303 |
|
$this->consumer = $consumer; |
59
|
|
|
|
60
|
303 |
|
if (isset($parameters['scope'])) { |
61
|
|
|
$this->setScope($parameters['scope']); |
62
|
|
|
} |
63
|
|
|
|
64
|
303 |
|
if (isset($parameters['fields'])) { |
65
|
|
|
$this->setFields($parameters['fields']); |
66
|
|
|
} |
67
|
|
|
|
68
|
303 |
|
if (isset($parameters['redirectUri'])) { |
69
|
299 |
|
$this->redirectUri = $parameters['redirectUri']; |
70
|
299 |
|
} |
71
|
|
|
|
72
|
303 |
|
if (isset($parameters['options'])) { |
73
|
|
|
$this->options = $parameters['options']; |
74
|
|
|
} |
75
|
303 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string $key |
79
|
|
|
* @param bool $default |
80
|
|
|
* @return bool |
81
|
|
|
*/ |
82
|
|
|
public function getBoolOption($key, $default) |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
if (array_key_exists($key, $this->options)) { |
85
|
|
|
return (bool) $this->options[$key]; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $default; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return mixed |
93
|
|
|
*/ |
94
|
43 |
|
protected function getRedirectUri() |
95
|
|
|
{ |
96
|
43 |
|
return $this->redirectUri; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
43 |
|
public function getRedirectUrl() |
103
|
|
|
{ |
104
|
43 |
|
return $this->getRedirectUri() . '/' . $this->getName() . '/'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
abstract public function getBaseUri(); |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Return Provider's name |
114
|
|
|
* |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
abstract public function getName(); |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param array $requestParameters |
121
|
|
|
* @return \SocialConnect\Provider\AccessTokenInterface |
122
|
|
|
*/ |
123
|
|
|
abstract public function getAccessTokenByRequestParameters(array $requestParameters); |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
abstract public function makeAuthUrl(); |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Get current user identity from social network by $accessToken |
132
|
|
|
* |
133
|
|
|
* @param AccessTokenInterface $accessToken |
134
|
|
|
* @return \SocialConnect\Common\Entity\User |
135
|
|
|
* |
136
|
|
|
* @throws \SocialConnect\Provider\Exception\InvalidResponse |
137
|
|
|
*/ |
138
|
|
|
abstract public function getIdentity(AccessTokenInterface $accessToken); |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return array |
142
|
|
|
*/ |
143
|
|
|
public function getScope() |
144
|
|
|
{ |
145
|
|
|
return $this->scope; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param array $scope |
150
|
|
|
*/ |
151
|
|
|
public function setScope(array $scope) |
152
|
|
|
{ |
153
|
|
|
$this->scope = $scope; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return string |
158
|
|
|
*/ |
159
|
|
|
public function getScopeInline() |
160
|
|
|
{ |
161
|
|
|
return implode(',', $this->scope); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return array |
166
|
|
|
*/ |
167
|
|
|
public function getFields() |
168
|
|
|
{ |
169
|
|
|
return $this->fields; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param array $fields |
174
|
|
|
*/ |
175
|
|
|
public function setFields(array $fields) |
176
|
|
|
{ |
177
|
|
|
$this->fields = $fields; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return string |
182
|
|
|
*/ |
183
|
6 |
|
public function getFieldsInline() |
184
|
|
|
{ |
185
|
6 |
|
return implode(',', $this->fields); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return \SocialConnect\Provider\Consumer |
190
|
|
|
*/ |
191
|
1 |
|
public function getConsumer() |
192
|
|
|
{ |
193
|
1 |
|
return $this->consumer; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|