Browse files

Update README.

  • Loading branch information...
1 parent 74dedd6 commit 87c388b45c72eb38c27eb219192d9120550759af @jaredhanson jaredhanson committed Oct 23, 2011
Showing with 54 additions and 0 deletions.
  1. +54 −0 README.md
View
54 README.md
@@ -3,6 +3,60 @@
[Passport](https://github.com/jaredhanson/passport) strategy for authenticating
with Twitter using the OAuth 1.0a API.
+## Installation
+
+ $ npm install passport-twitter
+
+
+#### Configure Strategy
+
+The Twitter authentication strategy authenticates users using a Twitter account
+and OAuth tokens. The strategy requires a `verify` callback, which accepts these
+credentials and calls `done` providing a user, as well as `options` specifying a
+consumer key, consumer secret, and callback URL.
+
+ passport.use(new TwitterStrategy({
+ consumerKey: TWITTER_CONSUMER_KEY,
+ consumerSecret: TWITTER_CONSUMER_SECRET,
+ callbackURL: "http://127.0.0.1:3000/auth/twitter/callback"
+ },
+ function(token, tokenSecret, profile, done) {
+ User.findOrCreate({ twitterId: profile.id }, function (err, user) {
+ return done(err, user);
+ });
+ }
+ ));
+
+#### Authenticate Requests
+
+Use `passport.authenticate()`, specifying the `'twitter'` strategy, to
+authenticate requests.
+
+For example, as route middleware in an [Express](http://expressjs.com/)
+application:
+
+ app.get('/auth/twitter',
+ passport.authenticate('twitter'),
+ function(req, res){
+ // The request will be redirected to Twitter for authentication, so this
+ // function will not be called.
+ });
+
+ app.get('/auth/twitter/callback',
+ passport.authenticate('twitter', { failureRedirect: '/login' }),
+ function(req, res) {
+ // Successful authentication, redirect home.
+ res.redirect('/');
+ });
+
+#### Examples
+
+For a complete, working example, refer to the [signin example](https://github.com/jaredhanson/passport-twitter/tree/master/examples/signin).
+
+## Credits
+
+ - [Jared Hanson](http://github.com/jaredhanson)
+
## License
(The MIT License)

0 comments on commit 87c388b

Please sign in to comment.