index.php
<?php
include_once __DIR__.'/app/start.php';
include_once __DIR__.'/app/dropbox_auth.php';
?>
start.php
<?php
session_start();
$_SESSION['user_id'] = 1;
require_once __DIR__.'/../vendor/dropbox-sdk/lib/Dropbox/autoload.php';
$key = "35ihzafqgsubhdk";
$secret = "q2ow8djsqnp72aa";
$GLOBALS['app_name'] = "samidha/1.0";
$GLOBALS['redirectURI'] = "https://localhost/drop/dropbox_finish.php";
$GLOBALS['HomeURI'] = "https://localhost/drop/";
$appInfo = new Dropbox\AppInfo($key, $secret);
//CSRF Cross Site Request Forgery protection.
$csrfTokenStore = new Dropbox\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
$webAuth = new Dropbox\WebAuth($appInfo, $GLOBALS['app_name'], $GLOBALS['redirectURI'], $csrfTokenStore);
$db = new PDO('mysql:host=localhost;dbname=drop_api','root','');
$user = $db->prepare("SELECT * FROM users WHERE id = :user_id");
$user->execute(['user_id' => $_SESSION['user_id']]);
$user = $user->fetchObject();
?>
dropbox_auth.php
<?php
if ($user->token){
$client = new Dropbox\Client($user->token, $GLOBALS['app_name'], 'UTF-8');
$client->getAccountInfo();
} else {
$authURL = $webAuth->start();
header("Location: $authURL");
exit();
}
?>
dropbox_finish
<?php
require_once "/app/start.php";
list($accessToken) = $webAuth->finish($_GET);
$store = $db->prepare("UPDATE users SET token = :dropbox_token"
. "WHERE id = :user_id");
$store->execute(['dropbox_token' => $accessToken,
'user_id' => $_SESSION['user_id']]);
header("Location: ".$GLOBALS['HomeURI']);
?>
Show me error in wamp server
! ) Fatal error: Uncaught exception 'Dropbox\WebAuthException_BadState' with message 'Missing CSRF token in session.' in H:\wamp\www\Drop\vendor\dropbox-sdk\lib\Dropbox\WebAuth.php on line 235
( ! ) Dropbox\WebAuthException_BadState: Missing CSRF token in session. in H:\wamp\www\Drop\vendor\dropbox-sdk\lib\Dropbox\WebAuth.php on line 235
Call Stack
# Time Memory Function Location
1 0.0010 132144 {main}( ) ...\dropbox_finish.php:0
2 0.0390 497696 Dropbox\WebAuth->finish( )
I am trying to allow my code to access the dropbox functionality with php but its getting error in dropbox_finish as shown above please help me.