Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix Dropbox plugin in sharing cases, retrieve the correct oauth tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Dec 20, 2013
1 parent 6d86024 commit e117376
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
23 changes: 21 additions & 2 deletions core/src/plugins/access.dropbox/class.dropboxAccessDriver.php
Expand Up @@ -109,11 +109,22 @@ public function isWriteable($dir, $type = "dir")

public function getTokens()
{
if($this->repository->getOption("DROPBOX_OAUTH_TOKENS") !== null && is_array($this->repository->getOption("DROPBOX_OAUTH_TOKENS"))){
return $this->repository->getOption("DROPBOX_OAUTH_TOKENS");
}
$repositoryId = $this->repository->getId();
if(AuthService::usersEnabled()) $userId = AuthService::getLoggedUser()->getId();
else $userId = "shared";
if(AuthService::usersEnabled()) {
$u = AuthService::getLoggedUser();
$userId = $u->getId();
if($u->getResolveAsParent()){
$userId = $u->getParent();
}
}else {
$userId = "shared";
}
return AJXP_Utils::loadSerialFile(AJXP_DATA_PATH."/plugins/access.dropbox/".$repositoryId."_".$userId."_tokens");
}

public function setTokens($oauth_tokens)
{
$repositoryId = $this->repository->getId();
Expand All @@ -122,4 +133,12 @@ public function setTokens($oauth_tokens)
return AJXP_Utils::saveSerialFile(AJXP_DATA_PATH."/plugins/access.dropbox/".$repositoryId."_".$userId."_tokens", $oauth_tokens, true);
}

public function makeSharedRepositoryOptions($httpVars, $repository)
{
$newOptions = parent::makeSharedRepositoryOptions($httpVars, $repository);
$newOptions["DROPBOX_OAUTH_TOKENS"] = $this->getTokens();
return $newOptions;
}


}
9 changes: 5 additions & 4 deletions core/src/plugins/access.dropbox/class.dropboxWrapper.php
Expand Up @@ -52,19 +52,20 @@ public function __construct()

public function initPath($ajxpPath)
{
$repo = ConfService::getRepository();
if (empty(self::$dropbox)) {
$repo = ConfService::getRepository();
$consumerKey = $repo->getOption('CONSUMER_KEY');
$consumerSecret = $repo->getOption('CONSUMER_SECRET');
$email = $repo->getOption('USER');
$pass = $repo->getOption("PASS");

self::$oauth = new Dropbox_OAuth_PEAR($consumerKey, $consumerSecret);
self::$oauth->setToken($_SESSION["OAUTH_DROPBOX_TOKENS"]);
self::$dropbox = new Dropbox_API(self::$oauth);
}
$basePath = $repo->getOption("PATH");
if(empty($basePath)) $basePath = "";
$parts = AJXP_Utils::safeParseUrl($ajxpPath);
$path = $parts["path"];
$path = $basePath."/".ltrim($parts["path"], "/");

if($path == "") return "/";
return $path;
}
Expand Down

0 comments on commit e117376

Please sign in to comment.