Dropbox API v2 fix for Neotoma sync server

November 5, 2017

As part of my working sprint at IndieWebCamp Berlin today, I managed to fix a show-stopping bug that’s been in production for sync-server on Neotoma.io apparently since September 28, 2017 when Dropbox fully retired its API v1 in favor of API v2.

I wasn’t aware of this bug until this week since error handling in production hasn’t been set to notify me (via email or otherwise), but setting up that notification is now a prioritized task to avoid silent problems like this one in the future.

After digging through the code, it turned out that the Passport implementation for Dropbox specifically was not passing an apiVersion parameter upon initialization of its strategy, and as such, it was defaulting to Dropbox’s API v1 without my realization.

I’ve added apiVersion as a parameter here and also as an attribute on the storage model, specifically setting it to “2” for Dropbox’s storage document.

Note: This attribute apparently needs to be a string, not an integer, the latter of which failed to work for me when attempted.

req.strategy = new passportStrategy.Strategy({
 apiVersion: document.apiVersion,
 clientID: document.clientId,
 clientSecret: document.clientSecret,
 consumerKey: document.clientId,
 consumerSecret: document.clientSecret,
 callbackURL: `${req.protocol}://${req.get('host')}${path.resolve('/', Model.modelType(), document.slug, 'auth-callback')}`,
 passReqToCallback: true,
 profileFields: ['id', 'displayName', 'emails']

As a result, Dropbox authentication now works again and I’ve been able to run a backup job for my Foursquare / Swarm check-ins, syncing the most recent ones to my Dropbox since last running backup earlier in the summer.