npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@whiteguru/capacitor-plugin-facebook-login

v5.0.1

Published

Capacitor plugin to login with Facebook

Downloads

4

Readme

@whiteguru/capacitor-plugin-facebook-login

Capacitor plugin to login with Facebook

Note This is a fork of @capacitor-community/facebook-login with Limited Tracking Login method.

Install

npm install @whiteguru/capacitor-plugin-facebook-login
npx cap sync

or for Capacitor 4.x

npm install @whiteguru/capacitor-plugin-facebook-login@^4.0.1
npx cap sync

Android configuration

In file android/app/src/main/java/**/**/MainActivity.java, add the plugin to the initialization list:

import android.os.Bundle; // required for onCreate parameter

public class MainActivity extends BridgeActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    registerPlugin(
      com.whiteguru.capacitor.plugin.facebooklogin.FacebookLoginPlugin.class
    );
  }
}

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

If you have trouble.

Please restart Android Studio, and do clean build.

iOS configuration

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 '@whiteguru/capacitor-plugin-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 '@whiteguru/capacitor-plugin-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}`);
}

Login with Limited Tracking (IOS only)

A successful login in Limited Login returns an AuthenticationToken instance instead of a AccessToken. This is a JSON web token (JWT) containing a signature, and other pieces of information. Your app should validate the token to make sure it is authentic.

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

import {
  FacebookLogin,
  FacebookLimitedLoginResponse,
} from '@whiteguru/capacitor-plugin-facebook-login';

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

if (result.authenticationToken) {
  // Login successful.
  console.log(
    `Facebook authentication token is ${result.authenticationToken.token}`,
  );
}

Logout

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

await FacebookLogin.logout();

CurrentAccessToken

import {
  FacebookLogin,
  FacebookLoginResponse,
} from '@whiteguru/capacitor-plugin-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 '@whiteguru/capacitor-plugin-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>

| Param | Type | | ------------- | ------------------------------------------------------------------------------------------------------------- | | options | Partial<FacebookConfiguration> |


login(...)

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

| Param | Type | | ------------- | --------------------------------------- | | options | { permissions: string[]; } |

Returns: Promise<FacebookLoginResponse>


loginWithLimitedTracking(...)

loginWithLimitedTracking(options: { permissions: string[]; }) => Promise<FacebookLimitedLoginResponse>

| Param | Type | | ------------- | --------------------------------------- | | options | { permissions: string[]; } |

Returns: Promise<FacebookLimitedLoginResponse>


logout()

logout() => Promise<void>

reauthorize()

reauthorize() => Promise<FacebookLoginResponse>

Returns: Promise<FacebookLoginResponse>


getCurrentAccessToken()

getCurrentAccessToken() => Promise<FacebookCurrentAccessTokenResponse>

Returns: Promise<FacebookCurrentAccessTokenResponse>


getProfile(...)

getProfile<T extends object>(options: { fields: readonly string[]; }) => Promise<T>

| Param | Type | | ------------- | ------------------------------------------- | | options | { fields: readonly string[]; } |

Returns: Promise<T>


Interfaces

FacebookConfiguration

| Prop | Type | | ---------------------- | -------------------- | | appId | string | | autoLogAppEvents | boolean | | xfbml | boolean | | version | string | | locale | string |

FacebookLoginResponse

| Prop | Type | | -------------------------------- | ----------------------------------------------------------- | | accessToken | AccessToken | null | | recentlyGrantedPermissions | string[] | | recentlyDeniedPermissions | string[] |

AccessToken

| Prop | Type | | ------------------------- | --------------------- | | applicationId | string | | declinedPermissions | string[] | | expires | string | | isExpired | boolean | | lastRefresh | string | | permissions | string[] | | token | string | | userId | string |

FacebookLimitedLoginResponse

| Prop | Type | | ------------------------- | --------------------------------------------------------------------------- | | authenticationToken | AuthenticationToken | null |

AuthenticationToken

| Prop | Type | | ------------ | ------------------- | | token | string | | userId | string |

FacebookCurrentAccessTokenResponse

| Prop | Type | | ----------------- | ----------------------------------------------------------- | | accessToken | AccessToken | null |

Type Aliases

Partial

Make all properties in T optional

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