Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/subhendukundu/worker-auth-providers
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.
https://github.com/subhendukundu/worker-auth-providers
auth authentication aws-sns-login cloudflare cloudflare-workers discord-login facebook-login github-login github-login-with-worker google-login oauth2 spotify worker-discord-login worker-login worker-twilio-otp
Last synced: 2 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/subhendukundu/worker-auth-providers
- Owner: subhendukundu
- Created: 2021-07-29T03:30:29.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-11T08:27:56.000Z (4 months ago)
- Last Synced: 2024-10-30T18:02:17.446Z (3 months ago)
- Topics: auth, authentication, aws-sns-login, cloudflare, cloudflare-workers, discord-login, facebook-login, github-login, github-login-with-worker, google-login, oauth2, spotify, worker-discord-login, worker-login, worker-twilio-otp
- Language: TypeScript
- Homepage: https://authc1.com
- Size: 824 KB
- Stars: 292
- Watchers: 10
- Forks: 31
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-list - worker-auth-providers - 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. | subhendukundu | 12 | (JavaScript)
- jimsghstars - subhendukundu/worker-auth-providers - 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 (TypeScript)
README
worker-auth-providers
An open-source auth providers for Cloudflare workers
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](https://worker-auth-providers.coolbio.workers.dev)## π§ Features
- Open Source
- Fast & Lightweight
- Easy## π οΈ Installation
**Step 1**: Install the dependencies
```bash
npm install worker-auth-providers
```
**Step 2**: Import the dependencies
```javascript
import {
github, google,
twilio, facebook, discord,
spotify
} from "worker-auth-providers";
```
**Step 3**: Redirect users
```javascript
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
```javascript
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
- [Cloudflare](https://www.cloudflare.com/)## π° Contributing
Contributions are always welcome!
See [contributing.md](contributing.md) for ways to get started.
Please adhere to this project's [code of conduct](code-of-conduct.md).## Roadmap
- [ ] Docs.
- [x] Apple.
- [ ] Azure (Microsoft)
- [x] Google.
- [x] Github
- [x] OTP Twilio
- [x] Mailgun Email
- [x] Sendgrid Email
- [x] Facebook
- [x] Discord
- [ ] Amazon
- [x] Spotify
- [ ] Auth0##FAQs
#### How to persist login?
Use cookie. Setting a cookie to indicate that theyβre authorized for future requests
```javascript
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
```javascript
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
- [@subhendukundu](https://www.github.com/subhendukundu)## πΌ License
[MIT](https://github.com/subhendukundu/worker-auth-providers/blob/main/LICENSE)