Let's assume our app.js/server.js looks like this:
Now, getting oAuth up and running can be easy, but you have to make sure you have mongodb up and running first, since we're using mongoose-auth. You could very well use everyauth, which mongoose-auth is based upon, though it would require a little more effort if you were to change to another database. This is pretty easy: in Ubuntu, you can just apt-get install mongodb, or in osx, brew install mongodb;. If you need to install homebrew for OSX, /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)".
Working with MongoDB
Let's connect to mongo:
To get this working, we have to add the following to our app.js:
The configuration for this file resides in a different folder, I made a config folder and put the oauth_providers.js file in there, it looks like this:
NOTE: these keypairs really shouldn't be made public, but they exist in the mongoose-auth repo, so you can test using them. This also assumes you have something setup in /etc/hosts to map local.host to 127.0.0.1, example: 127.0.0.1 local.host
In addition, we have to configure express a little differently:
The above sets up cookies, adds a session key, hooks into mongooseAuth to the app, and exposes everyauth's routes to express' views.
Now, just by visiting http://local.host:3000/auth/twitter, for example, and logging in, you'll be redirected back to the homepage. To check to make sure it's working, we have to add some views, make a folder called views and place the following in it named index.jade
And don't forget to change the route, to
And if you've been following, you'll see that all the twitter metadata is displayed. You're done! There's a lot of other things you can do, like being able to link each different account, whether or not to remember the user, and if anyone needs help with that, I can show you how to do it.