npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@codealpha/oauth2

v0.2.4

Published

faux IAM

Downloads

23

Readme

AuthN

Faux IAM.

reference material:

Installation

npm i @codealpha/oauth2 --save

Example

import {oauth} from '@codealpha/oauth2'
const oauthConfig = {...}

const Server = async () => {
  const { authN, authZ } = await oauth(oauthConfig);

  app
    .use(express.static(path.join(__dirname, "public")))
    .use("/auth", authN)
    .use("/private/stuff", [
      authZ,
      (req, res) => {
        res.send({ message: "welcome VIP", data: ["a", 2, { b: true }] });
      },
    ])
    .listen(5000, () => {
      console.log(`OAuth2 Server started at http://localhost:5000`);
    });
};

Usage

authN

.use("/auth", authN)

"/ui":

  • AS User Interface

"/client":

  • data about the website using the AS

"/user/whoami":

  • user object

authZ

.use("/private/stuff",
      authZ,
      (req, res) => {
        res.send({ message: "welcome VIP", data: ["a", 2, { b: true }] });
      },
    )

ClientSide Callback workflow

Post login:

  1. client website recieves authCode.
  2. client website exchanges authCode for authToken.
  3. client website uses authToken to make API requests.

Configuration

const oauthConfig = {
  database: {
    type: "postgres",
    config: {
      user: "DATABASE_USERNAME",
      host: "DATABASE_HOST",
      password: "DATABASE_PASSWORD",
      port: 5432,
    },
  },
};

| key | Description | Default | | ------------- |-----------| -----:| | awsCredentialsPath | the absolute file path to the AWS credentials.json file | | | mfaRequired | a SMS code is required on login in addition to a username/password. | false | | emailSalt | a bcrypt salt used to encrypt data at rest | no encryption | | database * | | | | database.type | type of database | [string] | | database.config | configuration object specific to a database | [Object] | | client | | | | client.name | name of website using OAuth2 | 'OAuth2Placeholder' | | client.website | fqdn of website using OAuth2 | 'OAuth2Placeholder' | | client.badgeUrl | url of brand image used to customize OAuth2 pages | | |registrationWhitelist | only allow a defined list of usernames to register | any |

Running Example (dev mode)

Authentication Server UI

  1. Start client
    1. cd to /client
    2. run:
      npm start

Build server & end-user functions

  1. Setup initial builds and watch for changes.
    1. from project root
    2. run:
      npm run cli start

Example end-user application

  1. Start Example
    1. from project root
    2. run:
      npm run cli example

Publishing npm module.

  1. Create NPM granular access token. StackOverflow ref
    1. run:
      npm config set _authToken=GRANULAR_ACCESS_TOKEN
      • if you get an error like Invalid auth configuration found: '_authToken' must be renamed to '//registry.npmjs.org/:_authToken' in user config.
      1. run:
        npm config fix
  2. Publish to NPM.
    1. from project root
    2. run:
      npm run publishit