내용으로 건너뛰기

Facebook 로그인 설정

GitHub

Capgo Social Login과 Facebook 로그인을 설정하는 방법을 배울 것입니다. 다음을 필요로합니다:

  • Facebook 개발자 계정
  • 앱의 패키지 이름/번들 ID
  • Android에서 키 해시를 생성하기 위한 터미널에 대한 접근

Facebook 앱 만들기

  1. 튜토리얼을 따라서

    앱 만들기 설정

  2. 앱에 Facebook 로그인을 추가하세요

    Facebook 개발자 도구에서 Facebook 로그인 제품을 앱에 추가하세요

  3. 앱을 일반인에게 공개하기 전에 이 튜토리얼 을 따라야 합니다

앱을 공개하기

중요한 정보

중요한 정보

  1. CLIENT_TOKEN:

    통합을 위해 필요한 키 정보를 찾으려면 여기에 오세요
  2. APP_ID:

    Facebook 개발자 도구에서 클라이언트 토큰을 찾으세요
  3. APP_NAME:

    Facebook 개발자 도구에서 앱 ID를 찾으세요

Facebook 개발자 도구에서 앱 이름을 찾으세요

안드로이드 설정
  1. 인터넷 권한을 추가하세요. AndroidManifest.xml

    이 줄이 포함되어야 합니다.

    <uses-permission android:name="android.permission.INTERNET"/>
  2. Android 키 해시를 생성하세요.

    이 단계는 Facebook에 의해 필요합니다. 터미널을 열고 다음 명령어를 실행하세요.

    터미널 창
    keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 -A

    비밀번호를 입력할 때 사용하세요: android

  3. Facebook 앱에 키 해시를 추가하세요

    1. Facebook Developers에서 앱의 대시보드에 가세요
    2. Settings > 기본으로 이동하세요
    3. ‘Android’ 섹션으로 스크롤 다운하세요
    4. Android가 아직 추가되지 않았다면 ‘플랫폼 추가’를 클릭하고 세부 정보를 입력하세요
    5. 생성한 키 해시를 추가하세요
    6. 프로덕션에서 debug 및 release 키 해시 모두 추가하세요
  4. 업데이트하여 AndroidManifest.xml 다음과 같이 포함하세요:

    <application>
    ...
    <activity android:name="com.facebook.FacebookActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name" />
    <activity
    android:name="com.facebook.CustomTabActivity"
    android:exported="true">
    <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="FB[APP_ID]" />
    </intent-filter>
    </activity>
    </application>
  1. Facebook 개발자 콘솔에서 iOS 플랫폼을 추가하세요.

    1. Facebook 개발자에 있는 앱의 대시보드에 가세요.
    2. 설정 > 기본 > 설정
    3. 페이지의 가장 아래쪽으로 스크롤하고 '플랫폼 추가' 버튼을 클릭하세요.
    4. iOS를 선택하고 필요한 정보를 입력하세요.
  2. Xcode 프로젝트를 열고 Info.plist로 이동하세요.

  3. Info.plist에 다음 항목을 추가하세요:

    <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>fb-messenger-share-api</string>
    </array>
    <key>CFBundleURLTypes</key>
    <array>
    <dict>
    <key>CFBundleURLSchemes</key>
    <array>
    <string>fb[APP-ID]</string>
    </array>
    </dict>
    </array>
  4. 수정하는 AppDelegate.swift

    import FBSDKCoreKit
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    // Initialize Facebook SDK
    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)
    }
    }
    }

Facebook 로그인 사용하기

Facebook 로그인 사용하기
  1. 앱에 Facebook 로그인 초기화하기

    import { SocialLogin } from '@capgo/capacitor-social-login';
    // Initialize during app startup
    await SocialLogin.initialize({
    facebook: {
    appId: 'APP_ID',
    clientToken: 'CLIENT_TOKEN',
    }
    })
  2. 로그인 함수 implement하기

    async function loginWithFacebook() {
    try {
    const result = await SocialLogin.login({
    provider: 'facebook',
    options: {
    permissions: ['email', 'public_profile'],
    limitedLogin: false // See Limited Login section below for important details
    }
    });
    console.log('Facebook login result:', result);
    // Handle successful login
    } catch (error) {
    console.error('Facebook login error:', error);
    // Handle error
    }
    }
  3. 사용자 프로필 데이터 가져오기

    로그인 성공 후 추가 프로필 정보를 가져올 수 있습니다.

    async function getFacebookProfile() {
    try {
    const profileResponse = await SocialLogin.providerSpecificCall({
    call: 'facebook#getProfile',
    options: {
    fields: ['id', 'name', 'email', 'first_name', 'last_name', 'picture']
    }
    });
    console.log('Facebook profile:', profileResponse.profile);
    return profileResponse.profile;
    } catch (error) {
    console.error('Failed to get Facebook profile:', error);
    return null;
    }
    }
    // Example usage after login
    async function loginAndGetProfile() {
    const loginResult = await loginWithFacebook();
    if (loginResult) {
    const profile = await getFacebookProfile();
    if (profile) {
    console.log('User ID:', profile.id);
    console.log('Name:', profile.name);
    console.log('Email:', profile.email);
    console.log('Profile Picture:', profile.picture?.data?.url);
    }
    }
    }

    토큰 타입 제한: getProfile 호출은 Facebook 토큰이 있는 경우에만 작동합니다. access token (표준 로그인에 추적 허용). 사용자가 추적 거부하거나 제한 로그인(JWT 토큰만)을 사용하는 경우, 이 호출은 실패합니다. 그 경우, 초기 로그인 응답에서 제공된 프로필 데이터를 사용하세요.

⚠️ Backend Token Handling에 대한 중요 경고

Section titled “⚠️ Backend Token Handling”

Your backend must handle 두 가지 토큰 유형을 처리해야 합니다. iOS 사용자는 앱 추적 투명성 선택에 따라 액세스 토큰 또는 JWT 토큰 중 하나를 받을 수 있기 때문에,

백엔드가 두 가지 토큰 유형을 처리해야 합니다. Android 사용자는 항상 액세스 토큰을 받습니다.

플랫폼별 토큰 유형
플랫폼제한된 로그인 설정사용자 ATT 선택결과 토큰 유형
iOStrue어떤JWT 토큰
iOSfalse추적을 허용액세스 토큰
iOSfalse추적 거부JWT 토큰 (자동 재정의)
Android어떤N/A액세스 토큰 (항상)

백엔드 구현

백엔드 구현 섹션
  1. 토큰 유형 감지 및 적절히 처리

    async function loginWithFacebook() {
    try {
    const loginResult = await SocialLogin.login({
    provider: 'facebook',
    options: {
    permissions: ['email', 'public_profile'],
    limitedLogin: false // iOS: depends on ATT, Android: ignored
    }
    });
    if (loginResult.accessToken) {
    // Access token (Android always, iOS when tracking allowed)
    return handleAccessToken(loginResult.accessToken.token);
    } else if (loginResult.idToken) {
    // JWT token (iOS only when tracking denied or limitedLogin: true)
    return handleJWTToken(loginResult.idToken);
    }
    } catch (error) {
    console.error('Facebook login error:', error);
    }
    }
  2. 파이어베이스 통합 예제

    import { OAuthProvider, FacebookAuthProvider, signInWithCredential } from 'firebase/auth';
    async function handleAccessToken(accessToken: string, nonce: string) {
    // For access tokens, use OAuthProvider (new method)
    const fbOAuth = new OAuthProvider("facebook.com");
    const credential = fbOAuth.credential({
    idToken: accessToken,
    rawNonce: nonce
    });
    try {
    const userResponse = await signInWithCredential(auth, credential);
    return userResponse;
    } catch (error) {
    console.error('Firebase OAuth error:', error);
    return false;
    }
    }
    async function handleJWTToken(jwtToken: string) {
    // For JWT tokens, send to your backend for validation
    try {
    const response = await fetch('/api/auth/facebook-jwt', {
    method: 'POST',
    headers: {
    'Content-Type': 'application/json',
    },
    body: JSON.stringify({ jwtToken })
    });
    const result = await response.json();
    return result;
    } catch (error) {
    console.error('JWT validation error:', error);
    return false;
    }
    }
  3. 백엔드 JWT 유효성 검사

    // Backend: Validate JWT token from Facebook
    import jwt from 'jsonwebtoken';
    import { Request, Response } from 'express';
    app.post('/api/auth/facebook-jwt', async (req: Request, res: Response) => {
    const { jwtToken } = req.body;
    try {
    // Verify JWT token with Facebook's public key
    // See: https://developers.facebook.com/docs/facebook-login/limited-login/token/validating/#standard-claims
    const decoded = jwt.verify(jwtToken, getFacebookPublicKey(), {
    algorithms: ['RS256'],
    audience: process.env.FACEBOOK_APP_ID,
    issuer: 'https://www.facebook.com' // From: https://www.facebook.com/.well-known/openid-configuration/?_rdr
    });
    // Extract user info from JWT
    const userInfo = {
    id: decoded.sub,
    email: decoded.email,
    name: decoded.name,
    isJWTAuth: true
    };
    // Create your app's session/token
    const sessionToken = createUserSession(userInfo);
    res.json({
    success: true,
    token: sessionToken,
    user: userInfo
    });
    } catch (error) {
    console.error('JWT validation failed:', error);
    res.status(401).json({ success: false, error: 'Invalid token' });
    }
    });
  4. 일반 백엔드 토큰 핸들러

    // Handle both token types in your backend
    async function authenticateFacebookUser(tokenData: any) {
    if (tokenData.accessToken) {
    // Handle access token - validate with Facebook Graph API
    const response = await fetch(`https://graph.facebook.com/me?access_token=${tokenData.accessToken}&fields=id,name,email`);
    const userInfo = await response.json();
    return {
    user: userInfo,
    tokenType: 'access_token',
    expiresIn: tokenData.expiresIn || 3600
    };
    } else if (tokenData.jwtToken) {
    // Handle JWT token - decode and validate
    // See: https://developers.facebook.com/docs/facebook-login/limited-login/token/validating/#standard-claims
    const decoded = jwt.verify(tokenData.jwtToken, getFacebookPublicKey());
    return {
    user: {
    id: decoded.sub,
    name: decoded.name,
    email: decoded.email
    },
    tokenType: 'jwt',
    expiresIn: decoded.exp - Math.floor(Date.now() / 1000)
    };
    } else {
    throw new Error('No valid token provided');
    }
    }

중요 고려 사항

중요 고려 사항 섹션

액세스 토큰 (표준 로그인):

  • Android: 항상 사용할 수 있습니다. (iOS-ONLY 제한이 적용되지 않습니다.)
  • iOS: 사용자가 앱 추적을 허용할 때만 사용할 수 있습니다.
  • ✅ Can be used to access Facebook Graph API
  • ✅ 더 긴 유효 기간
  • ✅ 사용자 데이터가 더 많습니다.
  • iOS 사용자가 트래킹 거부하는 경우 점점 더 흔해지며 __CAPGO_KEEP_0__

: iOS에서만 사용되는 트래킹 거부 모드에서 사용되는 JWT 토큰:

  • Android: 사용되지 않음 (지원하지 않음)
  • iOS: 트래킹이 거부되거나 사용자에게 limitedLogin: true
  • ✅ iOS 사용자 개인 정보 보호 설정을 존중합니다
  • ❌ 사용자 기본 정보만 포함합니다
  • ❌ 만료 시간이 짧습니다
  • ❌ No access to Facebook Graph API
  • ⚠️ iOS 사용자가 가장 흔하게 사용하는 시나리오입니다

플랫폼별 동작:

  • iOS 앱: 액세스 토큰 및 JWT 토큰 모두 처리해야 함
  • Android 앱: 액세스 토큰만 처리해야 함
  • 크로스 플랫폼 앱: 두 가지 토큰 처리 방법 모두 implement해야 함

Secure Context Requirements (Web/Capacitor)

Secure Context Requirements (Web/Capacitor)

업데이트된 Facebook 로그인 흐름은 __CAPGO_KEEP_0__ API 암호화 __CAPGO_KEEP_0__를 사용하여 비어있는 값을 생성하기 위해 필요합니다. 이는 __CAPGO_KEEP_0__ secure contexts:

// This requires secure context (HTTPS or localhost)
async function sha256(message: string) {
const msgBuffer = new TextEncoder().encode(message);
const hashBuffer = await crypto.subtle.digest("SHA-256", msgBuffer); // ❌ Fails in insecure context
// ...
}

__CAPGO_KEEP_0__: ionic serve HTTP URL을 사용하는 경우 Facebook 인증이 깨지게 됩니다.

환경암호화 API 사용 가능Facebook 로그인 작동
http://localhost:3000✅ 예✅ 예
http://127.0.0.1:3000✅ 예✅ 예
http://192.168.1.100:3000❌ 아니오❌ 아니오
https://any-domain.com✅ 예✅ 예

Capacitor 개발을 위한 솔루션

Capacitor 개발을 위한 솔루션
  1. localhost를 사용하여 웹 테스트

    터미널 창
    # Instead of ionic serve --host=0.0.0.0
    ionic serve --host=localhost
  2. Ionic에서 HTTPS를 활성화

    터미널 창
    ionic serve --ssl
  3. 실제 장치에서 테스트

    터미널 창
    # Capacitor apps run in secure context on devices
    ionic cap run ios
    ionic cap run android
  4. 개발용 대체 nonce 생성

    async function generateNonce() {
    if (typeof crypto !== 'undefined' && crypto.subtle) {
    // Secure context - use crypto.subtle
    return await sha256(Math.random().toString(36).substring(2, 10));
    } else {
    // Fallback for development (not secure for production)
    console.warn('Using fallback nonce - not secure for production');
    return btoa(Math.random().toString(36).substring(2, 10));
    }
    }

파이어베이스 통합 설명

파이어베이스 통합 설명 섹션

최근 파이어베이스 문서는 Facebook 인증을 위해 JWT 토큰과 NONCE가 필요합니다. 로그인 설정에 관계없이 이 방법은 양쪽 모두에 작동합니다. limitedLogin: truelimitedLogin: false:

// Both modes can return JWT tokens depending on user choice
const loginResult = await SocialLogin.login({
provider: 'facebook',
options: {
permissions: ['email', 'public_profile'],
limitedLogin: false, // true = always JWT, false = depends on user tracking choice
nonce: nonce
}
});

개발 제한: 로컬 호스트가 아닌 네트워크 IP에서 Facebook 로그인 시 crypto __CAPGO_KEEP_0__ 제한으로 인해 로그인에 실패합니다. 로컬 호스트 또는 HTTPS를 사용하여 웹 테스트를 진행하세요. ionic serve on a network IP (not localhost), Facebook login will fail due to crypto API restrictions. Use localhost or HTTPS for web testing.

[Troubleshooting]

[Troubleshooting]

[Common Issues and Solutions]

[Common Issues and Solutions]
  1. Android에서 Key hash 오류

    • Android에서 Facebook 대시보드에 올바른 Key hash를 추가했는지 확인하세요
    • 릴리즈 빌드에서는 디버그와 릴리즈 Key hash 모두 추가했는지 확인하세요
    • Keystore를 올바르게 사용했는지 확인하세요
  2. Facebook 로그인 버튼이 나타나지 않습니다

    • 모든 매니페스트 항목이 올바른지 확인하세요
    • Facebook App ID와 Client Token이 올바른지 확인하세요
    • SDK를 올바르게 초기화했는지 확인하세요
  3. iOS 일반 문제

    • Info.plist 항목이 모두 정확한지 확인하세요
    • URL 스키마가 올바르게 구성되어 있는지 확인하세요
    • Facebook 대시보드에 등록된 것과 일치하는 Bundle ID가 있는지 확인하세요

테스트

테스트란?
  1. 테스트하기 전에 Facebook Developer Console에서 테스트 사용자를 추가하세요

    • Roles > Test Users로 이동하세요
    • 테스트 사용자 생성
    • 테스트에 사용할 이메일과 비밀번호입니다
  2. debug 및 release 빌드 모두 테스트하세요

    • debug 키 해시를 사용한 debug 빌드
    • __CAPGO_KEEP_0__을 사용하여 빌드.release 키 해시
    • __CAPGO_KEEP_0__에서 테스트: 에뮬레이터 및 물리적 장치

로그인 흐름의 모든 단계를 테스트하십시오. 다음을 포함합니다:

  • 로그인 성공
  • 로그인 취소
  • 오류 처리
  • 로그아웃 기능

Facebook 로그인 설정에서 계속하기

Facebook 로그인 설정에서 계속하기

Facebook 로그인 설정을 사용하는 경우 Facebook 로그인 설정을 사용하여 인증 및 계정 흐름을 계획하고 연결하십시오. __CAPGO_KEEP_0__ @capgo/capacitor-social-login native capability in @capgo/capacitor-social-login @capgo/capacitor-social-login implementation detail in @capgo/capacitor-social-login @capgo/capacitor-passkey implementation detail in @capgo/capacitor-passkey @capgo/capacitor-native-biometric implementation detail in @capgo/capacitor-native-biometric, and Two-factor authentication implementation detail in Two-factor authentication.