Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/edy-b/everyauth into edy-…

…b-master

Conflicts:
	README.md
	example/conf.js
	example/server.js
	example/views/home.jade
  • Loading branch information...
commit d74d6a80f76d93dc79065e305fad98d252bc74b5 2 parents d0d1fd6 + 3ba53d8
@bnoguchi authored
View
39 README.md
@@ -50,6 +50,8 @@ So far, `everyauth` enables you to login via:
<td> <a href="https://github.com/ufssf">ufssf</a>
<tr> <td> <img src="http://static.mailchimp.com/www/downloads/brand-assets/Freddie_Light_Background.png" style="vertical-align:middle" width="16px"> Mailchimp
<td> <a href="http://github.com/wnadeau">Winfred Nadeau</a>
+ <tr> <td> <img src="https://github.com/bnoguchi/everyauth/raw/master/media/mendeley.ico" style="vertical-align:middle"> Mendeley
+ <td> <a href="https://github.com/edy-b">Eduard Baun</a>
</tbody>
<tbody id=misc>
<tr> <td> <img src="https://github.com/bnoguchi/everyauth/raw/master/media/box.ico" style="vertical-align:middle"> Box.net <td>
@@ -1992,6 +1994,43 @@ everyauth.mailchimp
var routes = function (app) {
// Define your routes here
};
+
+connect(
+ connect.bodyParser()
+ , connect.cookieParser()
+ , connect.session({secret: 'whodunnit'})
+ , everyauth.middleware()
+ , connect.router(routes);
+).listen(3000);
+```
+
+### Mendeley OAuth (1.0)
+
+You will first need to [register your application](http://dev.mendeley.com/applications/register/) to get the consumer key and secret.
+
+```javascript
+everyauth.mendeley
+ .consumerKey('YOUR CONSUMER KEY HERE')
+ .consumerSecret('YOUR CONSUMER SECRET HERE')
+ .findOrCreateUser( function (sess, accessToken, accessSecret, user) {
+ // find or create user logic goes here
+ //
+ // e.g.,
+ // return usersByMendeleyId[user.main.profile_id] || (usersByMendeleyId[user.main.profile_id] = user);
+ })
+ .redirectPath('/');
+
+var routes = function (app) {
+ // Define your routes here
+};
+
+connect(
+ connect.bodyParser()
+ , connect.cookieParser()
+ , connect.session({secret: 'whodunnit'})
+ , everyauth.middleware()
+ , connect.router(routes);
+).listen(3000);
```
### OpenID protocol
View
4 example/conf.js
@@ -112,4 +112,8 @@ module.exports = {
appId: 'Enter your client/app id here'
, appSecret: 'Enter your client/app secret here'
}
+ , mendeley: {
+ consumerKey: 'Enter your consumer key here'
+ , consumerSecret: 'Enter your consumer secret here'
+ }
};
View
9 example/server.js
@@ -50,6 +50,7 @@ var usersBy500pxId = {};
var usersBySoundCloudId = {};
var usersByMailchimpId = {};
var usersMailruId = {};
+var usersByMendeleyId = {};
var usersByLogin = {
'brian@example.com': addUser({ login: 'brian@example.com', password: 'password'})
};
@@ -370,6 +371,14 @@ everyauth['500px']
})
.redirectPath('/');
+everyauth.mendeley
+ .consumerKey(conf.mendeley.consumerKey)
+ .consumerSecret(conf.mendeley.consumerSecret)
+ .findOrCreateUser(function(sess, accessToken, accessSecret, user) {
+ return usersByMendeleyId[user.main.profile_id] || (usersByMendeleyId[user.main.profile_id] = addUser('mendeley', user));
+ })
+ .redirectPath('/');
+
everyauth
.soundcloud
.appId(conf.soundcloud.appId)
View
6 example/views/home.jade
@@ -83,6 +83,9 @@
img(src='http://mixi.co.jp/press/images/thumb_press_def.gif', title='Login with mixi')
#mailchimp-login
a(href='/auth/mailchimp',style='border: 0px') Login with Mailchimp
+ #mendeley-login
+ a(href='/auth/mendeley', style='border: 0px')
+ img(src='http://d1rktifm8krpj.cloudfront.net/graphics/commonnew/logo-mendeley_1248201417297118.png', title='Login with Mendeley')
#openid-login
form#openid(action='/auth/openid')
label(for='openid_identifier') OpenID Identifier: &nbsp;
@@ -171,5 +174,8 @@
- if (everyauth.mailchimp)
h3 mailchimp User Data
p= JSON.stringify(everyauth.mailchimp.user)
+ - if (everyauth.mendeley)
+ h3 Mendeley User Data
+ p= JSON.stringify(everyauth.mendeley.user)
h3
a(href='/logout') Logout
View
45 lib/modules/mendeley.js
@@ -0,0 +1,45 @@
+var oauthModule = require('./oauth'),
+ OAuth = require('oauth').OAuth;
+ var mendeley = module.exports =
+ oauthModule.submodule('mendeley')
+
+ // http://apidocs.mendeley.com/home/authentication
+ .apiHost('http://api.mendeley.com/oapi')
+ .oauthHost('http://www.mendeley.com/oauth')
+
+ .requestTokenPath('/request_token/')
+ .accessTokenPath('/access_token/')
+ .authorizePath('/authorize/')
+
+ // oauth_callback not allowed
+ .sendCallbackWithAuthorize(false)
+
+ .entryPath('/auth/mendeley')
+ .callbackPath('/auth/mendeley/callback')
+ .definit( function () {
+ this.oauth = new OAuth(
+ this.oauthHost() + this.requestTokenPath()
+ , this.oauthHost() + this.accessTokenPath()
+ , this.consumerKey()
+ , this.consumerSecret()
+ , '1.0', null, 'HMAC-SHA1');
+
+ // Mendeley does not support POST requests
+ this.oauth.setClientOptions({
+ "requestTokenHttpMethod": "GET",
+ "accessTokenHttpMethod": "GET"
+ });
+ })
+ .fetchOAuthUser( function (accessToken, accessTokenSecret, params) {
+ var p = this.Promise();
+ this.oauth.get(this.apiHost() + '/profiles/info/me/', accessToken, accessTokenSecret, function (err, data) {
+ if (err) return p.fail(err.error_message);
+ var oauthUser = JSON.parse(data);
+ p.fulfill(oauthUser);
+ })
+ return p;
+ })
+ .convertErr( function (data) {
+ return new Error(data.error_message);
+ });
+
View
BIN  media/mendeley.ico
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.