• Stars
    star
    266
  • Rank 154,103 (Top 4 %)
  • Language
    TypeScript
  • Created over 3 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

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,
  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 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

More Repositories

1

Electron-GoogleSheet

A electron application using google spreadsheet api v4. This could be used as desktop application where the user could update different data in a google spreadsheet. Could be used in grocery stores to track orders.
JavaScript
18
star
2

react-native-google-sheet

A <GoogleSheet /> component for react-native to access Google Sheets API which gives you full control over the content and appearence of your spreadsheet data.
JavaScript
16
star
3

daku

What if you had only a few secs to impress an investor? Does your brand/idea has what it needs? Validate now with Daku.
JavaScript
12
star
4

authc1

Authc1 is a cloud-based, next-gen IAM platform that uses Cloudflare technologies to provide secure and seamless authentication and authorization for modern applications.
TypeScript
7
star
5

epics-app

Make something epic.
Dart
7
star
6

gif-code-snippet

Make gif snippet of code
JavaScript
7
star
7

ntrace

Ntrace analytics is an open-source analytics service. It does not use Cookies to track your users. Setup in 2 mins with our lightweight script which keeps your site speed fast. Track all of your website traffic from any device.
JavaScript
7
star
8

cool-bio-flareact-styled

This demo shows off the next-gen Static Site Generation capabilities in Flareact. This can serve Billions of pages on the fly under 1s latency.
JavaScript
6
star
9

linkedin-auth-firebase-functions-node

LinkedIn login with firebase, firebase-functions and nodejs
JavaScript
5
star
10

vitedge-react-template

JavaScript
3
star
11

nswag

JavaScript
2
star
12

haal-landing

TypeScript
1
star
13

intro.cool.bio

TypeScript
1
star
14

electron-sso

CSS
1
star
15

offline-first

JavaScript
1
star
16

ContentManager

CSS
1
star
17

Chatbot

JavaScript
1
star
18

SSR-HandlebarsWithReact

JavaScript
1
star
19

splashit

splashit is a fun app to explore the unsplash apis
JavaScript
1
star
20

reacfy

JavaScript
1
star
21

hasura-nextjs-auth

TypeScript
1
star
22

aws-chime-content-share

JavaScript
1
star