From 42c41271e3981a3e20391bc71e2afab0ee2e289c Mon Sep 17 00:00:00 2001 From: Daniel Wylie Date: Wed, 28 Sep 2016 16:17:30 +1300 Subject: [PATCH 1/2] Add tokenfromoauth1 method to upgrade to Dropbox API v2 --- lib/dbox.js | 29 ++++++++++++++++++++++++++++- lib/helpers.js | 4 ++-- test/all.js | 7 +++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/dbox.js b/lib/dbox.js index b2d317b..ed48645 100644 --- a/lib/dbox.js +++ b/lib/dbox.js @@ -622,7 +622,34 @@ exports.app = function(config){ var args = { "method": "POST", - "headers": { + "headers": { + "content-type": "application/x-www-form-urlencoded", + "content-length": body.length + }, + "url": url, + "body": body + } + return request(args, function(e, r, b){ + cb(e ? null : r.statusCode, e ? null : helpers.parseJSON(b)) + }) + }, + + tokenfromoauth1: function(cb){ + var signature = helpers.sign(options) + signature["root"] = root + + var url = helpers.url({ + hostname: "api.dropbox.com", + action: "oauth2/token_from_oauth1" + }) + + console.log(url); + + var body = qs.stringify(signature) + + var args = { + "method": "POST", + "headers": { "content-type": "application/x-www-form-urlencoded", "content-length": body.length }, diff --git a/lib/helpers.js b/lib/helpers.js index e532ffd..beb2501 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -108,12 +108,12 @@ module.exports = function(config){ throw "must have proper base, version, and action" // calculate if fileops path - var fileop = obj.action.split("/")[0] == "fileops" + var fileop = obj.action.split("/")[0] == "fileops" || obj.action.split("/")[0] === "oauth2" // fileops calls desn't want root in path var rootpath = fileop ? "" : root - // fileops calls desn't want scope in path + // fileops and oauth2 calls desn't want scope in path var scopepath = fileop ? "" : scope // we wont always have this diff --git a/test/all.js b/test/all.js index 10cc019..65da4b9 100644 --- a/test/all.js +++ b/test/all.js @@ -185,6 +185,13 @@ describe("all", function(){ done() }) }) + + it("should get oauth2 token from oauth1 token", function(done) { + client.tokenfromoauth1(function(status, reply){ + status.should.eql(200) + done() + }) + }) after(function(){ //console.log("after step") From f4dc502edd975e25c0ffe6921acb7d8ab9dd1864 Mon Sep 17 00:00:00 2001 From: Daniel Wylie Date: Thu, 29 Sep 2016 14:52:31 +1300 Subject: [PATCH 2/2] Remove console log --- lib/dbox.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/dbox.js b/lib/dbox.js index ed48645..3298d00 100644 --- a/lib/dbox.js +++ b/lib/dbox.js @@ -643,8 +643,6 @@ exports.app = function(config){ action: "oauth2/token_from_oauth1" }) - console.log(url); - var body = qs.stringify(signature) var args = {