JJJollyjim
JJJollyjim

Reputation: 6217

Always using the same OAUTH code with Dropbox-js

I'm using the official Dropbox JS library in a Node.js server. It only ever needs to authenticate as a single user, and it can't go through the whole OAUTH browser setup every time the server starts. I am attempting to write an auth driver that pretends to be like the NodeServer driver, but runs the callback straight away with a code that always stays the same.

Here's what I've got (it's coffeescript, but you get the idea):

myAuthDriver = {
    authType: -> return "code"
    url: -> return "http://localhost:8912/oauth_callback" # What the url would be if I were using NodeServer
    doAuthorize: (authUrl_s, stateParam, client, callback) ->
        authUrl = url.parse(authUrl_s, true)

        callback({
            code: "[a code I just got using the NodeServer driver]"
            state: authUrl.query.state
        })
}

Running authenticate with this driver set causes this error:

Dropbox OAuth error invalid_grant :: given "code" is not valid

The docs say that this should only occur with a broken auth driver (but it doesn't give any ideas for fixing it).

Does anyone with more knowledge of OAUTH or Dropbox know what's wrong here?

Note: I've found in several places online that Dropbox OAUTH codes never expire

Upvotes: 0

Views: 1182

Answers (1)

user94559
user94559

Reputation: 60143

Once you have an OAuth 2 access token, you can just do var client = new Dropbox.Client({token: '<your token>'});. No need for an auth driver at all.

(If you want an easy way to get an access token, consider using https://dbxoauth2.site44.com.)

Upvotes: 2

Related Questions