Dropbox showing error, when asking for access token

守給你的承諾、 提交于 2019-12-25 02:58:11

问题


I I am working on a PHP application in which I need to integrate Dropbox. I am doing this in file1.php file. Following is the code:

require_once ("../dropbox-sdk/Dropbox/autoload.php");
    use \Dropbox as dbx;
    $appInfo = dbx\AppInfo::loadFromJsonFile("../dropbox-config.json");
    $csrfTokenStore = new dbx\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
    $webAuth = new dbx\WebAuth($appInfo, "MyApp", "https://example.net/app2/OAuthRedirectURI.php", $csrfTokenStore);
    $authorizeUrl = $webAuth->start('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']."|".session_id());

Since redirect uri cannot be dynamic, I have specified redirect uri to https://example.net/app2/RedirectURI.php.

In $webAuth->start() method, I have sent full path of file1.php and session id. This is because, I need to redirect to file1.php from RedirectURI.php file.

Following is the code of RedirectURI.php:

$stateArray = explode("|", $_GET['state']);
    session_id($stateArray[2]);
    session_start();
    $_GET['state'] = $stateArray[0];
    $_SESSION['DBX_AUTH_CODE_GET'] = $_GET;
    header("location:".$stateArray[1]);

In RedirectURI.php, I am getting auth code and parameters that I have sent, separated by pipe symbol. After creating session, I put $_GET array in session and redirected to file1.php.

In file1.php, following is the code to get access token:

if(isset($_SESSION['DBX_AUTH_CODE_GET'])){
$x = $_SESSION['DBX_AUTH_CODE_GET'];
        list($accessToken, $userId, $urlState) = $webAuth->finish($x);
        echo "access token: " . $accessToken;
    }

But it is showing error:

PHP fatal error in line 242 of file /var/www/html/example/public_html/app2/dropbox-sdk/Dropbox/WebAuth.php.
Uncaught exception 'Dropbox\WebAuthException_Csrf' with message 'Expected '6r9eW-MB82JxkJU9AE7u9g==', got 'KkgZk4491XEPhsn_14EObw=='.' in 
/var/www/html/example/public_html/app2/dropbox-sdk/Dropbox/WebAuth.php:242nStack trace:n#0 /var/www/html/example/public_html/app2/pm/file1.php(40): 
Dropbox\WebAuth->finish(Array)n#1 {main}n thrown

I have no idea why this is happening.

来源:https://stackoverflow.com/questions/29845655/dropbox-showing-error-when-asking-for-access-token

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!