![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.
express-authenticators
Advanced tools
Third party authenticators in nodejs. Support various providers. Almost zero dependencies.
Modern OAuth/OAuth2 authenticator.
r3986
and jws
(jws
is required for Google and Apple token check).yarn
: yarn add express-authenticators
.npm
: npm install --save express-authenticators
.fetch
polyfilled.randomUUID()
).export {
getGoogleConsentUrl, getGoogleAccessToken, fetchGoogleProfile, refreshGoogleAccessToken, verifyGoogleIdToken,
getFacebookConsentUrl, getFacebookAccessToken, fetchFacebookProfile,
getAppleConsentUrl, getAppleToken, generateAppleClientSecret, verifyAppleIdToken, revokeAppleToken,
getGithubConsentUrl, getGithubAccessToken, fetchGithubProfile,
getFoursquareConsentUrl, getFoursquareAccessToken, fetchFoursquareProfile,
getInstagramConsentUrl, getInstagramAccessToken, fetchInstagramProfile,
getLineConsentUrl, getLineAccessToken, fetchLineProfile, refreshLineAccessToken,
getLinkedInConsentUrl, getLinkedInAccessToken, fetchLinkedInProfile,
getTwitterConsentUrl, getTwitterAccessToken, fetchTwitterProfile,
getTumblrConsentUrl, getTumblrAccessToken, fetchTumblrProfile,
getZaloConsentUrl, getZaloAccessToken, fetchZaloProfile, refreshZaloAccessToken,
getPinterestConsentUrl, getPinterestAccessToken, fetchPinterestProfile,
getConsentUrl, getAccessToken,
getOauth1ConsentUrl, getOAuth1AccessToken, oauth1SignAndFetch,
}
const {
getGoogleConsentUrl, getGoogleAccessToken, fetchGoogleProfile, refreshGoogleAccessToken, verifyGoogleIdToken,
} = require('express-authenticators')
const express = require('express')
const session = require('express-session')
const app = express()
app.use(session())
app.get(
'/auth/google',
async (req, res, next) => {
req.session.someInfo = 'my info' // store the user credential
try {
const {url, state} = await getGoogleConsentUrl({
clientID: 'your client id',
redirectUri: 'https://your-host.com/auth/google/callback',
})
req.session.oauthGoogle = JSON.stringify(state)
res.redirect(302, url)
} catch (e) {
next(e)
}
}
)
app.get( // for AppleAuthenticator, must use POST method instead
'/auth/google/callback',
async (req, res, next) => {
try {
const {access_token} = await getGoogleAccessToken(
{
clientID: 'your client id',
clientSecret: 'your client secret',
redirectUri: 'https://your-host.com/auth/google/callback',
},
JSON.parse(req.session.oauthGoogle),
Object.fromEntries(new URLSearchParams(new URL(`https://example.com${req.url}`).search)) // for AppleAuthenticator, use req.body instead
)
const profile = await fetchGoogleProfile(access_token)
console.log('got profile', profile)
res.send(JSON.stringify(profile))
} catch (e) {
next(e)
}
}
)
All fetch profile APIs return the same interface:
interface OAuthProfile {
id?: string
email?: string
emailVerified?: boolean
first?: string
last?: string
avatar?: string
raw: any
}
Where raw
is the raw JSON-parsed data returned from the provider.
Other fields are calculated carefully based on the data returned from each provider.
FAQs
Third party authenticators in nodejs. Support various providers. Almost zero dependencies.
We found that express-authenticators demonstrated a healthy version release cadence and project activity because the last version was released less than 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.