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

0uth

v1.2.1

Published

![GitHub](https://img.shields.io/github/license/Mantra27/0uth) ![npm](https://img.shields.io/npm/v/0uth) ![Node.js](https://img.shields.io/node/v/0uth) ![GitHub last commit](https://img.shields.io/github/last-commit/Mantra27/0uth)

Downloads

182

Readme


Zerouth

Zerouth is a module for handling OAuth authentication in Node.js applications. It provides a middleware that simplifies the integration of various OAuth providers. With Zerouth, you can quickly set up OAuth authentication for popular platforms like Google, Discord, Reddit, Facebook, and more coming soon.

Installation

You can install Zerouth using either npm or yarn:

Using npm:

npm install 0uth

Using yarn:

yarn add 0uth

Usage

Zerouth is designed to make OAuth authentication easier in your Node.js applications. Below is an example of how to use Zerouth to handle OAuth authentication with different platforms.

const passport = require('passport');
const zerouth = require('0uth'); // Replace with the correct import path
const express = require("express");

const app = express();

//use middlwares in this sequence only
app.use(require("express-session")({ secret: 'SECRET' , resave: true, saveUninitialized: true}))
app.use(passport.initialize())
app.use(passport.session())

// Define your OAuth configuration
const GoogleConfig = {
  client: 'google',
  client_id: 'GOOGLE_CLIENT_ID',
  redirect_url: '/google/callback', //add http://localhost:3000/google/callback in google cloud console
  client_secret: 'GOOGLE_CLIENT_SECRET',
  success_redirect: '/success',
  failure_redirect: '/login',
  scope: ["email", "profile"]
};

const LocalStrategy = {
  client: 'local',
  client_id: null, //<could_use_cookie>
  client_secret: null, //<could_use_cookie>
  redirect_url: '/local/callback',
  success_redirect: '/local/lmao',
  failure_redirect: '/login',
  //cb takes (3 argumensts, [req, res, callback])
  cb: (req, res, callback)=>{
    // if(cookie) return ValidateCookie(cookie, (result:String)=>{callback(null, {username: result.username)})

    // validate username and password using your own database
    if(req.body.username == "admin" && req.body.password == "admin"){
      return callback(null, {username: req.body.username, password: req.body.password})
    }
    
  }
}

// Apply the zerouth to your Express app
app.use(
  zerouth("/auth/google", GoogleConfig)
);

app.use(
  zerouth("/auth/local", LocalStrategy)
);

// Handle successful authentication
app.get('/success', (req, res) => {
  return res.send(req.user);
});

// Start your Express server
app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Supported Platforms

Zerouth currently supports OAuth authentication for the following platforms:

  • Google
  • Discord
  • Reddit
  • Facebook
  • GitHub
  • LinkedIn
  • Spotify
  • ...and more

Configuration

Zerouth uses a configuration object to set up OAuth parameters. Make sure to provide the necessary client information and callback URLs as required by the OAuth providers.

Configuration Options

  • client: The name of the OAuth client (e.g., 'google', 'discord').
  • client_id: The client ID provided by the OAuth provider.
  • client_secret: The client secret provided by the OAuth provider.
  • redirect_url: The callback URL to redirect to after successful authentication.
  • success_redirect: The URL to redirect to after successful authentication.
  • failure_redirect: The URL to redirect to after failed authentication.
  • scope: (Optional) An array of scope strings for requesting specific permissions.
  • ...other configuration options specific to each OAuth provider.

Error Handling

Zerouth provides detailed error handling for various scenarios, including invalid configuration, unsupported clients, and duplicate paths or URLs. Make sure to handle errors appropriately based on your application's requirements.

Contribution

Feel free to fork dev branch :)

License

This project is licensed under the MIT License.