Giter Club home page Giter Club logo

fusion-plugin-passport's Introduction

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: "[email protected]", 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

fusion-plugin-passport's People

Contributors

morphexe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.