Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #22 from slickplaid/master

Added Justin.tv OAuth option
  • Loading branch information...
commit c5a75e53900a905378638838cf59949c4f77d1d5 2 parents fbef0e3 + 081cecd
@bnoguchi authored
View
82 README.md
@@ -14,6 +14,7 @@ So far, `everyauth` enables you to login via:
- `yahoo`
- `readability`                             (Credits [Alfred Nerstu](https://github.com/alfrednerstu))
- `dropbox`                                    (Credits [Torgeir](https://github.com/torgeir))
+ - `justin.tv`                                  (Credits [slickplaid](https://github.com/slickplaid))
- OAuth2
- `facebook`
- `github`
@@ -935,6 +936,87 @@ object whose parameter name keys map to description values:
everyauth.dropbox.configurable();
```
+## Setting up Justin.tv OAuth
+
+[Sign up for a Justin.tv account](http://www.justin.tv/user/signup) and activate it as a [developer account](http://www.justin.tv/developer/activate) to get your consumer key and secret.
+
+```javascript
+var everyauth = require('everyauth')
+ , connect = require('connect');
+
+everyauth.justintv
+ .consumerKey('YOUR CONSUMER KEY HERE')
+ .consumerSecret('YOUR CONSUMER SECRET HERE')
+ .findOrCreateUser( function (sess, accessToken, accessSecret, justintvUser) {
+ // find or create user logic goes here
+ //
+ // e.g.,
+ // return usersByJustintvId[justintvUser.id] || (usersByJustintvId[justintvUser.id] = justintvUser);
+ })
+ .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);
+```
+
+The `justintvUser` parameter in the `.findOrCreateUser()` function above returns the `account/whoami` API call
+
+[Justin.tv API Wiki - Account/whoami](http://apiwiki.justin.tv/mediawiki/index.php/Account/whoami)
+
+```javascript
+{
+ "image_url_huge": "http:\/\/static-cdn.justin.tv\/jtv_user_pictures\/justin-320x240-4.jpg",
+ "profile_header_border_color": null,
+ "favorite_quotes": "I love Justin.tv",
+ "sex": "Male",
+ "image_url_large": "http:\/\/static-cdn.justin.tv\/jtv_user_pictures\/justin-125x94-4.jpg",
+ "profile_about": "Check out my website:\n\nwww.justin.tv\n",
+ "profile_background_color": null,
+ "image_url_medium": "http:\/\/static-cdn.justin.tv\/jtv_user_pictures\/justin-75x56-4.jpg",
+ "id": 1698,
+ "broadcaster": true,
+ "profile_url": "http:\/\/www.justin.tv\/justin\/profile",
+ "profile_link_color": null,
+ "image_url_small": "http:\/\/static-cdn.justin.tv\/jtv_user_pictures\/justin-50x37-4.jpg",
+ "profile_header_text_color": null,
+ "name": "The JUST UN",
+ "image_url_tiny": "http:\/\/static-cdn.justin.tv\/jtv_user_pictures\/justin-33x25-4.jpg",
+ "login": "justin",
+ "profile_header_bg_color": null,
+ "location": "San Francisco"
+}
+```
+
+You can also configure more parameters (most are set to defaults) via the same chainable API:
+
+```javascript
+everyauth.justintv
+ .entryPath('/auth/justintv')
+ .callbackPath('/auth/justintv/callback');
+```
+
+If you want to see what the current value of a configured parameter is, you can do so via:
+
+```javascript
+everyauth.justintv.callbackPath(); // '/auth/justintv/callback'
+everyauth.justintv.entryPath(); // '/auth/justintv'
+```
+
+To see all parameters that are configurable, the following will return an object whose parameter name keys map to description values:
+
+```javascript
+everyauth.justintv.configurable();
+```
+
## Setting up 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
@@ -35,6 +35,10 @@ module.exports = {
consumerKey: 'Alfrednerstu'
, consumerSecret: 'MXGftcxrRNMYn66CVmADR3KRnygCdYSk'
}
+ , justintv: {
+ consumerKey: 'enter your consumer key here'
+ , consumerSecret: 'enter your consumer secret here'
+ }
, dropbox: {
consumerKey: 'uhfqnbely5stdtm'
, consumerSecret: 'jr7ofuwo32l7vkd'
View
10 example/server.js
@@ -4,6 +4,7 @@ var express = require('express')
everyauth.debug = true;
+var usersByJustintvId = {};
var usersByDropboxId = {};
var usersByFbId = {};
var usersByTwitId = {};
@@ -204,6 +205,15 @@ everyauth
})
.redirectPath('/')
+everyauth.justintv
+ .consumerKey(conf.justintv.consumerKey)
+ .consumerSecret(conf.justintv.consumerSecret)
+ .findOrCreateUser( function (sess, accessToken, accessSecret, justintvUser) {
+ return usersByJustintvId[justintvUser.id] ||
+ (usersByJustintvId[justintvUser.id] = justintvUser);
+ })
+ .redirectPath('/')
+
everyauth.box
.apiKey(conf.box.apiKey)
.findOrCreateUser( function (sess, authToken, boxUser) {
View
6 example/views/home.jade
@@ -39,6 +39,9 @@
#dropbox-login
a(href='/auth/dropbox', style='border: 0px')
img(src='https://www.dropbox.com/static/16890/images/logo.png')
+ #justintv-login
+ a(href='/auth/justintv', style='border: 0px')
+ img(src='http://s.jtvnw.net/jtv_user_pictures/hosted_images/new_logo_148_40_black.png')
#box-login
a(href='/auth/box', style='border: 0px')
img(src='http://sites.box.net/apps/web/simpleshare/img/logo.png')
@@ -79,6 +82,9 @@
- if (everyauth.dropbox)
h3 Dropbox User Data
p= JSON.stringify(everyauth.dropbox.user)
+ - if (everyauth.justintv)
+ h3 Justin.tv User Data
+ p= JSON.stringify(everyauth.justintv.user)
- if (everyauth.box)
h3 Box.net User Data
p= JSON.stringify(everyauth.box.user)
View
20 lib/modules/justintv.js
@@ -0,0 +1,20 @@
+var oauthModule = require('./oauth');
+
+var justintv = module.exports =
+oauthModule.submodule('justintv')
+
+ .apiHost('http://api.justin.tv')
+ .oauthHost('http://api.justin.tv')
+
+ .entryPath('/auth/justintv')
+ .callbackPath('/auth/justintv/callback')
+
+ .fetchOAuthUser( function (accessToken, accessTokenSecret, params) {
+ var promise = this.Promise();
+ this.oauth.get(this.apiHost() + '/api/account/whoami.json', accessToken, accessTokenSecret, function (err, data) {
+ if (err) return promise.fail(err);
+ var oauthUser = JSON.parse(data);
+ return promise.fulfill(oauthUser);
+ });
+ return promise;
+ });
Please sign in to comment.
Something went wrong with that request. Please try again.