I am trying to build a small application using NodeJS , node-dbox and Express . When you request authorization DropBox is a three-step process , first you need to get request_token , then the user allows them to visit the Dropbox page and only then request access_token based on request_token and the fact that the user has an authorized request.
However, by the time I served the page for steps 1 and 2 (getting the request_token and providing the user with a URL), the request_token instance disappeared !, so in step 3 I canβt request access_token , because it requires request_token
I am trying to store request_token in a cookie, but given that it contains sensitive data, sending it to a client might not be such a good idea. Any ideas?
The simplified code is given below:
(function() { var dbox = require('dbox'), config = require('easy-config'), express = require('express'), dboxApp = dbox.app(config.dropbox_credentials), app = express(); app.use(express.cookieParser()); app.get('/', function(req, res) { dboxApp.requesttoken(function(status, request_token) { res.cookie('request_token', JSON.stringify(request_token)); res.send("<a href='" + request_token.authorize_url + "' targe='_new'>authorize via dropbox</a><br/>" + "<a href='/next'>next</a>"); }); }); app.get('/next', function(req, res) { var request_token = JSON.parse(req.cookies.request_token); if(request_token) { dboxApp.accesstoken(request_token, function(status, access_token) { var client = dboxApp.client(access_token); client.account(function(status, reply){ res.send(reply); }); }); } else { res.send('sorry :('); } }); app.listen(3000); })();
bonus question: client is created using access_token , so any client instance or access_token should be supported on all page updates, and what works best?