0.0.2 • Published 11 years ago

passport-hatena v0.0.2

Weekly downloads
7
License
-
Repository
github
Last release
11 years ago

Passport-Hatena

===============

OAuth1.0a npm package for Hatena

Passport strategy for authenticating with YConnect using the OAuth 2.0 API

This module can be used with passport in Node.js. You can integrate into below applications or frameworks. Connect-style middleware, including Express.

Install

$ npm install passport-hatena

Usage

Configuration Strategy

This Hatena passport module requires your application' id. You can get this id from Hatena Developer Center

Authorization Endpoint

passport.use(new HatenaStrategy({
    consumerKey: HATENA_CONSUMER_KEY,
    consumerSecret: HATENA_SECRET_KEY,
    callbackURL: "http://127.0.0.1:3000/auth/hatena/callback"
  },
  function(token, tokenSecret, profile, done) {
    User.findOrCreate({ hatenaId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate(), specifying the 'hatena' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/hatena',
  passport.authenticate('hatena'), { scope: ['read_public'] });

app.get('/auth/hatena/callback',
  passport.authenticate('hatena', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

Examples

For a complete, working example, refer to the login example.

License

The MIT License