Skip to main content

Facebook Provider

Package: @nauth-toolkit/social-facebook Type: Social Auth Provider

npm install @nauth-toolkit/social-facebook

Exports

ExportTypeEntry
FacebookSocialAuthServiceClassDefault
FacebookOAuthClientClassDefault
TokenVerifierServiceClassDefault
VerifiedFacebookTokenProfileInterfaceDefault
FacebookSocialAuthModuleNestJS Module/nestjs

Configuration

Configure Facebook under config.social.facebook (in @nauth-toolkit/core config).

KeyTypeRequiredDescription
enabledbooleanNoEnable Facebook OAuth
clientIdstringYes (if enabled)Facebook App ID
clientSecretstringYes (if enabled)Facebook App Secret
callbackUrlstringYes (if enabled)Backend callback URL (/auth/social/facebook/callback)
scopesstring[]NoDefault: ['email', 'public_profile']
autoLinkbooleanNoAuto-link to existing users by verified email
allowSignupbooleanNoAllow creating new users on first login
oauthParamsRecord<string, string>NoAdditional OAuth parameters to include in authorization URL. These act as defaults and can be overridden on a per-request basis.

OAuth Parameters

The oauthParams option allows you to customize the Facebook OAuth authorization flow. These parameters are appended to Facebook's authorization URL and can be overridden on a per-request basis from the frontend.

Common Parameters:

  • auth_type: Authentication type
    • 'reauthenticate' - Force user to re-authenticate
    • 'rerequest' - Re-request declined permissions
  • display: UI display mode
    • 'page' - Full-page redirect (default)
    • 'popup' - Popup window
    • 'touch' - Mobile-optimized UI
  • auth_nonce: For replay attack prevention

Example:

social: {
facebook: {
enabled: true,
clientId: process.env.FACEBOOK_APP_ID,
clientSecret: process.env.FACEBOOK_APP_SECRET,
callbackUrl: 'https://api.myapp.com/auth/social/facebook/callback',
scopes: ['email', 'public_profile'],
oauthParams: {
auth_type: 'rerequest', // Always rerequest declined permissions
display: 'popup', // Use popup window
},
},
}

See Social Login Guide for usage examples.

Usage

import { FacebookSocialAuthModule } from '@nauth-toolkit/social-facebook/nestjs';

@Module({
imports: [AuthModule.forRoot(config), FacebookSocialAuthModule],
})
export class AppModule {}

Profile Data

FieldTypeDescription
idstringFacebook user ID
emailstring?Email (if permission granted)
namestringDisplay name
picturestringProfile picture URL