@akoenig/sso
Opinionated wrapper around Passport.js. It supports logins via Facebook and local users.
Last updated 2 years ago by akoenig .
Original npm · Tarball · package.json
$ cnpm install @akoenig/sso 
SYNC missed versions from official npm registry.

@akoenig/sso

Opinionated wrapper around Passport.js. It supports logins via Facebook and local users.

Installation

npm install --save @akoenig/sso

Usage

Facebook

The following describes the configuration for performing a Facebook SSO

const app = express();

const restricted = sso(app, {
    facebook: {
        clientID: "<the-facebook-app-client-id>",
        clientSecret: "<the-facebook-app-client-secret>",
        callbackURL: "http://localhost:8080/auth/facebook/callback",
        successRedirect: "/",
        failureRedirect: "/login",
        authenticated: async (profile) => {
            // Insert or Update in database
        }
    }
});

This results in a new handler which can be accessed via GET /auth/facebook. The user gets redirected to Facebook and has to perform the authentication process there. Afterwards the user will be send back to callbackUrl by Facebook.

Local

The following describes the configuration for performing a local SSO (own users in a database):

const restricted = sso(app, {
    local: {
        verify: (username, password, callback) => {
            const user = YOUR_DATABASE.findUserByUsername(username);

            if (!user || user.password !== password) {
                return callback(null, false);
            }

            callback(null, user);
        },
        successRedirect: "/",
        failureRedirect: "/login",
    },
});

This registers the following route handler: POST /auth/local. You can perform a request against that route with the help of a form:

<form action="/auth/local" method="post">
    <input type="text" name="username">
    <input type="password" name="password">

    <input type="submit" value="Login">
</form>

Each time the user submits that form, the provided verify function gets executed. You have to verify the user within that function by gathering the user from your database. The parameters username and password are filled with the values from the form.

Current Tags

  • 1.2.2                                ...           latest (2 years ago)

5 Versions

  • 1.2.2                                ...           2 years ago
  • 1.2.1                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 11
Last Day 0
Last Week 5
Last Month 20
Dependencies (6)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |