Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@capacitor-community/facebook-login

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capacitor-community/facebook-login

A native plugin for Facebook Login

  • 6.1.0-0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.6K
increased by2.62%
Maintainers
0
Weekly downloads
 
Created
Source


Facebook Login

@capacitor-community/facebook-login

Capacitor community plugin for native Facebook Login.


Maintainers

MaintainerGitHubSocialSponsoring Company
Masahiko Sakakibarardlabo@rdlaboRELATION DESIGN LABO, GENERAL INC. ASSOCIATION

Contributors ✨

Made with contributors-img.

Demo

Demo code is here.

Installation

% npm i --save @capacitor-community/facebook-login
% npx cap update

Versions

Users of Capacitor v5 should use version v5 of the Plugin.

% npm install @capacitor-community/facebook-login@5

Configuration

Android configuration

In file android/app/src/main/AndroidManifest.xml, add the following XML elements under <manifest><application> :

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>

In file android/app/src/main/res/values/strings.xml add the following lines :

<string name="facebook_app_id">[APP_ID]</string>
<string name="facebook_client_token">[CLIENT_TOKEN]</string>

Don't forget to replace [APP_ID] and [CLIENT_TOKEN] by your Facebook application Id.

More information can be found here: https://developers.facebook.com/docs/android/getting-started

iOS configuration

In file ios/App/Podfile add the following:

  target 'App' do
    capacitor_pods
    # Add your Pods here
+   pod 'FBSDKCoreKit'
  end

In file ios/App/App/AppDelegate.swift add or replace the following:

import UIKit
import Capacitor
import FBSDKCoreKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        FBSDKCoreKit.ApplicationDelegate.shared.application(
            application,
            didFinishLaunchingWithOptions: launchOptions
        )

        return true
    }

    ...

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
        // Called when the app was launched with a url. Feel free to add additional processing here,
        // but if you want the App API to support tracking app url opens, make sure to keep this call
        if (FBSDKCoreKit.ApplicationDelegate.shared.application(
            app,
            open: url,
            sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
            annotation: options[UIApplication.OpenURLOptionsKey.annotation]
        )) {
            return true;
        } else {
            return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
        }
    }
}

Add the following in the ios/App/App/info.plist file inside of the outermost <dict>:


<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb[APP_ID]</string>
        </array>
    </dict>
</array>
<key>FacebookAppID</key>
<string>[APP_ID]</string>
<key>FacebookClientToken</key>
<string>[CLIENT_TOKEN]</string>
<key>FacebookDisplayName</key>
<string>[APP_NAME]</string>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fbapi20130214</string>
    <string>fbapi20130410</string>
    <string>fbapi20130702</string>
    <string>fbapi20131010</string>
    <string>fbapi20131219</string>
    <string>fbapi20140410</string>
    <string>fbapi20140116</string>
    <string>fbapi20150313</string>
    <string>fbapi20150629</string>
    <string>fbapi20160328</string>
    <string>fbauth</string>
    <string>fb-messenger-share-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>

More information can be found here: https://developers.facebook.com/docs/facebook-login/ios

Web configuration

import { FacebookLogin } from '@capacitor-community/facebook-login';

// use hook after platform dom ready
await FacebookLogin.initialize({ appId: '105890006170720' });

More information can be found here: https://developers.facebook.com/docs/facebook-login/web And you must confirm return type at https://github.com/rdlabo/capacitor-facebook-login/blob/master/src/web.ts#L55-L57 not same type for default web facebook login!

Example

Login

import {
  FacebookLogin,
  FacebookLoginResponse,
} from '@capacitor-community/facebook-login';

const FACEBOOK_PERMISSIONS = [
  'email',
  'user_birthday',
  'user_photos',
  'user_gender',
];
const result = await (<FacebookLoginResponse>(
  FacebookLogin.login({ permissions: FACEBOOK_PERMISSIONS })
));

if (result.accessToken) {
  // Login successful.
  console.log(`Facebook access token is ${result.accessToken.token}`);
}

Logout

import { FacebookLogin } from '@capacitor-community/facebook-login';

await FacebookLogin.logout();

CurrentAccessToken

import {
  FacebookLogin,
  FacebookLoginResponse,
} from '@capacitor-community/facebook-login';

const result = await (<FacebookLoginResponse>(
  FacebookLogin.getCurrentAccessToken()
));

if (result.accessToken) {
  console.log(`Facebook access token is ${result.accessToken.token}`);
}

getProfile

import {
  FacebookLogin,
  FacebookLoginResponse,
} from '@capacitor-community/facebook-login';

const result = await FacebookLogin.getProfile<{
  email: string;
}>({ fields: ['email'] });

console.log(`Facebook user's email is ${result.email}`);

API

initialize(...)

initialize(options: Partial<FacebookConfiguration>) => Promise<void>
ParamType
optionsPartial<FacebookConfiguration>

login(...)

login(options: { permissions: string[]; }) => Promise<FacebookLoginResponse>
ParamType
options{ permissions: string[]; }

Returns: Promise<FacebookLoginResponse>


limitedLogin(...)

limitedLogin(options: { permissions: string[]; tracking?: 'limited' | 'enabled'; nonce?: string; }) => Promise<LimitedFacebookLoginResponse>
ParamType
options{ permissions: string[]; tracking?: 'limited' | 'enabled'; nonce?: string; }

Returns: Promise<LimitedFacebookLoginResponse>


logout()

logout() => Promise<void>

reauthorize()

reauthorize() => Promise<FacebookLoginResponse>

Returns: Promise<FacebookLoginResponse>


getCurrentAccessToken()

getCurrentAccessToken() => Promise<FacebookCurrentAccessTokenResponse>

Returns: Promise<FacebookCurrentAccessTokenResponse>


getProfile(...)

getProfile<T extends Record<string, unknown>>(options: { fields: readonly string[]; }) => Promise<T>
ParamType
options{ fields: readonly string[]; }

Returns: Promise<T>


logEvent(...)

logEvent(options: { eventName: string; }) => Promise<void>
ParamType
options{ eventName: string; }

setAutoLogAppEventsEnabled(...)

setAutoLogAppEventsEnabled(options: { enabled: boolean; }) => Promise<void>
ParamType
options{ enabled: boolean; }

setAdvertiserTrackingEnabled(...)

setAdvertiserTrackingEnabled(options: { enabled: boolean; }) => Promise<void>
ParamType
options{ enabled: boolean; }

setAdvertiserIDCollectionEnabled(...)

setAdvertiserIDCollectionEnabled(options: { enabled: boolean; }) => Promise<void>
ParamType
options{ enabled: boolean; }

Interfaces

FacebookConfiguration
PropType
appIdstring
autoLogAppEventsboolean
xfbmlboolean
versionstring
localestring
FacebookLoginResponse
PropType
accessTokenAccessToken | null
recentlyGrantedPermissionsstring[]
recentlyDeniedPermissionsstring[]
AccessToken
PropType
applicationIdstring
declinedPermissionsstring[]
expiresstring
isExpiredboolean
lastRefreshstring
permissionsstring[]
tokenstring
userIdstring
LimitedFacebookLoginResponse
PropType
authenticationToken{ token: string; userId?: string; name?: string; email?: string; }
FacebookCurrentAccessTokenResponse
PropType
accessTokenAccessToken | null

Type Aliases

Partial

Make all properties in T optional

{ [P in keyof T]?: T[P]; }

Record

Construct a type with a set of properties K of type T

{ [P in K]: T; }

Keywords

FAQs

Package last updated on 11 Dec 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc