Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@umanghome/login-with-twitter-cf-workers
Advanced tools
Readme
Forked from feross/login-with-twitter and modified to be executable on CloudFlare Workers.
This module is designed to be the lightest possible wrapper on Twitter OAuth.
All this in < 100 lines of code.
npm install @umanghome/login-with-twitter-cf-workers
Set up two routes on your web sever. We'll call them /twitter
and
/twitter/callback
, but they can be named anything.
Initialize this module with the consumer key and secret for your Twitter App you created with an Twitter Developer account.
const LoginWithTwitter = require('@umanghome/login-with-twitter-cf-workers');
const tw = new LoginWithTwitter({
consumerKey: '<your consumer key>',
consumerSecret: '<your consumer secret>',
callbackUrl: 'https://example.com/twitter/callback',
});
Call login
from your /twitter
route, saving the OAuth tokenSecret
to use later. In this example, we use the request session (using, for example, express-session).
app.get('/twitter', (req, res) => {
tw.login()
.then(({ tokenSecret, url }) => {
// Save the OAuth token secret for use in your /twitter/callback route
req.session.tokenSecret = tokenSecret;
// Redirect to the /twitter/callback route, with the OAuth responses as query params
res.redirect(url);
})
.catch((err) => {
// Handle the error your way
});
});
Then, call callback
from your /twitter/callback
route. The request will include oauth_token
and oauth_verifier
in the URL, accessible with req.query
. Pass those into callback
, along with the OAuth tokenSecret
you saved in the login
callback above, and a callback that handles a user
object that this module will return.
app.get('/twitter/callback', (req, res) => {
tw.callback(
{
oauth_token: req.query.oauth_token,
oauth_verifier: req.query.oauth_verifier,
},
req.session.tokenSecret
)
.then((user) => {
// Delete the tokenSecret securely
delete req.session.tokenSecret;
// The user object contains 4 key/value pairs, which
// you should store and use as you need, e.g. with your
// own calls to Twitter's API, or a Twitter API module
// like `twitter` or `twit`.
// user = {
// userId,
// userName,
// userToken,
// userTokenSecret
// }
req.session.user = user;
// Redirect to whatever route that can handle your new Twitter login user details!
res.redirect('/');
})
.catch((err) => {
// Handle the error your way
});
});
If you want to implement logout, simply delete the user
object stored in the session.
For more information, check out the implementation in index.js.
MIT. Copyright (c) Umang Galaiya.
FAQs
Login with Twitter. OAuth without the nonsense - for CloudFlare Workers
The npm package @umanghome/login-with-twitter-cf-workers receives a total of 0 weekly downloads. As such, @umanghome/login-with-twitter-cf-workers popularity was classified as not popular.
We found that @umanghome/login-with-twitter-cf-workers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.