PluginProbe
JetBackup – Backup, Restore & Migrate / 1.4.6
JetBackup – Backup, Restore & Migrate v1.4.6
3.1.23.6 3.1.23.5 3.1.23.3 3.1.22.4 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 All 82 releases
backup / com / lib / Dropbox / WebAuthBase.php
WebAuthBase.php
120 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Dropbox;
3
4 /**
5 * The base class for the two auth options.
6 */
7 class WebAuthBase extends AuthBase
8 {
9 // protected function _getAuthorizeUrl($redirectUri, $state)
10 // {
11 // return RequestUtil::buildUrlForGetOrPut(
12 // $this->userLocale,
13 // $this->appInfo->getHost()->getWeb(),
14 // "1/oauth2/authorize",
15 // array(
16 // "client_id" => $this->appInfo->getKey(),
17 // "response_type" => "code",
18 // "redirect_uri" => $redirectUri,
19 // "state" => $state,
20 // ));
21 // }
22
23 /* Dropbox api 2*/
24 protected function _getAuthorizeUrl($redirectUri, $state)
25 {
26 return RequestUtil::buildUrlForGetOrPut(
27 $this->userLocale,
28 $this->appInfo->getHost()->getWeb(),
29 "oauth2/authorize",
30 array(
31 "client_id" => $this->appInfo->getKey(),
32 "response_type" => "code",
33 "redirect_uri" => $redirectUri,
34 "state" => $state,
35 ));
36 }
37
38 protected function _finish($code, $originalRedirectUri)
39 {
40 // This endpoint requires "Basic" auth.
41 $clientCredentials = $this->appInfo->getKey().":".$this->appInfo->getSecret();
42 $authHeaderValue = "Basic ".base64_encode($clientCredentials);
43
44 $response = RequestUtil::doPostWithSpecificAuth(
45 $this->clientIdentifier, $authHeaderValue, $this->userLocale,
46 $this->appInfo->getHost()->getApi(),
47 "oauth2/token",
48 array(
49 "grant_type" => "authorization_code",
50 "code" => $code,
51 "redirect_uri" => $originalRedirectUri,
52 ));
53
54 if ($response->statusCode !== 200) throw RequestUtil::unexpectedStatus($response);
55
56 $parts = RequestUtil::parseResponseJson($response->body);
57
58 if (!array_key_exists('token_type', $parts) || !is_string($parts['token_type'])) {
59 throw new Exception_BadResponse("Missing \"token_type\" field.");
60 }
61 $tokenType = $parts['token_type'];
62 if (!array_key_exists('access_token', $parts) || !is_string($parts['access_token'])) {
63 throw new Exception_BadResponse("Missing \"access_token\" field.");
64 }
65 $accessToken = $parts['access_token'];
66 if (!array_key_exists('uid', $parts) || !is_string($parts['uid'])) {
67 throw new Exception_BadResponse("Missing \"uid\" string field.");
68 }
69 $userId = $parts['uid'];
70
71 if ($tokenType !== "Bearer" && $tokenType !== "bearer") {
72 throw new Exception_BadResponse("Unknown \"token_type\"; expecting \"Bearer\", got "
73 .Util::q($tokenType));
74 }
75
76 return array($accessToken, $userId);
77 }
78
79 // protected function _finish($code, $originalRedirectUri)
80 // {
81 // // This endpoint requires "Basic" auth.
82 // $clientCredentials = $this->appInfo->getKey().":".$this->appInfo->getSecret();
83 // $authHeaderValue = "Basic ".base64_encode($clientCredentials);
84
85 // $response = RequestUtil::doPostWithSpecificAuth(
86 // $this->clientIdentifier, $authHeaderValue, $this->userLocale,
87 // $this->appInfo->getHost()->getApi(),
88 // "1/oauth2/token",
89 // array(
90 // "grant_type" => "authorization_code",
91 // "code" => $code,
92 // "redirect_uri" => $originalRedirectUri,
93 // ));
94
95 // if ($response->statusCode !== 200) throw RequestUtil::unexpectedStatus($response);
96
97 // $parts = RequestUtil::parseResponseJson($response->body);
98
99 // if (!array_key_exists('token_type', $parts) || !is_string($parts['token_type'])) {
100 // throw new Exception_BadResponse("Missing \"token_type\" field.");
101 // }
102 // $tokenType = $parts['token_type'];
103 // if (!array_key_exists('access_token', $parts) || !is_string($parts['access_token'])) {
104 // throw new Exception_BadResponse("Missing \"access_token\" field.");
105 // }
106 // $accessToken = $parts['access_token'];
107 // if (!array_key_exists('uid', $parts) || !is_string($parts['uid'])) {
108 // throw new Exception_BadResponse("Missing \"uid\" string field.");
109 // }
110 // $userId = $parts['uid'];
111
112 // if ($tokenType !== "Bearer" && $tokenType !== "bearer") {
113 // throw new Exception_BadResponse("Unknown \"token_type\"; expecting \"Bearer\", got "
114 // .Util::q($tokenType));
115 // }
116
117 // return array($accessToken, $userId);
118 // }
119 }
120