Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tokenfromoauth1 method to upgrade to Dropbox API v2 #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/dbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down