@mayurajs/auth-facebook
v1.2.0
Published
Facebook Login access tokens (checked with Facebook) and Limited Login tokens as Mayura server identities, and a preset for better-auth's Facebook sign-in.
Readme
@mayurajs/auth-facebook
Facebook sign-in for Mayura, on any runtime, with no dependency:
facebookAuthenticator: Facebook Login user access tokens sent straight to Mayura's server, checked with Facebook, and iOS Limited Login tokens, checked with Facebook's keys;facebookSignIn: Facebook as a better-auth social login (withmayura/auth/better-auth), reading no more of the profile than signing in needs.
npm install mayura @mayurajs/auth-facebookimport { principalId } from 'mayura/auth';
import { facebookAuthenticator, facebookSignIn } from '@mayurajs/auth-facebook';
const authenticate = facebookAuthenticator({
appId: process.env.FACEBOOK_APP_ID!,
appSecret: process.env.FACEBOOK_APP_SECRET!,
requiredScopes: ['email'],
identity: session => ({
principalId: principalId('facebook', session.userId),
projectId: 'acme',
agentIds: ['support'],
capabilities: ['runs:submit', 'runs:read'],
}),
});
// Or sign people in with better-auth:
// betterAuth({ socialProviders: { facebook: facebookSignIn({ clientId, clientSecret }) }, ... })- Access tokens are opaque, so each one is checked with Facebook's
debug_token(Graph APIv26.0unlessgraphVersion), using your app's token (appId|appSecret, which never leaves your server and never appears in an error). A token passes only when Facebook says it is valid, a user's, for your app, unexpired, and holds everyrequiredScopespermission. That is a call to Facebook per request:cacheTtlMs(up to 5 minutes, 0 by default) keeps Facebook's answer for that long, so a token the user revokes then works for that long more. A call takes at mosttimeoutMs(5 s); when Facebook cannot answer, the server answers that authentication is unavailable. - Limited Login (with
limitedLogin: true): iOS Limited Login tokens are OIDC JWTs, checked with no call per request: RS256 with Facebook's keys, issued byhttps://www.facebook.com, for your app. Check the token'snoncein your app, which made it. - What you get.
identityreceiveskind(access_tokenorlimited_login),userId(app-scoped: the same person has a different id in each of your apps),scopes,emailandname(Limited Login), andexpiresAtMs. Nothing is granted unlessidentitygrants it. facebookSignIngives better-auth'ssocialProviders.facebookreading onlyid,nameandemail(pictureif asked), with no permissions beyond better-auth'semailandpublic_profileunless you addscopes.- Options:
facebookAuthenticator({ appId, appSecret, identity, requiredScopes, limitedLogin, cacheTtlMs, timeoutMs, graphVersion, clockSkewMs, maxIdentityMs, fetch }),facebookSignIn({ clientId, clientSecret, picture, scopes }).
See Authentication and API keys. Apache-2.0.
