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

net-passport

v3.0.32

Published

Easily create OAuth2 keys in one line of code

Downloads

93

Readme

Net Passport

net-passport is a all-strategy (Google, Facebook, etc...) server side authentication using Passport JS mechanism in just a single line of code. You don't need any more boilerplates, repetitive configurations, strategies installations and more. Just use net-passport middleware in your express application and manage your authenticated users! In addition, net-passport gives you a simple way for sign and verify messages using your NetPassport ID.

prerequisites

If you don't have one then go to NetPassport and create an account. After that, navigate to Console (on the left):

alt text

Then, click on "Generate key pair", scroll down and download the key-pair.

Alternatively, you could upload a private key you generated by yourself.

Installation

$ npm install net-passport

Usage

const { authenticate, signer } = require("net-passport");

Get your netPassportID in NetPassportHome on the top right:

alt text

you could click the "Copy" button to copy the id and paste it inside your code.

// Create an object with the relevant parameters
const message = {
  netPassportID: "112233", // **required** your NetPassport id (String type must be provided)
  domain: "http://localhost:5000", // **required** your domain
  initUri: "/auth", // Optional - your base auth path
  redirectUri: "/auth/callback", // **required** callback auth path so NetPassport could recieve authentication callback
  successRedirect: "/success", // **required** a success relative path in case user authenticated successfully
  failureRedirect: "/failed", // ***required** a failed relative path for failed authentication
  appName: "myAwesomeApp", // **required** application name
  provider: "google", // **optional** pass a provider name from the list of providers ("google" / "facebook" / "github") to skip NetPassport sign in screen
};

Add your private key

// Pass in the .pem file or a pth to the file
const pk = fs.readFileSync(
  path.join(__dirname, "lib", "keys", "privatekey.pem"),
  "utf-8"
);

// OR

const pk = path.join(__dirname, "lib", "keys", "privatekey.pem");

Define middlewares

// Use NetPassport in a top level middleware
app.use(authenticate(pk, message));

// Define success and failed routs
app.get("/success", (req, res) => {
  res.send(`Hello ${req.session.passport.user[0].identifier}`);
});

app.get("/failed", (req, res) => {
  res.send(`Failed authentication`);
});

Authenticate without configured initUri

app.get("/:company/auth", authenticate(pk, message, { initUri: true }));

Server to server authentication

Sign data

// Initiate your message object
const message = {
  netPassportID: "112233",
  myData: "Hi there",
};

// Pass in two parameters that includes your object message (as mentioned above) and a private key or path to your private key
const signature = signer.sign(message, pk);

Verify data

// Pass in two parameters that includes your original object message and the hashed signature of the message
signer.verify(message, signature).then((verifiedMessage) => verifiedMessage);

License

MIT