GithubHelp home page GithubHelp logo

hapi-passport's Introduction

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

hapi-passport's People

Contributors

atuyl avatar martinheidegger avatar cvan avatar achingbrain avatar

Stargazers

John Magdy Lotfy Kamel avatar Denis avatar Asad Dhamani avatar PaulZeng avatar Supachai avatar Hannan Ali avatar Kamron Batman avatar Yılmaz Uğurlu avatar Gustavo Adolfo Cruz Laura avatar Matt Travi avatar  avatar Hongbo LU avatar Thomas Lekanger avatar Austris avatar  avatar Chris Alatorre avatar Will Monk avatar Jaehoon Jung avatar

Watchers

exilis avatar  avatar James Cloos avatar  avatar Tony Brown avatar Chris Alatorre avatar Himanshu Kansal avatar

hapi-passport's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.