1 | <?php |
||
18 | abstract class AbstractProvider extends AbstractBaseProvider |
||
19 | { |
||
20 | /** |
||
21 | * HTTP method for access token request |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $requestHttpMethod = Client::POST; |
||
26 | |||
27 | /** |
||
28 | * @return string |
||
29 | */ |
||
30 | abstract public function getAuthorizeUri(); |
||
31 | |||
32 | /** |
||
33 | * @return string |
||
34 | */ |
||
35 | abstract public function getRequestTokenUri(); |
||
36 | |||
37 | /** |
||
38 | * Default parameters for auth url, can be redeclared inside implementation of the Provider |
||
39 | * |
||
40 | * @return array |
||
41 | */ |
||
42 | 16 | public function getAuthUrlParameters() |
|
50 | |||
51 | /** |
||
52 | * @return string |
||
53 | */ |
||
54 | 16 | protected function generateState() |
|
60 | |||
61 | /** |
||
62 | * @return string |
||
63 | */ |
||
64 | 16 | public function makeAuthUrl() |
|
83 | |||
84 | /** |
||
85 | * Parse access token from response's $body |
||
86 | * |
||
87 | * @param string|bool $body |
||
88 | * @return AccessToken |
||
89 | * @throws InvalidAccessToken |
||
90 | */ |
||
91 | 5 | public function parseToken($body) |
|
92 | { |
||
93 | 5 | if (empty($body)) { |
|
94 | throw new InvalidAccessToken('Provider response with empty body'); |
||
95 | } |
||
96 | |||
97 | 5 | parse_str($body, $token); |
|
98 | |||
99 | 5 | if (!is_array($token) || !isset($token['access_token'])) { |
|
100 | 4 | throw new InvalidAccessToken('Provider API returned an unexpected response'); |
|
101 | } |
||
102 | |||
103 | 1 | return new AccessToken($token); |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * @param string $code |
||
108 | * @return \SocialConnect\Common\Http\Request |
||
109 | */ |
||
110 | 17 | protected function makeAccessTokenRequest($code) |
|
129 | |||
130 | /** |
||
131 | * @param string $code |
||
132 | * @return AccessToken |
||
133 | * @throws InvalidResponse |
||
134 | */ |
||
135 | 32 | public function getAccessToken($code) |
|
155 | |||
156 | /** |
||
157 | * @param array $parameters |
||
158 | * @return AccessToken |
||
159 | * @throws \SocialConnect\OAuth2\Exception\InvalidState |
||
160 | * @throws \SocialConnect\OAuth2\Exception\UnknownState |
||
161 | * @throws \SocialConnect\OAuth2\Exception\UnknownAuthorization |
||
162 | */ |
||
163 | public function getAccessTokenByRequestParameters(array $parameters) |
||
180 | } |
||
181 |