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.
async-twitter-login
Advanced tools
Readme
All this in < 4kb, what else do you need? ✨
$ npm i async-twitter-login
We will configure two routes in our web server, auth/login
and auth/callback
can have any name :P
We import and instantiate, you will need your consumer key and your comsumer secret... both are obtained when creating an application from the Twitter Developer Portal.
Finally you will need your callback url, as we said before it would be https://example.com/auth/callback
.
// CommonJS
const { AsyncTwitterLogin } = require('async-twitter-login')
// EcmaScript
import { AsyncTwitterLogin } from 'async-twitter-login'
const twitterLogin = new AsyncTwitterLogin({
consumerKey: 'your-consumer-key',
consumerSecret: 'your-consumer-secret',
callbackUrl: 'https://example.com/auth/callback'
})
From our auth/login
path we call the request()
method and save in a safe place tokenSecret
to use it later.
app.get('/auth/login', async (req, res) => {
try {
const { token, tokenSecret, redirectUrl } = await twitterLogin.request()
// Save the token secret in a safe place
req.session.tokenSecret = tokenSecret
// Redirect to Twitter to authorize the application
res.redirect(redirectUrl)
} catch (err) {
// Handle errors
}
})
If the user completes the authorization from twitter, he will be redirected to his auth/callback
path together with oauth_token
and oauth_verifier
as query parameters in the URL, they are accessed with req.query
.
We call the callback()
method from our auth/callback
path and pass the parameters to it along with the tokenSecret
that we saved in the previous step.
This method will return a user object. 🧔
app.get('/auth/callback', async (req, res) => {
try {
const { oauth_token: token, oauth_verifier: verifier } = req.query
const tokenSecret = req.session.tokenSecret
const user = await twitterLogin.callback(token, tokenSecret, verifier)
// Delete the token secret from the session
delete req.session.tokenSecret
// The user object is a readable object with the user's data.
// user = {
// id,
// userName,
// token,
// tokenSecret
// }
req.session.user = user
// Redirect to the home page
res.redirect('/')
} catch (err) {
// Handle errors
}
})
MIT License © 2021- Brian Fernandez.
FAQs
Simple Twitter login, without much of the bullshit. and promises... who doesn't like them?
The npm package async-twitter-login receives a total of 0 weekly downloads. As such, async-twitter-login popularity was classified as not popular.
We found that async-twitter-login 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.