public function initRepository() { if (is_array($this->pluginConf)) { $this->driverConf = $this->pluginConf; } else { $this->driverConf = array(); } $wrapperData = $this->detectStreamWrapper(true); $this->logDebug("Detected wrapper data", $wrapperData); $this->wrapperClassName = $wrapperData["classname"]; $this->urlBase = $wrapperData["protocol"] . "://" . $this->repository->getId(); if (!AJXP_Utils::searchIncludePath('HTTP/OAuth/Consumer.php')) { $this->logError("Dropbox", "The PEAR HTTP_OAuth package must be installed!"); return; } $consumerKey = $this->repository->getOption("CONSUMER_KEY"); $consumerSecret = $this->repository->getOption("CONSUMER_SECRET"); $oauth = new Dropbox_OAuth_PEAR($consumerKey, $consumerSecret); // TOKENS IN SESSION? if (!empty($_SESSION["OAUTH_DROPBOX_TOKENS"])) { return; } // TOKENS IN FILE ? $tokens = $this->getTokens(); if (!empty($tokens)) { $_SESSION["OAUTH_DROPBOX_TOKENS"] = $tokens; return; } // OAUTH NEGOCIATION if (isset($_SESSION['DROPBOX_NEGOCIATION_STATE'])) { $state = $_SESSION['DROPBOX_NEGOCIATION_STATE']; } else { $state = 1; } switch ($state) { case 1: $tokens = $oauth->getRequestToken(); //print_r($tokens); // Note that if you want the user to automatically redirect back, you can // add the 'callback' argument to getAuthorizeUrl. //echo "Step 2: You must now redirect the user to:\n"; $_SESSION['DROPBOX_NEGOCIATION_STATE'] = 2; $_SESSION['oauth_tokens'] = $tokens; throw new Exception("Please go to <a style=\"text-decoration:underline;\" target=\"_blank\" href=\"" . $oauth->getAuthorizeUrl() . "\">" . $oauth->getAuthorizeUrl() . "</a> to authorize the access to your dropbox. Then try again to switch to this workspace."); case 2: $oauth->setToken($_SESSION['oauth_tokens']); try { $tokens = $oauth->getAccessToken(); } catch (Exception $oauthEx) { throw new Exception($oauthEx->getMessage() . ". Please go to <a style=\"text-decoration:underline;\" target=\"_blank\" href=\"" . $oauth->getAuthorizeUrl() . "\">" . $oauth->getAuthorizeUrl() . "</a> to authorize the access to your dropbox. Then try again to switch to this workspace."); } $_SESSION['DROPBOX_NEGOCIATION_STATE'] = 3; $_SESSION['OAUTH_DROPBOX_TOKENS'] = $tokens; $this->setTokens($tokens); return; } throw new Exception("Impossible to find the dropbox tokens for accessing this workspace"); }
public function get_authorize_url() { $oauth = new Dropbox_OAuth_PEAR(self::CONSUMER_KEY, self::CONSUMER_SECRET); $this->tokens['request'] = $oauth->getRequestToken(); $this->save_tokens(); return $oauth->getAuthorizeUrl(); }
function get_authorize_url() { $oauth = new Dropbox_OAuth_PEAR($this->_key, $this->_secret); $this->_token['request'] = $oauth->getRequestToken(); pb_backupbuddy::save(); //echo 'authorizeurltoken:<pre>'; //print_r( $this->_token ); //echo '</pre>'; return str_replace('api.', 'www.', $oauth->getAuthorizeUrl()); }
static function tryToConnect($call_back_link, $user_id, $token = null) { if (isset($token)) { //token übergeben $_SESSION['oauth_tokens'] = array("token" => $token['token'], "token_secret" => $token['token_secret']); $_SESSION['state'] = 3; $state = 3; } if (!isset($_SESSION['state'])) { //ganz neu $_SESSION['state'] = 1; } $state = $_SESSION['state']; //try to login $consumerKey = '5wty9mf06gcuco0'; $consumerSecret = 'hveok3hllw48hji'; $oauth = new \Dropbox_OAuth_PEAR($consumerKey, $consumerSecret); $dropbox = new \Dropbox_API($oauth, \Dropbox_API::ROOT_SANDBOX); try { switch ($state) { /* In this phase we grab the initial request tokens and redirect the user to the 'authorize' page hosted on dropbox */ case 1: $tokens = $oauth->getRequestToken(); $link = $oauth->getAuthorizeUrl($call_back_link) . "\n"; // Note that if you want the user to automatically redirect back, you can // add the 'callback' argument to getAuthorizeUrl. $link = $oauth->getAuthorizeUrl($call_back_link) . "\n"; $_SESSION['state'] = 2; $_SESSION['oauth_tokens'] = $tokens; return $link; break; /* In this phase, the user just came back from authorizing and we're going to fetch the real access tokens */ /* In this phase, the user just came back from authorizing and we're going to fetch the real access tokens */ case 2: $oauth->setToken($_SESSION['oauth_tokens']); try { $tokens = $oauth->getAccessToken(); $_SESSION['state'] = 3; $state = 3; $_SESSION['oauth_tokens'] = $tokens; } catch (\PEAR_Exception $e) { $_SESSION['state'] = 1; $state = 1; $_SESSION['oauth_tokens'] = NULL; $tokens = NULL; $link = $oauth->getAuthorizeUrl($call_back_link) . "\n"; return self::tryToConnect($call_back_link, $user_id); break; } // There is no break here, intentional /* This part gets called if the authentication process already succeeded. We can use our stored tokens and the api should work. Store these tokens somewhere, like a database */ // There is no break here, intentional /* This part gets called if the authentication process already succeeded. We can use our stored tokens and the api should work. Store these tokens somewhere, like a database */ case 3: try { $oauth->setToken($_SESSION['oauth_tokens']); //checks if Connection is Good $dropbox->getAccountInfo(); } catch (\Dropbox_Exception $e) { $_SESSION['state'] = 1; $state = 1; $link = $oauth->getAuthorizeUrl($call_back_link) . "\n"; unset($_SESSION['oauth_tokens']); // delete the stored token self::deleteToken($user_id); return self::tryToConnect($call_back_link, $user_id); } catch (\HTTP_OAuth_Exception $e) { $_SESSION['state'] = 1; $state = 1; $link = $oauth->getAuthorizeUrl($call_back_link) . "\n"; unset($_SESSION['oauth_tokens']); // delete the stored token self::deleteToken($user_id); return self::tryToConnect($call_back_link, $user_id); } break; } //connection should be good self::storeToken($user_id); return "connected"; } catch (Exception $e) { return false; } catch (\HTTP_OAuth_Exception $e) { return false; } catch (\Dropbox_Exception $e) { return false; } }