@nazarkulyk/passport-env
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

passport-env

Passportjs authentication strategy based on OS/pod/container enviroment variables.

As example on macosx you always has ${USER} set to current user name.

How to use

import { Strategy } from 'passport';
import { EnvAuthStrategy, VerifyFunction } from '@nazarkulyk/passport-env';

const userIdEnvVariableName = 'USER';
const envVariables = [userIdEnvVariableName];

const verifyFn: VerifyFunction = (verifyEnvVariables, done) => {
    const id = verifyEnvVariables[userIdEnvVariableName];
  return !id ? done(null) : done(null, { id });
};

const createStrategy = (): Strategy => new EnvAuthStrategy({ envVariables }, verifyFn);

Than i your Express Routes:

app.get('/auth/env-auth', authenticate('env-auth', { session: false }), (req, res) => {
  res.send({ authenticated: true, user: req.user });
});

Package Sidebar

Install

npm i @nazarkulyk/passport-env

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

10.4 kB

Total Files

9

Last publish

Collaborators

  • nazarkulyk