Skip to content
FusionJS Passport Plugin
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
src
.codecov.yml
.cuprc.js
.eslintrc.js
.flowconfig
.gitignore
.npmrc
Dockerfile
LICENSE
README.md
docker-compose.yml
package.json
renovate.json
yarn.lock

README.md

fusion-plugin-passport

The fusion-plugin-passport package provides a PassportJS implementation for FusionJS. This is currently in very early release, it should work, but still lacks tests,flow typings, and some architecture changes are still planned.


Table of contents


Installation

yarn add fusion-plugin-passport

Setup

// src/main.js
import App from 'fusion-react';
import Passport, { PassportConfigToken, UserStoreToken } from 'fusion-plugin-passport';
import UniversalEvents, {
  UniversalEventsToken,
} from 'fusion-plugin-universal-events';
import root from './components/root';

export default function start(App) {
  const app = new App(root);
  app.register(Router);
if (__NODE__) {
    app.register(SessionToken, JWTSession);
    app.register(SessionSecretToken, "some-secret"); // required
    app.register(SessionCookieNameToken, "some-cookie-name"); // required
    app.register(SessionCookieExpiresToken, 86400); // optional
    app.register(PassportConfigToken, [
      {
        /*config is the default Passport Config object*/
        config: {
          clientID: "--------------", // clientID
          clientSecret: "--------------", // app secret
          scope: ["email"], // the scope
          callbackURL: "/auth/facebook/callback",
          profileFields: ["id", "emails", "displayName"] // fields to retrive
        },
        name: "facebook",
        redirect: "/",
        authUrl: "/auth/facebook",
        Strategy: FacebookStrategy
      }
    ]);
    app.register(UserStoreToken, {
      getUserByEmail() {
        return { email: "something@somethig.com", id: "1298393812093548907" };
      },
      register(ob) {
        console.warn("registered user", ob);
      },
      registerAuthForUser(auth, id, userid) {
        console.warn("NEW AUTH TYPE for user", auth, id, userid);
      }
    });
    app.register(Passport);
  }

  return app;
}

API

Registration API

Plugin
import Passport from "fusion-plugin-passport";

The plugin. The plugin requires a SessionToken to be set to store the current user information. In my examples I use JWT

PassportConfigToken
import { PassportConfigToken } from "fusion-plugin-passport";

A token for registering the passport configuration.

UserStoreToken
import { UserStoreToken } from "fusion-plugin-passport";

A token for registering the UserStoreToken to be used by the plugin to handle registration and user fetching. The user store supports has the following interface:

UserStoreToken Api
 {
    registerAuthForUser(authName : string ,id : string, userId : any ) { ....},
    register({id, email, password}) {

      // Store the user fields to a database
     },
    getUserByEmail(email : string ) {
      let user = await loadFromDatabase(email);
      return user; // this can be anything the only requirment is having a email fields and id field.
    }

Auth Events

The plugin will emit the following events/metrics via the universal events plugin if provided:

Server-side events

None, in the future I want to log login attempts that fail or seem suspicious, but I am still thinkering on how to do so.

Browser events
None
You can’t perform that action at this time.