Permalink
Browse files

Add support for RunKeeper HealthGraph API

  • Loading branch information...
1 parent ae47e87 commit 25d4ae461f78eaa9133a7336ca8c2b14d2957611 @akinsella akinsella committed May 26, 2012
Showing with 91 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +31 −0 README.md
  3. +4 −0 example/conf.js
  4. +9 −0 example/server.js
  5. +6 −0 example/views/home.jade
  6. +39 −0 lib/modules/runkeeper.js
  7. BIN media/runkeeper.ico
View
2 .gitignore
@@ -5,3 +5,5 @@ issues
IRC.md
playground.js
CHANGES
+npm-debug.log
+.idea
View
31 README.md
@@ -52,6 +52,8 @@ So far, `everyauth` enables you to login via:
<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>
+ <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>
@@ -2112,6 +2114,35 @@ connect(
).listen(3000);
```
+### RunKeeper OAuth (2.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
OpenID protocol allows you to use an openid auth request. You can read more information about it here http://openid.net/
View
4 example/conf.js
@@ -116,4 +116,8 @@ module.exports = {
consumerKey: 'Enter your consumer key here'
, consumerSecret: 'Enter your consumer secret here'
}
+ , runkeeper: {
+ appId: 'Enter your client/app id here'
+ , appSecret: 'Enter your client/app secret here'
+ }
};
View
9 example/server.js
@@ -51,6 +51,7 @@ var usersBySoundCloudId = {};
var usersByMailchimpId = {};
var usersMailruId = {};
var usersByMendeleyId = {};
+var usersByRunKeeperId = {};
var usersByLogin = {
'brian@example.com': addUser({ login: 'brian@example.com', password: 'password'})
};
@@ -379,6 +380,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)
View
6 example/views/home.jade
@@ -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;
@@ -177,5 +180,8 @@
- if (everyauth.mendeley)
h3 Mendeley User Data
p= JSON.stringify(everyauth.mendeley.user)
+ - if (everyauth.runkeeper)
+ h3 Runkeeper User Data
+ p= JSON.stringify(everyauth.runkeeper.user)
h3
a(href='/logout') Logout
View
39 lib/modules/runkeeper.js
@@ -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;
+ });
View
BIN media/runkeeper.ico
Binary file not shown.

0 comments on commit 25d4ae4

Please sign in to comment.