Giter VIP home page Giter VIP logo

queletr / worker-auth-providers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from subhendukundu/worker-auth-providers

0.0 0.0 0.0 690 KB

worker-auth-providers is an open-source providers to make authentication easy with workers. Very lightweight script which doesn't need a lot of dependencies. Plug it with any framework or template of workers.

Home Page: https://worker-auth-providers.coolbio.workers.dev

JavaScript 46.29% TypeScript 48.57% HTML 1.94% CSS 3.20%

worker-auth-providers's Introduction

worker-auth-providers

worker-auth-providers

An open-source auth providers for Cloudflare workers

Repo Size Issues Pull Requests Last Commit

worker-auth-providers is an open-source providers to make authentication easy with workers. Very lightweight script which doesn't need a lot of dependencies. Plug it with any framework or template of workers.

πŸš€ Demo

Try now

🧐 Features

  • Open Source
  • Fast & Lightweight
  • Easy

πŸ› οΈ Installation

Step 1: Install the dependencies

npm install worker-auth-providers

Step 2: Import the dependencies

import {
  github, google, awsSNS,
  twilio, facebook, discord,
  spotify
} from "worker-auth-providers";

Step 3: Redirect users

const githubLoginUrl = await github.redirect({
    options: {
        clientId,
    },
});
return {
    status: 302,
    headers: {
        location: githubLoginUrl,
    },
};

// or send otp

const res = await awsSNS.send({
  options: {
    phone,
    region: 'ap-south-1',
    kvProvider: WORKER_AUTH_PROVIDERS_STORE,
  },
})

Step 4: Get user

const { user: providerUser, tokens } = await github.users({
    options: { clientSecret, clientId },
    request,
});
console.log("[providerUser]", providerUser);

// or verify otp
const res = await awsSNS.verify({
  options: {
    phone,
    otp,
    kvProvider: WORKER_AUTH_PROVIDERS_STORE,
    secret: 'eyJhbGciOiJIUzI1NiJ9.ew0KICAic3ViIjogIjE2Mjc4MTE1MDEiLA0KICAibmFtZSI6ICJoYWFsLmluIiwNCiAgImlhdCI6ICIwMTA4MjAyMCINCn0.aNr18szvBz3Db3HAsJ-2KHYbnnHwHfK65CiZ_AWwpc0',
  },
})

πŸ“ƒ Documentation

Coming soon

πŸ‘©β€πŸ’» Tech

🍰 Contributing

Contributions are always welcome! See contributing.md for ways to get started. Please adhere to this project's code of conduct.

Roadmap

  • Docs.
  • Google.
  • Github
  • OTP AWS SNS
  • OTP Twilio
  • Mailgun Email
  • Sendgrid Email
  • Facebook
  • Discord
  • Instagram
  • Amazon
  • Twitter
  • Spotify
  • Auth0

##FAQs

How to persist login?

Use cookie. Setting a cookie to indicate that they’re authorized for future requests

const cookieKey = "worker-auth-providers"
const persistAuth = async exchange => {
    const date = new Date()  date.setDate(date.getDate() + 1)
    const headers = { 
      Location: "/",
      "Set-cookie": `${cookieKey}=${id}; Secure; HttpOnly; SameSite=Lax; Expires=${date.toUTCString()}`,
    }
    return { headers, status: 302 }
}

How to logout?

Easy, delete the cookie

export const logout = event => {
  const cookieHeader = event.request.headers.get('Cookie')
  if (cookieHeader && cookieHeader.includes(cookieKey)) {
    return {
      headers: {
        'Set-cookie': `${cookieKey}=""; HttpOnly; Secure; SameSite=Lax;`,
      },
    }
  }
  return {}
}

Feedback

If you have any feedback, please reach out to me at [email protected]

✍️ Authors

πŸ’Ό License

MIT

worker-auth-providers's People

Contributors

cometkim avatar subhendukundu avatar walshydev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.