Skip to content

Commit

Permalink
Merge pull request #8 from torgeir/master
Browse files Browse the repository at this point in the history
Added dropbox oauth module
  • Loading branch information
bnoguchi committed Jun 4, 2011
2 parents a930e94 + 9c056ea commit 344a35c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
6 changes: 5 additions & 1 deletion example/conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module.exports = {
fb: {
dropbox: {
consumerKey: 'PLEASE ENTER YOUR CONSUMER KEY'
, consumerSecret: 'PLEASE ENTER YOUR CONSUMER SECRET'
}
, fb: {
appId: '111565172259433'
, appSecret: '85f7e0a0cc804886180b887c1f04a3c1'
}
Expand Down
12 changes: 12 additions & 0 deletions example/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var express = require('express')

everyauth.debug = true;

var usersByDropboxId = {};
var usersByFbId = {};
var usersByTwitId = {};
var usersByGhId = {};
Expand All @@ -21,6 +22,17 @@ var usersByLogin = {
}
};

everyauth
.dropbox
.myHostname('http://local.host:3000')
.consumerKey(conf.dropbox.consumerKey)
.consumerSecret(conf.dropbox.consumerSecret)
.findOrCreateUser( function (sess, accessToken, accessSecret, dropboxUserMetadata) {
return usersByDropboxId[dropboxUserMetadata.uid] ||
(usersByDropboxId[dropboxUserMetadata.uid] = dropboxUserMetadata);
})
.redirectPath('/')

everyauth
.facebook
.myHostname('http://local.host:3000')
Expand Down
6 changes: 6 additions & 0 deletions example/views/home.jade
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
a.fb_button_medium(href: '/auth/facebook')
span#fb_login_text.fb_button_text
Connect with Facebook
#dropbox-login
a(href: '/auth/dropbox', style: 'border: 0px')
img(src: '/')
#twitter-login
a(href: '/auth/twitter', style: 'border: 0px')
img(style='border: 0px', src: 'http://apiwiki.twitter.com/f/1242697715/Sign-in-with-Twitter-darker.png')
Expand Down Expand Up @@ -38,6 +41,9 @@
img(style: 'border: 0px', src: 'https://www.readability.com/media/images/logo_chair.png')
- else
h2 Authenticated
- if (everyauth.dropbox)
h3 Dropbox User Data
p= JSON.stringify(everyauth.dropbox.user)
- if (everyauth.facebook)
h3 Facebook User Data
p= JSON.stringify(everyauth.facebook.user)
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ everyauth.modules = {};
everyauth.enabled = {};
var includeModules = [['everymodule', false], ['password', true], ['ldap', true]
, ['oauth', false], ['twitter', true], ['linkedin', true], ['yahoo', true], ['readability', true]
, ['oauth2', false], ['facebook', true], ['github', true], ['instagram', true], ['foursquare', true], ['google', true], ['openid', true], ['googlehybrid', true]];
, ['oauth2', false], ['facebook', true], ['github', true], ['instagram', true], ['foursquare', true], ['google', true], ['openid', true], ['googlehybrid', true], ['dropbox', true]];

for (var i = 0, l = includeModules.length; i < l; i++) {
var name = includeModules[i][0]
Expand Down
18 changes: 18 additions & 0 deletions lib/dropbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var oauthModule = require('./oauth');

var dropbox = module.exports =
oauthModule.submodule('dropbox')
.apiHost('https://api.dropbox.com/0')
.oauthHost('https://www.dropbox.com/0')
.entryPath('/auth/dropbox')
.callbackPath('/auth/dropbox/callback')
.fetchOAuthUser( function (accessToken, accessTokenSecret, params) {
var p = this.Promise();
this.oauth.get(this.apiHost() + '/account/info', accessToken, accessTokenSecret, function (err, data) {
if (err) return p.fail(err);
var oauthUser = JSON.parse(data);
oauthUser.id = oauthUser.uid;
p.fulfill(oauthUser);
});
return p;
});
2 changes: 1 addition & 1 deletion lib/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ everyModule.submodule('oauth')
_provider.tokenSecret = tokenSecret;
})
.redirectToProviderAuth( function (res, token) {
res.writeHead(303, { 'Location': this.oauthHost() + this.authorizePath() + '?oauth_token=' + token });
res.writeHead(303, { 'Location': this.oauthHost() + this.authorizePath() + '?oauth_token=' + token + '&oauth_callback=' + this.myHostname() + this.callbackPath() });
res.end();
})

Expand Down

0 comments on commit 344a35c

Please sign in to comment.