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

auth-simple11

v1.5.0

Published

**Created by Rishi Yadav** *GitHub: [rishiyadav11](https://github.com/rishiyadav11)* *Full Stack Developer*

Downloads

13

Readme

auth-simple11

Created by Rishi Yadav
GitHub: rishiyadav11
Full Stack Developer

auth-simple11 is a lightweight package that simplifies the implementation of OAuth strategies in your application. With a simple function call, you can easily integrate Google, GitHub, Facebook, and LinkedIn authentication.

Installation

To install the package, run the following command:

npm install auth-simple11

Environment Variables

Before using the package, you need to set up the following environment variables in your .env file:

GOOGLE_CLIENT_ID=<your_google_client_id>
GOOGLE_CLIENT_SECRET=<your_google_client_secret>
GITHUB_CLIENT_ID=<your_github_client_id>
GITHUB_CLIENT_SECRET=<your_github_client_secret>
FACEBOOK_APP_ID=<your_facebook_app_id>
FACEBOOK_APP_SECRET=<your_facebook_app_secret>
LINKEDIN_CLIENT_ID=<your_linkedin_client_id>
LINKEDIN_CLIENT_SECRET=<your_linkedin_client_secret>
CALLBACK_URL=<your_callback_url>  # The URL to which the user will be redirected after authentication

Make sure to replace the placeholders with your actual credentials.

Using a Single Strategy

To implement a single OAuth strategy, you can follow the steps below. This example will demonstrate how to use Google authentication.

Step 1: Set Up Google Authentication

In your app.js, you can set up Google authentication like this:

import express from 'express';
import dotenv from 'dotenv';
import passport from 'passport';
import { setupAuth } from 'auth-simple11';

dotenv.config();
const app = express();

// Initialize passport
app.use(passport.initialize());

// Set up Google OAuth strategy
setupAuth('google', {
    clientID: process.env.GOOGLE_CLIENT_ID,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    callbackURL: process.env.CALLBACK_URL
}, (profile) => {
    // Here you can handle the user data returned from Google
    console.log('Google profile:', profile);
    // You can save the user data to your database here
});

// Define the route to initiate authentication
app.get('/auth/google', passport.authenticate('google', { scope: ['profile', 'email'] }));

// Handle the callback after Google has authenticated the user
app.get('/auth/callback', (req, res) => {
    // You can handle the user data after authentication here
    res.redirect('/');
});

// Serve a simple homepage
app.get('/', (req, res) => {
    res.send('<h1>Welcome to the OAuth App</h1><p><a href="/auth/google">Login with Google</a></p>');
});

// Start the server
const PORT = 3000;
app.listen(PORT, () => {
    console.log(`Server is running on http://localhost:${PORT}`);
});

Step 2: Run the Application

Start your application with the following command:

node app.js

Step 3: Test the Google Authentication

Open your browser and navigate to http://localhost:3000. Click the "Login with Google" link to initiate the Google authentication flow. After you log in, you will be redirected back to your application.

Full App Usage Example

Here is a complete example of how to use the auth-simple11 package in an Express application:

// app.js
import express from 'express';
import dotenv from 'dotenv';
import passport from 'passport';
import { setupAuth } from 'auth-simple11';

dotenv.config();
const app = express();

// Initialize passport
app.use(passport.initialize());

// Set up OAuth strategies
setupAuth('google', {
    clientID: process.env.GOOGLE_CLIENT_ID,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    callbackURL: process.env.CALLBACK_URL
}, (profile) => {
    console.log('Google profile:', profile);
});

setupAuth('github', {
    clientID: process.env.GITHUB_CLIENT_ID,
    clientSecret: process.env.GITHUB_CLIENT_SECRET,
    callbackURL: process.env.CALLBACK_URL
}, (profile) => {
    console.log('GitHub profile:', profile);
});

setupAuth('facebook', {
    clientID: process.env.FACEBOOK_APP_ID,
    clientSecret: process.env.FACEBOOK_APP_SECRET,
    callbackURL: process.env.CALLBACK_URL
}, (profile) => {
    console.log('Facebook profile:', profile);
});

setupAuth('linkedin', {
    clientID: process.env.LINKEDIN_CLIENT_ID,
    clientSecret: process.env.LINKEDIN_CLIENT_SECRET,
    callbackURL: process.env.CALLBACK_URL
}, (profile) => {
    console.log('LinkedIn profile:', profile);
});

// Define routes for authentication
app.get('/auth/google', passport.authenticate('google', { scope: ['profile', 'email'] }));
app.get('/auth/github', passport.authenticate('github'));
app.get('/auth/facebook', passport.authenticate('facebook'));
app.get('/auth/linkedin', passport.authenticate('linkedin'));

// Handle callbacks
app.get('/auth/callback', (req, res) => {
    res.redirect('/');
});

// Serve a simple homepage
app.get('/', (req, res) => {
    res.send('<h1>Welcome to the OAuth App</h1><p><a href="/auth/google">Login with Google</a></p><p><a href="/auth/github">Login with GitHub</a></p><p><a href="/auth/facebook">Login with Facebook</a></p><p><a href="/auth/linkedin">Login with LinkedIn</a></p>');
});

// Start the server
const PORT = 3000;
app.listen(PORT, () => {
    console.log(`Server is running on http://localhost:${PORT}`);
});

License

This project is licensed under the MIT License - see the LICENSE file for details.


This README file contains all the necessary information in a single document, including installation instructions, environment variable setup, usage examples, and a complete application example using the `auth-simple11` package. You can copy and upload this file as needed!