Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #30 from aslakhellesoy/dropbox-with-info

Added info option to get user info.
  • Loading branch information...
commit 6added0f7719b5a339859a4bd6df0fcb3c3bcf32 2 parents 7bd6763 + 2edc6d9
Jed Schmidt authored October 24, 2012
2  README.md
Source Rendered
@@ -267,6 +267,7 @@ Options:
267 267
 - `service`: "dropbox"
268 268
 - `id`: the application's `App key`
269 269
 - `secret`: the application's `App secret`
  270
+- `info`: specify `true` if you want to get the user info (a little slower - one extra request)
270 271
 
271 272
 Example:
272 273
 
@@ -275,6 +276,7 @@ var dropbox = authom.createServer({
275 276
   service: "dropbox",
276 277
   id: "zuuteb2w7i82mdg",
277 278
   secret: "rj503lgqodxzvbp"
  279
+  info: true
278 280
 })
279 281
 ```
280 282
 
3  example/express.js
@@ -87,7 +87,8 @@ authom.createServer({
87 87
 authom.createServer({
88 88
   service: "dropbox",
89 89
   id: "zuuteb2w7i82mdg",
90  
-  secret: "rj503lgqodxzvbp"
  90
+  secret: "rj503lgqodxzvbp",
  91
+  info: true
91 92
 })
92 93
 
93 94
 authom.createServer({
3  example/server.js
@@ -124,7 +124,8 @@ authom.createServer({
124 124
 authom.createServer({
125 125
   service: "dropbox",
126 126
   id: "zuuteb2w7i82mdg",
127  
-  secret: "rj503lgqodxzvbp"
  127
+  secret: "rj503lgqodxzvbp",
  128
+  info: false
128 129
 })
129 130
 
130 131
 authom.createServer({
33  lib/services/dropbox.js
@@ -11,8 +11,11 @@ catch (e) {
11 11
 function Dropbox(options) {
12 12
   this.id = options.id
13 13
   this.secret = options.secret
  14
+  this.info = options.info
14 15
 
15 16
   this.on("request", this.onRequest.bind(this))
  17
+
  18
+  this.infoUrl = "https://api.dropbox.com/1/account/info"
16 19
 }
17 20
 
18 21
 Dropbox.prototype = new EventEmitter
@@ -67,12 +70,30 @@ Dropbox.prototype.onRequest = function(req, res) {
67 70
   function onToken(error, oauth_access_token, oauth_access_token_secret, results){
68 71
     if (error) return self.emit("error", req, res, uri.query)
69 72
 
70  
-    self.emit("auth", req, res, {
71  
-      token: oauth_access_token,
72  
-      secret: oauth_access_token_secret,
73  
-      id: results.uid,
74  
-      data: results
75  
-    })
  73
+    if(self.info) {
  74
+      oa.getProtectedResource(
  75
+        self.infoUrl,
  76
+        "GET",
  77
+        oauth_access_token,
  78
+        oauth_access_token_secret,
  79
+        function (error, data, response) {
  80
+          var feed = JSON.parse(data);
  81
+          self.emit("auth", req, res, {
  82
+            token: oauth_access_token,
  83
+            secret: oauth_access_token_secret,
  84
+            id: results.uid,
  85
+            data: feed
  86
+          })
  87
+        }
  88
+      )
  89
+    } else {
  90
+      self.emit("auth", req, res, {
  91
+        token: oauth_access_token,
  92
+        secret: oauth_access_token_secret,
  93
+        id: results.uid,
  94
+        data: results
  95
+      })
  96
+    }
76 97
   }
77 98
 }
78 99
 

0 notes on commit 6added0

Please sign in to comment.
Something went wrong with that request. Please try again.