Giter VIP home page Giter VIP logo

rm-session-populator's Introduction

RM-SESSION-POPULATOR

This Middleware is designed to work in NodeJS Express Backends with the rm-authenticator and a Front-End that is connected to that Authenticator as well.

Docker - rm-authenticator
GitHub - rm-authenticator

When the Front-End sends you a request containing a session cookie, the middleware will automatically populate the request Object with a user Property containing all the user information

Installation

  npm install --save rm-session-populator

Use

You configure the Session Populator with the Options Object. This has several possible Settings

authenticatorHost Hostname where your rm-authenticator is running. By default it's http://localhost:8081

authenticatorUserPath: The path to the endpoint where userinfo is stored. By default it uses the authenticators default /auth/userinfo

credentialsCookieName:: The Name of the Session Cookie. Defaults to connect.sid

rejectWithoutAuthentication: Determines the behaviour of the middleware. If set to true (which it is by default) it will automatically reject any request made to the backend as unauthorized that is missing a cookie and web token. If it is set to false it will poplulate the user property with null

jwtMode: defaults to direct. If set to direct JWT will use the secret provided with the jwt Secret option to verify your web token. If set to key it will use the public key from a file

jwtSecret: Only has to be set if jwtMode is direct. The secret will be used to verify the web token if present. You will have to set the same Secret in the Authenticator.

jwtKeyLocation: Only needs to be set if jwtMode is key. Points to the Public Key in the file system. Defaults to /data/public_key.pem

jwtHeaderName: Session Populator will by default look for the Bearer token in the "Authorization" Header. If you want to use another header, you can change this here.

To implement the middleware do the following

JavaScript

const express = require("express");
const cookieParser = require("cookie-parser");
const sessionPopulate = require("rm-session-populator");
const app = express();

app.use(cookieParser());
app.use(express.json());
app.use(
  sessionPopulate({
    authenticatorHost: "https://my-own-host:443",
    rejectWithoutAuthentication: false,
    jwtMode: "key",
    // jwtSecret: "superSecret",
    jwtKeyLocation: "/data/privateKey.pem",
  })
);

TypeScript

import express from "express";
import cookieParser from "cookie-parser";
import sessionPoplulate from "rm-session-populator";

const app = express();

app.use(cookieParser());
app.use(express.json());
app.use(
  sessionPopulate({
    authenticatorHost: "https://my-own-host:443",
    rejectWithoutAuthentication: false,
    jwtMode: "key",
    // jwtSecret: "superSecret",
    jwtKeyLocation: "/data/privateKey.pem",
  })
);

rm-session-populator's People

Contributors

dependabot[bot] avatar relief-melone avatar xan2063 avatar

Watchers

 avatar  avatar

rm-session-populator'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.