Exception
6 years ago
WebAuthException
6 years ago
certs
6 years ago
AppInfo.php
6 years ago
AppInfoLoadException.php
6 years ago
ArrayEntryStore.php
6 years ago
AuthBase.php
6 years ago
AuthInfo.php
6 years ago
AuthInfoLoadException.php
6 years ago
Checker.php
6 years ago
Client.php
6 years ago
Curl.php
6 years ago
CurlStreamRelay.php
6 years ago
DeserializeException.php
6 years ago
DropboxMetadataHeaderCatcher.php
6 years ago
Exception.php
6 years ago
Host.php
6 years ago
HttpResponse.php
6 years ago
OAuth1AccessToken.php
6 years ago
OAuth1Upgrader.php
6 years ago
Path.php
6 years ago
RequestUtil.php
6 years ago
RootCertificates.php
6 years ago
SSLTester.php
6 years ago
Security.php
6 years ago
StreamReadException.php
6 years ago
Util.php
6 years ago
ValueStore.php
6 years ago
WebAuth.php
6 years ago
WebAuthBase.php
6 years ago
WebAuthNoRedirect.php
6 years ago
WriteMode.php
6 years ago
autoload.php
6 years ago
strict.php
6 years ago
WebAuthBase.php
120 lines
| 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 |