hapi-passport
Passport Strategy connector to hapi
Last updated 6 years ago by leichtgewicht .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install hapi-passport 
SYNC missed versions from official npm registry.

hapi-passport

hapi-passport is supposed to be a connector between passport.js strategies and the hapi request api. Right now its in a early phase so its only tested with facebook.

usage

You need to install hapi-passport together with the connector strategies like passport-facebook.

$ npm install hapi-passport passport-facebook

With this you can make a request handler like this:

var FacebookStrategy = require("passport-facebook"),
    facebookLogin = require("hapi-passport")(new FacebookStrategy(...));

and connect it hapi using

server.routes({method: "GET", path: "/login/facebook", facebookLogin() });

By default it would just show loose error or success messages. You can work around that by passing redirect urls for the different cases:

server.routes({
    method: "GET",
    path: "/login/facebook",
    handler: facebookLogin({
        successRedirect: "http://mydomain/login/success",
        errorRedirect: "http://mydomain/login/error",
        failRedirect: "http://mydomain/login/failed"
    })
});

... or you can use handlers for the various cases:

server.routes({
    method: "GET", path: "/login/facebook", handler: facebookLogin({
        onSuccess: function (info, request, reply) {
            // maybe do a redirect?
        },
        onFailed: function (warning, request, reply) {
            // maybe show an error?
        },
        onError: function (error, request, reply) {
            // tell the world that you are angry.
        }
    })
});

Resulting into something like:

var FacebookStrategy = require("passport-facebook"),
    facebookLogin = require("hapi-passport")(new FacebookStrategy({
        clientID: "FACEBOOK_APP_ID", // Facebook app id
        clientSecret: "FACEBOOK_APP_SECRET", // Facebook secret
        callbackURL: "http://localhost:3000/login/facebook" // needs to be added in the facebook admin interface
    }, function verify(accessToken, refreshToken, profile, verified) {
        verified(error, info);
    }));

server.routes({
    method: "GET", path: "/login/facebook", handler: facebookLogin({
        onSuccess: function (info, request, reply) {
            // maybe do a redirect?
        },
        onFailed: function (warning, request, reply) {
            // maybe show an error?
        },
        onError: function (error, request, reply) {
            // tell the world that you are angry.
        }
    })
});

Current Tags

  • 0.0.1                                ...           beta (6 years ago)
  • 0.0.6                                ...           latest (6 years ago)

6 Versions

  • 0.0.6                                ...           6 years ago
  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (5)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |