Sponsor

2012/01/04

Node.js modules you should know about: everyauth - good coders code, great reuse

Node.js modules you should know about: everyauth - good coders code, great reuse


Node.js modules you should know about: everyauth

Posted: 03 Jan 2012 09:27 AM PST


node logoHello everyone! This is the 14th post in the node.js modules you should know about article series.

The first post was about dnode - the freestyle rpc library for node, the second was about optimist - the lightweight options parser for node, the third was about lazy - lazy lists for node, the fourth was about request - the swiss army knife of HTTP streaming, the fifth was about hashish - hash combinators library, the sixth was about read - easy reading from stdin, the seventh was about ntwitter - twitter api for node, the eighth was about socket.io that makes websockets and realtime possible in all browsers, the ninth was about redis - the best redis client API library for node, the tenth was on express - an insanely small and fast web framework for node, the eleventh was semver - a node module that takes care of versioning, the twelfth was cradle - a high-level, caching, CouchDB client for node, the thirteenth was jsonstream - streaming JSON parsing library.

Today I'm gonna introduce you to everyauth by Brian Noguchi. Everyauth is a connect middleware that allows you to setup authentication for your app via facebook, twitter, google, vimeo, tumblr, 4square, etc.

Here is a list of all the sites you can use to login into your app:


Everyauth supports a plenty of sites.

Everyauth supports OpenID, Google, Twitter, LinkedIn, Yahoo, Readability, Dropbox, Justin.tv, Vimeo, Tumblr, Facebook, Github, Instagram, Foursquare, Gowalla, 37signals, AngelList, Dwolla, Box.net.

Using it is as simple as setting up a middleware for connect:

var everyauth = require('everyauth'); var connect = require('connect');  var app = connect(everyauth.middleware()); 

And setting up config.json that contains secret keys from the sites you are going to be using for authentication:

module.exports = {     fb: {         appId: '111565172259433'       , appSecret: '85f7e0a0cc804886180b887c1f04a3c1'     },     twit: {         consumerKey: 'JLCGyLzuOK1BjnKPKGyQ'       , consumerSecret: 'GNqKfPqtzOcsCtFbGTMqinoATHvBcy1nzCTimeA9M0'     },     github: {         appId: '11932f2b6d05d2a5fa18'       , appSecret: '2603d1bc663b74d6732500c1e9ad05b0f4013593'     },     // ... }; 

Then you setup routes for logging in for each particular site you want to support (in this example facebook) and you're done:

var conf = require('./config.json');  var usersByFbId = {};  everyauth   .facebook     .appId(conf.fb.appId)     .appSecret(conf.fb.appSecret)     .findOrCreateUser(function (session, accessToken, accessTokenExtra, fbUserMetadata) {       return usersByFbId[fbUserMetadata.id] ||         (usersByFbId[fbUserMetadata.id] = addUser('facebook', fbUserMetadata));     })     .redirectPath('/'); 

You can install everyauth through npm as always:

 npm install everyauth 

JSONStream on GitHub: https://github.com/bnoguchi/everyauth.

Enjoy!

If you love these articles, subscribe to my blog for more, follow me on Twitter to find about my adventures, and watch me produce code on GitHub!

No comments:

Post a Comment

Keep a civil tongue.

Label Cloud

Technology (1464) News (793) Military (646) Microsoft (542) Business (487) Software (394) Developer (382) Music (360) Books (357) Audio (316) Government (308) Security (300) Love (262) Apple (242) Storage (236) Dungeons and Dragons (228) Funny (209) Google (194) Cooking (187) Yahoo (186) Mobile (179) Adobe (177) Wishlist (159) AMD (155) Education (151) Drugs (145) Astrology (139) Local (137) Art (134) Investing (127) Shopping (124) Hardware (120) Movies (119) Sports (109) Neatorama (94) Blogger (93) Christian (67) Mozilla (61) Dictionary (59) Science (59) Entertainment (50) Jewelry (50) Pharmacy (50) Weather (48) Video Games (44) Television (36) VoIP (25) meta (23) Holidays (14)

Popular Posts (Last 7 Days)