Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added info option to get user info. #30

Merged
merged 1 commit into from

2 participants

@aslakhellesoy
Collaborator

Dropbox doesn't give much by default. This adds an info option so you can get more. Try the different modes with example/express.js and example/server.js.

@jed jed merged commit 6added0 into jed:master
@jed
Owner

thanks again, @aslakhellesoy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 24, 2012
  1. @aslakhellesoy
This page is out of date. Refresh to see the latest.
View
2  README.md
@@ -265,6 +265,7 @@ Options:
- `service`: "dropbox"
- `id`: the application's `App key`
- `secret`: the application's `App secret`
+- `info`: specify `true` if you want to get the user info (a little slower - one extra request)
Example:
@@ -273,6 +274,7 @@ var signals = authom.createServer({
service: "dropbox",
id: "zuuteb2w7i82mdg",
secret: "rj503lgqodxzvbp"
+ info: true
})
```
View
3  example/express.js
@@ -87,7 +87,8 @@ authom.createServer({
authom.createServer({
service: "dropbox",
id: "zuuteb2w7i82mdg",
- secret: "rj503lgqodxzvbp"
+ secret: "rj503lgqodxzvbp",
+ info: true
})
app.get("/auth/:service", authom.app)
View
3  example/server.js
@@ -123,7 +123,8 @@ authom.createServer({
authom.createServer({
service: "dropbox",
id: "zuuteb2w7i82mdg",
- secret: "rj503lgqodxzvbp"
+ secret: "rj503lgqodxzvbp",
+ info: false
})
authom.on("auth", function(req, res, data) {
View
33 lib/services/dropbox.js
@@ -11,8 +11,11 @@ catch (e) {
function Dropbox(options) {
this.id = options.id
this.secret = options.secret
+ this.info = options.info
this.on("request", this.onRequest.bind(this))
+
+ this.infoUrl = "https://api.dropbox.com/1/account/info"
}
Dropbox.prototype = new EventEmitter
@@ -67,12 +70,30 @@ Dropbox.prototype.onRequest = function(req, res) {
function onToken(error, oauth_access_token, oauth_access_token_secret, results){
if (error) return self.emit("error", req, res, uri.query)
- self.emit("auth", req, res, {
- token: oauth_access_token,
- secret: oauth_access_token_secret,
- id: results.uid,
- data: results
- })
+ if(self.info) {
+ oa.getProtectedResource(
+ self.infoUrl,
+ "GET",
+ oauth_access_token,
+ oauth_access_token_secret,
+ function (error, data, response) {
+ var feed = JSON.parse(data);
+ self.emit("auth", req, res, {
+ token: oauth_access_token,
+ secret: oauth_access_token_secret,
+ id: results.uid,
+ data: feed
+ })
+ }
+ )
+ } else {
+ self.emit("auth", req, res, {
+ token: oauth_access_token,
+ secret: oauth_access_token_secret,
+ id: results.uid,
+ data: results
+ })
+ }
}
}
Something went wrong with that request. Please try again.