Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/akinsella/everyauth into …
Browse files Browse the repository at this point in the history
…akinsella-master

Conflicts:
	README.md
	example/conf.js
	example/server.js
	example/views/home.jade
  • Loading branch information
bnoguchi committed Aug 8, 2012
2 parents 8c11710 + 950559d commit c9c8da4
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ issues
IRC.md
playground.js
CHANGES
npm-debug.log
.idea
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ So far, `everyauth` enables you to login via:
<td> <a href="https://github.com/edy-b">Eduard Baun</a>
<tr> <td> <img src="https://github.com/bnoguchi/everyauth/raw/master/media/smarterer.ico" style="vertical-align:middle"> Smarterer
<td> <a href="https://github.com/kaizenpack">kaizenpack</a>
<tr> <td> <img src="https://github.com/bnoguchi/everyauth/raw/master/media/runkeeper.ico" style="vertical-align:middle"> RunKeeper
<td> <a href="https://github.com/akinsella">Alexis Kinsella</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>
Expand Down Expand Up @@ -2116,6 +2118,35 @@ connect(
).listen(3000);
```
### RunKeeper OAuth (2.0)
You will first need to [register your application](http://runkeeper.com/partner/applications) to get the appId and appSecret.
```javascript
everyauth.runkeeper
.appId('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 usersByRunKeeperId[user.userID] || (usersByRunKeeperId[user.userID] = 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
OpenID protocol allows you to use an openid auth request. You can read more information about it here http://openid.net/
Expand Down
14 changes: 9 additions & 5 deletions example/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,13 @@ module.exports = {
, mendeley: {
consumerKey: 'Enter your consumer key here'
, consumerSecret: 'Enter your consumer secret here'
}
, weibo: {
appId: '3350967939'
, appSecret: 'ef7f0a836d0ef315dca53e8d73816cc0'
}
}
, weibo: {
appId: '3350967939'
, appSecret: 'ef7f0a836d0ef315dca53e8d73816cc0'
}
, runkeeper: {
appId: 'Enter your client/app id here'
, appSecret: 'Enter your client/app secret here'
}
};
9 changes: 9 additions & 0 deletions example/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var usersMailruId = {};
var usersByMendeleyId = {};
var usersByDcId = {};
var usersByWeiboId = {};
var usersByRunKeeperId = {};
var usersByLogin = {
'[email protected]': addUser({ login: '[email protected]', password: 'password'})
};
Expand Down Expand Up @@ -389,6 +390,14 @@ everyauth.mendeley
})
.redirectPath('/');

everyauth.runkeeper
.appId(conf.runkeeper.appId)
.appSecret(conf.runkeeper.appSecret)
.findOrCreateUser(function(sess, accessToken, accessSecret, user) {
return usersByRunKeeperId[user.userID] || (usersByRunKeeperId[user.userID] = addUser('runkeeper', user));
})
.redirectPath('/');

everyauth
.soundcloud
.appId(conf.soundcloud.appId)
Expand Down
6 changes: 6 additions & 0 deletions example/views/home.jade
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
#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')
#runkeeper-login
a(href='/auth/runkeeper', style='border: 0px')
img(src='http://d2b4ufapzmnxpw.cloudfront.net/build/3572/static/kronos/images/logo.png', title='Login with Runkeeper')
#openid-login
form#openid(action='/auth/openid')
label(for='openid_identifier') OpenID Identifier: &nbsp;
Expand Down Expand Up @@ -185,5 +188,8 @@
p= JSON.stringify(everyauth.dailycred.user.email)
- if (everyauth['weibo'])
p= JSON.stringify(everyauth.weibo.user)
- if (everyauth.runkeeper)
h3 Runkeeper User Data
p= JSON.stringify(everyauth.runkeeper.user)
h3
a(href='/logout') Logout
39 changes: 39 additions & 0 deletions lib/modules/runkeeper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var oauthModule = require('./oauth2')
, request = require('request');

var runkeeper = module.exports =
oauthModule.submodule('runkeeper')
.configurable({
scope: 'specify types of access: (no scope), non-expiring'
})
.apiHost('https://api.runkeeper.com')
.oauthHost('https://runkeeper.com')
.authPath('/apps/authorize')
.accessTokenPath('/apps/token')
.entryPath('/auth/runkeeper')
.callbackPath('/auth/runkeeper/callback')
.authQueryParam('response_type', 'code')
.authQueryParam('scope', function () {
return this._scope && this.scope();
})
.accessTokenHttpMethod('post')
.postAccessTokenParamsVia('data')
.accessTokenParam('grant_type', 'authorization_code')
.fetchOAuthUser(function (accessToken) {
console.log("Access Token: ", accessToken);
var promise = this.Promise();
request.get({
url: this.apiHost() + '/user'
, headers: {
'Authorization': 'Bearer ' + accessToken
}
}, function (err, res, body) {
if (err) return promise.fail(err);
if (parseInt(res.statusCode / 100, 10) !== 2) {
return promise.fail(body);
}
return promise.fulfill(JSON.parse(body));
});

return promise;
});
Binary file added media/runkeeper.ico
Binary file not shown.

0 comments on commit c9c8da4

Please sign in to comment.