passport-hatena-oauth
v1.0.0
Published
Hatena authentication strategy for passport.
Downloads
15
Maintainers
Readme
Passport-Hatena
===============
Passport strategy for authenticating with Hatena using the OAuth 1.0a 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-oauth
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('/');
});