Skip to content

Commit fd04434

Browse files
committed
[VD:Dropbox2] add public static function getTokenFromOauth1()
1 parent 24d2af1 commit fd04434

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

php/elFinderVolumeDropbox2.class.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,40 @@ protected function _db_joinName($dir, $displayName)
231231
return rtrim($dir, '/').'/'.$displayName;
232232
}
233233

234+
/**
235+
* Get OAuth2 access token form OAuth1 tokens.
236+
*
237+
* @param string $app_key
238+
* @param string $app_secret
239+
* @param string $oauth1_token
240+
* @param string $oauth1_secret
241+
*
242+
* @return string|false
243+
*/
244+
public static function getTokenFromOauth1($app_key, $app_secret, $oauth1_token, $oauth1_secret)
245+
{
246+
$data = [
247+
'oauth1_token' => $oauth1_token,
248+
'oauth1_token_secret' => $oauth1_secret,
249+
];
250+
$auth = base64_encode($app_key.':'.$app_secret);
251+
252+
$ch = curl_init('https://api.dropboxapi.com/2/auth/token/from_oauth1');
253+
curl_setopt($ch, CURLOPT_POST, true);
254+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
255+
curl_setopt($ch, CURLOPT_HTTPHEADER, [
256+
'Content-Type: application/json',
257+
'Authorization: Basic '.$auth,
258+
]);
259+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
260+
$result = curl_exec($ch);
261+
curl_close($ch);
262+
263+
$res = $result ? json_decode($result, true) : [];
264+
265+
return isset($res['oauth2_token']) ? $res['oauth2_token'] : false;
266+
}
267+
234268
/*********************************************************************/
235269
/* EXTENDED FUNCTIONS */
236270
/*********************************************************************/

0 commit comments

Comments
 (0)