phpdropboxdropbox-apidropbox-php

Missing CSRF token in session


I am creating the application which can fetch the files and folder from the dropbox and will show in the web page.I have the below code.

$appInfo=new Dropbox\AppInfo($dropboxKey,$dropboxSecret);
//store CSRF token
$csrfTokenStore = new Dropbox\ArrayEntryStore($_SESSION,'dropbox-auth-csrf-token');
$webAuth = new Dropbox\WebAuth($appInfo,$appName,'path',$csrfTokenStore);

when i execute the code i got the below error:

Fatal error: Uncaught exception 'Dropbox\WebAuthException_BadState' with message 'Missing CSRF token in session.


Solution

  • The problem is happening because of there is no dropbox-auth-csrf-token value in the session.When you check the ArrayEntryStore files you get to know there are function like get(),set(),clear().Here clear function will unset the csrf token.

    What you have to do is you need to store the csrf token value in database and when same user comes to need to fetch the value and pass it into the ArrayEntryStore else do the same.