protected function _finish($code, $originalRedirectUri)
 {
     // This endpoint requires "Basic" auth.
     $clientCredentials = $this->appInfo->getKey() . ":" . $this->appInfo->getSecret();
     $authHeaderValue = "Basic " . base64_encode($clientCredentials);
     $response = Dropbox_RequestUtil::doPostWithSpecificAuth($this->clientIdentifier, $authHeaderValue, $this->userLocale, $this->appInfo->getHost()->getApi(), "1/oauth2/token", array("grant_type" => "authorization_code", "code" => $code, "redirect_uri" => $originalRedirectUri));
     if ($response->statusCode !== 200) {
         throw Dropbox_RequestUtil::unexpectedStatus($response);
     }
     $parts = Dropbox_RequestUtil::parseResponseJson($response->body);
     if (!array_key_exists('token_type', $parts) or !is_string($parts['token_type'])) {
         throw new Dropbox_Exception_BadResponse("Missing \"token_type\" field.");
     }
     $tokenType = $parts['token_type'];
     if (!array_key_exists('access_token', $parts) or !is_string($parts['access_token'])) {
         throw new Dropbox_Exception_BadResponse("Missing \"access_token\" field.");
     }
     $accessToken = $parts['access_token'];
     if (!array_key_exists('uid', $parts) or !is_string($parts['uid'])) {
         throw new Dropbox_Exception_BadResponse("Missing \"uid\" string field.");
     }
     $userId = $parts['uid'];
     if ($tokenType !== "Bearer" && $tokenType !== "bearer") {
         throw new Dropbox_Exception_BadResponse("Unknown \"token_type\"; expecting \"Bearer\", got  " . Dropbox_Client::q($tokenType));
     }
     return array($accessToken, $userId);
 }
 public static function testDisallowed($url, $expectedExceptionMessage)
 {
     $curl = Dropbox_RequestUtil::mkCurl("test-ssl", $url);
     $curl->set(CURLOPT_RETURNTRANSFER, true);
     try {
         $curl->exec();
     } catch (Dropbox_Exception_NetworkIO $ex) {
         if (strpos($ex->getMessage(), $expectedExceptionMessage) == 0) {
             return true;
         } else {
             throw $ex;
         }
     }
     return false;
 }
 /**
  * @param Dropbox_OAuth1AccessToken $oauth1AccessToken
  * @param string                    $path
  *
  * @return Dropbox_HttpResponse
  *
  * @throws Dropbox_Exception
  */
 private function doPost($oauth1AccessToken, $path)
 {
     // Construct the OAuth 1 header.
     $authHeaderValue = "OAuth oauth_signature_method=\"PLAINTEXT\"" . ", oauth_consumer_key=\"" . rawurlencode($this->appInfo->getKey()) . "\"" . ", oauth_token=\"" . rawurlencode($oauth1AccessToken->getKey()) . "\"" . ", oauth_signature=\"" . rawurlencode($this->appInfo->getSecret()) . "&" . rawurlencode($oauth1AccessToken->getSecret()) . "\"";
     return Dropbox_RequestUtil::doPostWithSpecificAuth($this->clientIdentifier, $authHeaderValue, $this->userLocale, $this->appInfo->getHost()->getApi(), $path, null);
 }
Exemple #4
0
 /**
  * Create a {@link Curl} object that is pre-configured with {@link getClientIdentifier()},
  * and the proper OAuth 2 "Authorization" header.
  *
  * @param string $url
  *                    Generate this URL using {@link buildUrl()}.
  *
  * @return Dropbox_Curl
  */
 public function mkCurl($url)
 {
     return Dropbox_RequestUtil::mkCurlWithOAuth($this->clientIdentifier, $url, $this->accessToken);
 }