hapi-passport

Passport strategy wrapper for hapi

Showing:

Popularity

Downloads/wk

468

GitHub Stars

17

Maintenance

Last Commit

7yrs ago

Contributors

5

Package

Dependencies

0

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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.
        }
    })
});

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial