Zum Inhalt springen

Facebook-Anmeldungsmigration zu @capgo/social-login

GitHub

Diese Anleitung bietet umfassende Anweisungen für die Migration von @capacitor-community/facebook-login __CAPGO_KEEP_0__ @capgo/capacitor-social-login. The new plugin modernizes Facebook authentication with a unified API that supports multiple social providers, improved TypeScript support, and enhanced capabilities.

Abschnitt mit dem Titel „Installation“

Entfernen Sie das alte Paket:
  1. Terminalfenster

    In die Zwischenablage kopieren
    npm uninstall @capacitor-community/facebook-login
  2. Die neue Erweiterung modernisiert die Facebook-Authentifizierung mit einer einheitlichen __CAPGO_KEEP_0__ , die mehrere soziale Anbieter unterstützt, verbesserte TypeScript-Unterstützung und erweiterte Funktionen bietet.

    Terminalfenster
    npm install @capgo/capacitor-social-login
    npx cap sync
import { FacebookLogin } from '@capacitor-community/facebook-login';
import { SocialLogin } from '@capgo/capacitor-social-login';

Schlüsseländerung: Die neue Paket erfordert eine explizite Einrichtung in Ihrem code:

// Old package required no explicit initialization in code
// Configuration was done only in native platforms
// New package requires explicit initialization
await SocialLogin.initialize({
facebook: {
appId: 'YOUR_FACEBOOK_APP_ID', // Required for web and Android
clientToken: 'YOUR_CLIENT_TOKEN' // Required for Android
}
});

Der Login-Methode wird nun ein Parameter für den Anbieter akzeptiert:

const FACEBOOK_PERMISSIONS = ['email', 'public_profile'];
const result = await FacebookLogin.login({ permissions: FACEBOOK_PERMISSIONS });
const result = await SocialLogin.login({
provider: 'facebook',
options: {
permissions: ['email', 'public_profile'],
limitedLogin: false,
nonce: 'optional_nonce'
}
});

Die Antwortstruktur wurde modernisiert und umfasst ein umfassenderes Profilobjekt:

// Old response type
interface FacebookLoginResponse {
accessToken: {
applicationId: string;
userId: string;
token: string;
expires: string;
};
recentlyGrantedPermissions: string[];
recentlyDeniedPermissions: string[];
}
// New response type
interface FacebookLoginResponse {
provider: 'facebook';
result: {
accessToken: {
token: string;
applicationId?: string;
expires?: string;
userId?: string;
permissions?: string[];
declinedPermissions?: string[];
} | null;
idToken: string | null;
profile: {
userID: string;
email: string | null;
friendIDs: string[];
birthday: string | null;
ageRange: { min?: number; max?: number } | null;
gender: string | null;
location: { id: string; name: string } | null;
hometown: { id: string; name: string } | null;
profileURL: string | null;
name: string | null;
imageURL: string | null;
};
};
}

Hauptunterschiede:

  • Antwort enthält nun ein provider Feld, das den Authentifizierungsanbieter identifiziert
  • Mehr detailliert profile Objekt mit zusätzlichen Benutzerinformationen
  • Konsistente Struktur bei allen sozialen Login-Anbietern
const result = await FacebookLogin.getCurrentAccessToken();
const isLoggedIn = result && result.accessToken;
const status = await SocialLogin.isLoggedIn({
provider: 'facebook'
});
const isLoggedIn = status.isLoggedIn;
await FacebookLogin.logout();
await SocialLogin.logout({
provider: 'facebook'
});

Plattformspezifische Änderungen

Abschnitt: 'Plattformspezifische Änderungen'

Die Konfiguration wird nun über die initialize-Methode verwaltet:

// AndroidManifest.xml changes remain the same
// strings.xml become irrelevant
// Additionally initialize in your code:
await SocialLogin.initialize({
facebook: {
appId: 'your-app-id',
clientToken: 'your-client-token' // New requirement
}
});

Wichtig:

Ein Client-Token ist nun erforderlich für die Android-Authentifizierung.

iOS-Einrichtung
  1. Abschnitt mit dem Titel “iOS-Einrichtung” AppDelegate.swift Die iOS-Einrichtung in
import FBSDKCoreKit
// In application:didFinishLaunchingWithOptions:
FBSDKCoreKit.ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
// In application:openURL:options:
ApplicationDelegate.shared.application(
app,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
  1. In die Zwischenablage kopieren Info.plist Die
<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>fbauth</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>

Zusammenfassung der Änderungen im Code bei der Migration:

  1. Die explizite Initialisierung ist jetzt erforderlich - Muss aufgerufen werden initialize() vor der Verwendung
  2. Die Struktur des Antwortobjekts hat sich erheblich geändert - Neuer nested Ergebnisformat mit erweiterten Profildaten
  3. Ein Client-Token ist jetzt für Android erforderlich - Zusätzliche Konfiguration erforderlich
  4. Verschiedene Methodennamen und Parameterstrukturen - Provider-basierte Ansatz
  5. Fehlerbehandlung und Fehlerarten haben sich geändert - Mehr detaillierte Fehlerinformationen

Das neue Plugin bietet:

  • Einheitliche API über mehrere soziale Anbieter (Google, Apple, Facebook)
  • Verbesserte TypeScript-Unterstützung mit besseren Typdefinitionen
  • Erweiterte Profildaten mit mehr Benutzerinformationen
  • Aktive Wartung und Community-Unterstützung
  • Konsistente Fehlerbehandlung über alle Anbieter hinweg
  • Bessere Token-Verwaltung mit ordnungsgemäßer Ablaufzeitbehandlung

Für detailliertere Einrichtungsanweisungen, wenden Sie sich bitte an die offizielle Dokumentation.

Weitermachen von Facebook Login Migration zu @capgo/social-login

Abschnitt mit dem Titel „Weitermachen von Facebook Login Migration zu @capgo/social-login“

Wenn Sie Facebook Login Migration zu @capgo/social-login zur Planung der Authentifizierung und der Kontoflows verwenden, verbinden Sie es mit Mit @capgo/capacitor-social-login für die native Fähigkeit in Mit @capgo/capacitor-social-login, @capgo/capacitor-social-login für die Implementierungsdetails in @capgo/capacitor-social-login, @capgo/capacitor-passkey für die Implementierungsdetails in @capgo/capacitor-passkey, @capgo/capacitor-native-biometric für die Implementierungsdetails in @capgo/capacitor-native-biometric, und Zwei-Faktor-Authentifizierung für die Implementierungsdetails in Zwei-Faktor-Authentifizierung.