diff --git a/lib/dbox.js b/lib/dbox.js index b2d317b..3298d00 100644 --- a/lib/dbox.js +++ b/lib/dbox.js @@ -622,7 +622,32 @@ 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" + }) + + 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")