Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add cookie and session support to Dropbox file browser example.
app.configure(function() {
app.use(express.logger());
app.use(express.bodyDecoder());
app.use(express.cookieDecoder()); // Cookie-decoding.
app.use(express.session()); // Session-handling.
});
// File browser page.
app.get('/file_browser(/*)?', function(req, res) {
// Fetch target metadata and render the page.
if (req.session.dropbox) {
req.session.dropbox.getMetadata(req.params[1] || '',
function(err, metadata) {
if (err) console.log('Error: ' + sys.inspect(err));
else {
res.render('file_browser.jade', {
locals: {
title: 'Dropbox File Browser',
current_dir: (metadata.path.length > 0) ? metadata.path : 'root',
items: metadata.contents
}
});
}
});
} else res.redirect('home');
});
// Upon response, extract access token/secret and redirect to file_browser.
request.on('response', function(token_res) {
token_res.setEncoding('utf8');
token_res.on('data', function(chunk) {
var token_res = JSON.parse(chunk),
access_token = token_res['token'],
access_token_secret = token_res['secret'];
req.session.dropbox = new DropboxClient(oauth, access_token,
access_token_secret);
res.redirect('/file_browser');
});
});
// Set up persistent variables.
// Delete this section or comment out the following line.
//var access_token = '', access_token_secret = '', dropbox = null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.