Skip to main content

Facebook authentication

Not yet available (2.4.x)

The Facebook provider is not enabled yet. Only Google is live right now — calling auth.signIn() with this provider throws AuthErrorCode.PROVIDER_NOT_ENABLED. The page below documents its intended shape for when it is re-enabled. See the provider overview and the Google provider.

The Facebook provider signs users in with the Facebook JS SDK (window.FB). The provider loads the SDK from connect.facebook.net and initializes it with your app ID and Graph API version.

When you need a backend

No backend is required for the basic login flow — the Facebook JS SDK returns an access token in the browser. A backend is only needed if you want to verify or extend the access token server-side (recommended before trusting it for authorization).

Configuration

import { auth } from 'capacitor-auth-manager';

auth.configure({
providers: {
facebook: {
appId: 'YOUR_FACEBOOK_APP_ID',
scopes: ['email', 'public_profile'],
fields: ['id', 'name', 'email', 'picture'],
},
},
});

Options

From the FacebookAuthOptions interface in src/definitions.ts:

OptionTypeRequiredPurpose
appIdstringYesFacebook application ID.
appSecretstringNoServer-side use only — do not ship in the browser bundle.
scopesstring[]NoPermissions to request (e.g. email, public_profile).
fieldsstring[]NoGraph API profile fields to fetch.
versionstringNoGraph API version. Defaults to v18.0.
loginBehavior'native_with_fallback' | 'native_only' | 'web_only' | 'web_view_only'NoLogin behavior preference.
defaultAudience'friends' | 'only_me' | 'everyone'NoDefault audience for posted content permissions.
limitedLoginbooleanNoUse Facebook Limited Login (privacy-restricted, OIDC-style token).
authTypestringNoAuth type parameter (e.g. re-request declined permissions).
messengerPageIdstringNoMessenger page association.
resetMessengerStatebooleanNoReset Messenger extension state.

Sign in

await auth.signIn('facebook');

Notes & caveats

  • The provider loads and initializes the Facebook JS SDK itself; the login depends on Facebook's SDK being reachable.
  • limitedLogin follows Facebook's Limited Login mode, which restricts the data returned.
  • The library does not verify token signatures in the browser — re-validate the access/ID token server-side before trusting it.