PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.6.9
JetBackup – Backup, Restore & Migrate v1.6.9
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / com / lib / Dropbox / WebAuthBase.php
backup / com / lib / Dropbox Last commit date
Exception 8 years ago WebAuthException 8 years ago certs 8 years ago AppInfo.php 8 years ago AppInfoLoadException.php 8 years ago ArrayEntryStore.php 8 years ago AuthBase.php 8 years ago AuthInfo.php 8 years ago AuthInfoLoadException.php 8 years ago Checker.php 8 years ago Client.php 8 years ago Curl.php 8 years ago CurlStreamRelay.php 8 years ago DeserializeException.php 8 years ago DropboxMetadataHeaderCatcher.php 8 years ago Exception.php 8 years ago Host.php 8 years ago HttpResponse.php 8 years ago OAuth1AccessToken.php 8 years ago OAuth1Upgrader.php 8 years ago Path.php 8 years ago RequestUtil.php 8 years ago RootCertificates.php 8 years ago SSLTester.php 8 years ago Security.php 8 years ago StreamReadException.php 8 years ago Util.php 8 years ago ValueStore.php 8 years ago WebAuth.php 3 years ago WebAuthBase.php 3 years ago WebAuthNoRedirect.php 8 years ago WriteMode.php 8 years ago autoload.php 8 years ago strict.php 8 years ago
WebAuthBase.php
101 lines
1 <?php
2
3 namespace Dropbox;
4
5 /**
6 * The base class for the two auth options.
7 */
8 class WebAuthBase extends AuthBase
9 {
10 protected function _getRefreshedAccessToken($key, $secrect, $refreshToken) // phpcs:ignore
11 {
12 $array = array();
13 $ch = curl_init();
14 curl_setopt($ch, CURLOPT_URL, 'https://api.dropbox.com/oauth2/token');
15 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
16 curl_setopt($ch, CURLOPT_POST, 1);
17 curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=refresh_token&refresh_token=" . $refreshToken);
18 curl_setopt($ch, CURLOPT_USERPWD, $key . ':' . $secrect);
19 $headers = array();
20 $headers[] = 'Content-Type: application/x-www-form-urlencoded';
21 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
22 $response = json_decode(curl_exec($ch), true);
23
24 if (curl_errno($ch)) {
25 $array = ['status' => 400, 'access_token' => null];
26 } elseif (isset($response['access_token'])) {
27 $array = ['status' => 200, 'access_token' => $response['access_token']];
28 }
29 curl_close($ch);
30
31 return $array;
32 }
33
34 /* Dropbox api 2*/
35 protected function _getAuthorizeUrl($redirectUri, $state) // phpcs:ignore
36 {
37 return RequestUtil::buildUrlForGetOrPut(
38 $this->userLocale,
39 $this->appInfo->getHost()->getWeb(),
40 "oauth2/authorize",
41 array(
42 "token_access_type" => "offline",
43 "client_id" => $this->appInfo->getKey(),
44 "response_type" => "code",
45 "redirect_uri" => $redirectUri,
46 "state" => $state,
47 )
48 );
49 }
50
51 protected function _finish($code, $originalRedirectUri) // phpcs:ignore
52 {
53 // This endpoint requires "Basic" auth.
54 $clientCredentials = $this->appInfo->getKey() . ":" . $this->appInfo->getSecret();
55 $authHeaderValue = "Basic " . base64_encode($clientCredentials);
56
57 $response = RequestUtil::doPostWithSpecificAuth(
58 $this->clientIdentifier,
59 $authHeaderValue,
60 $this->userLocale,
61 $this->appInfo->getHost()->getApi(),
62 "oauth2/token",
63 array(
64 "grant_type" => "authorization_code",
65 "code" => $code,
66 "redirect_uri" => $originalRedirectUri,
67 )
68 );
69
70 if ($response->statusCode !== 200) {
71 throw RequestUtil::unexpectedStatus($response);
72 }
73
74 $parts = RequestUtil::parseResponseJson($response->body);
75
76 if (!array_key_exists('token_type', $parts) || !is_string($parts['token_type'])) {
77 throw new Exception_BadResponse("Missing \"token_type\" field.");
78 }
79 $tokenType = $parts['token_type'];
80 if (!array_key_exists('access_token', $parts) || !is_string($parts['access_token'])) {
81 throw new Exception_BadResponse("Missing \"access_token\" field.");
82 }
83 $accessToken = $parts['access_token'];
84 if (!array_key_exists('uid', $parts) || !is_string($parts['uid'])) {
85 throw new Exception_BadResponse("Missing \"uid\" string field.");
86 }
87 $refreshToken = $parts['refresh_token'];
88 if (!array_key_exists('refresh_token', $parts) || !is_string($parts['refresh_token'])) {
89 throw new Exception_BadResponse("Missing \"refresh_token\" string field.");
90 }
91 $userId = $parts['uid'];
92
93 if ($tokenType !== "Bearer" && $tokenType !== "bearer") {
94 throw new Exception_BadResponse("Unknown \"token_type\"; expecting \"Bearer\", got "
95 . Util::q($tokenType));
96 }
97
98 return array($accessToken, $refreshToken, $userId);
99 }
100 }
101