1 | <?php |
||
39 | class OAuth2Client |
||
40 | { |
||
41 | /** |
||
42 | * @const string The base authorization URL. |
||
43 | */ |
||
44 | const BASE_AUTHORIZATION_URL = 'https://www.facebook.com'; |
||
45 | |||
46 | /** |
||
47 | * The FacebookApp entity. |
||
48 | * |
||
49 | * @var FacebookApp |
||
50 | */ |
||
51 | protected $app; |
||
52 | |||
53 | /** |
||
54 | * The Facebook client. |
||
55 | * |
||
56 | * @var FacebookClient |
||
57 | */ |
||
58 | protected $client; |
||
59 | |||
60 | /** |
||
61 | * The version of the Graph API to use. |
||
62 | * |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $graphVersion; |
||
66 | |||
67 | /** |
||
68 | * The last request sent to Graph. |
||
69 | * |
||
70 | * @var FacebookRequest|null |
||
71 | */ |
||
72 | protected $lastRequest; |
||
73 | |||
74 | /** |
||
75 | * @param FacebookApp $app |
||
76 | * @param FacebookClient $client |
||
77 | * @param string|null $graphVersion The version of the Graph API to use. |
||
78 | */ |
||
79 | public function __construct(FacebookApp $app, FacebookClient $client, $graphVersion = null) |
||
85 | |||
86 | /** |
||
87 | * Returns the last FacebookRequest that was sent. |
||
88 | * Useful for debugging and testing. |
||
89 | * |
||
90 | * @return FacebookRequest|null |
||
91 | */ |
||
92 | public function getLastRequest() |
||
96 | |||
97 | /** |
||
98 | * Get the metadata associated with the access token. |
||
99 | * |
||
100 | * @param AccessToken|string $accessToken The access token to debug. |
||
101 | * |
||
102 | * @return AccessTokenMetadata |
||
103 | */ |
||
104 | public function debugToken($accessToken) |
||
123 | |||
124 | /** |
||
125 | * Generates an authorization URL to begin the process of authenticating a user. |
||
126 | * |
||
127 | * @param string $redirectUrl The callback URL to redirect to. |
||
128 | * @param array $scope An array of permissions to request. |
||
129 | * @param string $state The CSPRNG-generated CSRF value. |
||
130 | * @param array $params An array of parameters to generate URL. |
||
131 | * @param string $separator The separator to use in http_build_query(). |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | public function getAuthorizationUrl($redirectUrl, $state, array $scope = [], array $params = [], $separator = '&') |
||
148 | |||
149 | /** |
||
150 | * Get a valid access token from a code. |
||
151 | * |
||
152 | * @param string $code |
||
153 | * @param string $redirectUri |
||
154 | * |
||
155 | * @return AccessToken |
||
156 | * |
||
157 | * @throws FacebookSDKException |
||
158 | */ |
||
159 | public function getAccessTokenFromCode($code, $redirectUri = '') |
||
168 | |||
169 | /** |
||
170 | * Exchanges a short-lived access token with a long-lived access token. |
||
171 | * |
||
172 | * @param AccessToken|string $accessToken |
||
173 | * |
||
174 | * @return AccessToken |
||
175 | * |
||
176 | * @throws FacebookSDKException |
||
177 | */ |
||
178 | public function getLongLivedAccessToken($accessToken) |
||
188 | |||
189 | /** |
||
190 | * Get a valid code from an access token. |
||
191 | * |
||
192 | * @param AccessToken|string $accessToken |
||
193 | * @param string $redirectUri |
||
194 | * |
||
195 | * @return AccessToken |
||
196 | * |
||
197 | * @throws FacebookSDKException |
||
198 | */ |
||
199 | public function getCodeFromLongLivedAccessToken($accessToken, $redirectUri = '') |
||
214 | |||
215 | /** |
||
216 | * Send a request to the OAuth endpoint. |
||
217 | * |
||
218 | * @param array $params |
||
219 | * |
||
220 | * @return AccessToken |
||
221 | * |
||
222 | * @throws FacebookSDKException |
||
223 | */ |
||
224 | protected function requestAnAccessToken(array $params) |
||
249 | |||
250 | /** |
||
251 | * Send a request to Graph with an app access token. |
||
252 | * |
||
253 | * @param string $endpoint |
||
254 | * @param array $params |
||
255 | * @param AccessToken|string|null $accessToken |
||
256 | * |
||
257 | * @return FacebookResponse |
||
258 | * |
||
259 | * @throws FacebookResponseException |
||
260 | */ |
||
261 | protected function sendRequestWithClientParams($endpoint, array $params, $accessToken = null) |
||
279 | |||
280 | /** |
||
281 | * Returns the client_* params for OAuth requests. |
||
282 | * |
||
283 | * @return array |
||
284 | */ |
||
285 | protected function getClientParams() |
||
292 | } |
||
293 |