@caracal7/worker-auth-providers
v0.0.13-beta.4
Published
<p align="center"><img src="/logo.png" alt="worker-auth-providers" width="120px"></p>
Downloads
1
Readme
🚀 Demo
🧐 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.
- [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
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]