![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
antisocial-auth
Advanced tools
Social authentication for websites that don't provide any.
This project will both describe:
An user wants to authenticate on your website with his example.com username.
They fill a form with the username they want to authenticate with.
You generates a nonce, and store it in some kind of session (like signed cookies) for this user, together with the username they want to authenticate.
The user is then told to paste this "verification code" (the nonce) somewhere on example.com where they can easily be identified, that may be in a private message to a "bot" user you own, in teir profile description, or whatever is possible on the website.
When the use is done, they confirm it to your website (optionally providing some data so you can easily find the key if it's not ovbious), which will search the expected location for the nonce.
If the nonce is found, and it was effectively posted by the user in question, the user is a authenticated, and you can be sure they own the example.com account they claimed.
Also, note you could add some time limit to complete the authentication, for exmaple by storing the current time in session when the authentication request is made (when the nonce is generated), and checking it before verifying the nonce.
Example with an Express web app.
// Default settings.
const auth = require('antisocial-auth')
// Extend settings.
const auth = require('antisocial-auth').extend({
nonceSize: 256, // Change nonce size (default is 128).
expirationTime: 1000 * 60 * 10, // Expire after 10 minutes (default is 2).
})
// example.com imaginary API/crawler.
const example = require('example')
const app = require('express')()
const then = require('express-then')
app.use(require('cookie-parser')('secret'))
app.set('views', __dirname + '/views')
app.set('view engine', 'whatever')
// Request user authentication.
app.get('/auth/:user', then(async (req, res) => {
const user = req.param.user
const nonce = await auth.generateNonce() // Generate nonce buffer.
const nonce64 = nonce.toString('base64') // Can't set a buffer as JSON cookie.
const beginTime = Date.now() // Store the time for later verification.
res.cookie('auth', { user, nonce64, beginTime }, { httpOnly: true, signed: true })
res.render('auth', { user, nonce: auth.beautify(nonce) })
// `auth.beautify` will return something like this:
//
// -----BEGIN AUTH-----
// 1RZqcR7W+Z5itOuGVyEmIquYWpdMW92u
// rq4zbiUb4VhZIymJg4pQC4uLRHqcCqKk
// /06zQIt7Hf/j5ssElL+ZChkVlV6qoZxt
// M9dhXjoeYDkpG9BWXOnb7EsNWQiWsoYY
// GM9ApEoVFX34DZ8eSVa9TWLOZ0yKK/xf
// aEHXsz8qJHk=
// -----END AUTH-----
//
// The user is supposed to paste it somewhere on his example.com
// account, like in a private message to a bot you own, or his profile
// description.
}))
// Verify authentication.
app.get('/auth/:user/confirm', then(async (req, res) => {
const { user, nonce64, beginTime } = req.signedCookies.auth
const nonce = new Buffer(nonce64, 'base64')
// Bad request.
if (user !== req.params.user) {
return res.status(400).end()
}
// Authentication timeout expired.
if (!auth.checkTime(beginTime)) {
return res.status(401).end()
}
// Get (for example) user profile description.
const { desc } = await example.getProfile(user)
// Search for authentication tags and parse wrapped content.
const buffer = auth.uglify(desc)
// Failed authentication.
if (!nonce.equals(buffer)) {
return res.status(401).end()
}
// The user is authenticated!
res.cookie('user', user, { httpOnly: true, signed: true })
res.clearCookie('auth')
res.redirect('/')
}))
// Regular page.
app.get('/', (req, res) => {
if (req.signedCookies.user) {
// The user is authenticated.
}
// ...
})
FAQs
Social authentication for websites that don't provide any.
The npm package antisocial-auth receives a total of 0 weekly downloads. As such, antisocial-auth popularity was classified as not popular.
We found that antisocial-auth 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.