PluginProbe
ManageWP Worker / 4.0.1
ManageWP Worker v4.0.1
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / Dropbox / WebAuthBase.php

WebAuthBase.php in ManageWP Worker 4.0.1, at src/Dropbox/WebAuthBase.php

65 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The base class for the two auth options.
5 */
6 class Dropbox_WebAuthBase extends Dropbox_AuthBase
7 {
8 protected function _getAuthorizeUrl($redirectUri, $state)
9 {
10 return Dropbox_RequestUtil::buildUrlForGetOrPut(
11 $this->userLocale,
12 $this->appInfo->getHost()->getWeb(),
13 "1/oauth2/authorize",
14 array(
15 "client_id" => $this->appInfo->getKey(),
16 "response_type" => "code",
17 "redirect_uri" => $redirectUri,
18 "state" => $state,
19 ));
20 }
21
22 protected function _finish($code, $originalRedirectUri)
23 {
24 // This endpoint requires "Basic" auth.
25 $clientCredentials = $this->appInfo->getKey().":".$this->appInfo->getSecret();
26 $authHeaderValue = "Basic ".base64_encode($clientCredentials);
27
28 $response = Dropbox_RequestUtil::doPostWithSpecificAuth(
29 $this->clientIdentifier, $authHeaderValue, $this->userLocale,
30 $this->appInfo->getHost()->getApi(),
31 "1/oauth2/token",
32 array(
33 "grant_type" => "authorization_code",
34 "code" => $code,
35 "redirect_uri" => $originalRedirectUri,
36 ));
37
38 if ($response->statusCode !== 200) {
39 throw Dropbox_RequestUtil::unexpectedStatus($response);
40 }
41
42 $parts = Dropbox_RequestUtil::parseResponseJson($response->body);
43
44 if (!array_key_exists('token_type', $parts) or !is_string($parts['token_type'])) {
45 throw new Dropbox_Exception_BadResponse("Missing \"token_type\" field.");
46 }
47 $tokenType = $parts['token_type'];
48 if (!array_key_exists('access_token', $parts) or !is_string($parts['access_token'])) {
49 throw new Dropbox_Exception_BadResponse("Missing \"access_token\" field.");
50 }
51 $accessToken = $parts['access_token'];
52 if (!array_key_exists('uid', $parts) or !is_string($parts['uid'])) {
53 throw new Dropbox_Exception_BadResponse("Missing \"uid\" string field.");
54 }
55 $userId = $parts['uid'];
56
57 if ($tokenType !== "Bearer" && $tokenType !== "bearer") {
58 throw new Dropbox_Exception_BadResponse("Unknown \"token_type\"; expecting \"Bearer\", got "
59 .Dropbox_Client::q($tokenType));
60 }
61
62 return array($accessToken, $userId);
63 }
64 }
65