1 | <?php |
||
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 | * Nonce/State to protect CSRF |
||
41 | * |
||
42 | * @var string|null |
||
43 | */ |
||
44 | protected $state; |
||
45 | |||
46 | /** |
||
47 | * @var SessionInterface |
||
48 | */ |
||
49 | protected $session; |
||
50 | |||
51 | /** |
||
52 | * @param ClientInterface $httpClient |
||
53 | * @param SessionInterface $session |
||
54 | * @param array $parameters |
||
55 | */ |
||
56 | 12 | public function __construct(ClientInterface $httpClient, SessionInterface $session, Consumer $consumer, array $parameters) |
|
57 | { |
||
58 | 12 | $this->httpClient = $httpClient; |
|
59 | 12 | $this->session = $session; |
|
60 | 12 | $this->consumer = $consumer; |
|
61 | |||
62 | 12 | if (isset($parameters['scope'])) { |
|
63 | $this->setScope($parameters['scope']); |
||
64 | } |
||
65 | |||
66 | 12 | if (isset($parameters['fields'])) { |
|
67 | $this->setFields($parameters['fields']); |
||
68 | } |
||
69 | |||
70 | 12 | if (isset($parameters['redirectUri'])) { |
|
71 | 10 | $this->redirectUri = $parameters['redirectUri']; |
|
72 | 10 | } |
|
73 | 12 | } |
|
74 | |||
75 | /** |
||
76 | * @return mixed |
||
77 | */ |
||
78 | 3 | protected function getRedirectUri() |
|
79 | { |
||
80 | 3 | return $this->redirectUri; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return string |
||
85 | */ |
||
86 | 3 | public function getRedirectUrl() |
|
87 | { |
||
88 | 3 | return $this->getRedirectUri() . '/' . $this->getName() . '/'; |
|
89 | } |
||
90 | |||
91 | /** |
||
92 | * @return string |
||
93 | */ |
||
94 | abstract public function getBaseUri(); |
||
95 | |||
96 | /** |
||
97 | * Return Provider's name |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | abstract public function getName(); |
||
102 | |||
103 | /** |
||
104 | * @param array $requestParameters |
||
105 | * @return \SocialConnect\Provider\AccessTokenInterface |
||
106 | */ |
||
107 | abstract public function getAccessTokenByRequestParameters(array $requestParameters); |
||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | abstract public function makeAuthUrl(); |
||
113 | |||
114 | /** |
||
115 | * Get current user identity from social network by $accessToken |
||
116 | * |
||
117 | * @param AccessTokenInterface $accessToken |
||
118 | * @return \SocialConnect\Common\Entity\User |
||
119 | * |
||
120 | * @throws \SocialConnect\Provider\Exception\InvalidResponse |
||
121 | */ |
||
122 | abstract public function getIdentity(AccessTokenInterface $accessToken); |
||
123 | |||
124 | /** |
||
125 | * @return array |
||
126 | */ |
||
127 | public function getScope() |
||
131 | |||
132 | /** |
||
133 | * @param array $scope |
||
134 | */ |
||
135 | public function setScope(array $scope) |
||
139 | |||
140 | /** |
||
141 | * @return string |
||
142 | */ |
||
143 | public function getScopeInline() |
||
147 | |||
148 | /** |
||
149 | * @return array |
||
150 | */ |
||
151 | public function getFields() |
||
155 | |||
156 | /** |
||
157 | * @param array $fields |
||
158 | */ |
||
159 | public function setFields(array $fields) |
||
163 | |||
164 | /** |
||
165 | * @return string |
||
166 | */ |
||
167 | 3 | public function getFieldsInline() |
|
168 | { |
||
169 | 3 | return implode(',', $this->fields); |
|
170 | } |
||
171 | |||
172 | /** |
||
173 | * @return \SocialConnect\Provider\Consumer |
||
174 | */ |
||
175 | 1 | public function getConsumer() |
|
176 | { |
||
177 | 1 | return $this->consumer; |
|
178 | } |
||
179 | |||
180 | /** |
||
181 | * @param null|string $state |
||
182 | */ |
||
183 | public function setState($state) |
||
187 | |||
188 | /** |
||
189 | * @return string |
||
190 | */ |
||
191 | public function useState() |
||
197 | } |
||
198 |