본문 바로가기

iOS에서 Firebase Google Login

GitHub

이 가이드는 iOS에서 Firebase Authentication과 Google Sign-In을 연동하는 방법을 안내합니다. 다음은 이미 완료했다고 가정합니다. Firebase Google 일반 설정.

  1. 다음 프로젝트 개요 페이지로 이동하세요: console.cloud.google.com

    Firebase 프로젝트 개요
  2. 다음을 클릭하세요: Add app 버튼을 클릭하세요

    Firebase 앱 추가 버튼 Firebase 앱 추가 버튼
  3. 선택 iOS

    Firebase iOS 앱 추가 버튼
  4. 양식의 첫 번째 부분을 작성하세요

    1. 다음 항목을 작성하세요 Apple bundle ID
      1. 사용 중인 앱을 Xcode로 여세요 npx cap open ios
      2. 더블 클릭하여 App Xcode 프로젝트 네비게이터의 App target
      3. 다음 항목이 선택되었는지 확인하세요 Targets -> App Xcode의 App이 선택된 Targets 섹션
      4. 다음 항목을 찾으세요 Bundle Identifier Xcode 프로젝트 설정의 Bundle Identifier 필드
      5. 다음을 복사하세요 Bundle Identifier 를 사용하여 Firebase 콘솔에 붙여넣겠습니다 Firebase 앱 추가 iOS 번들 ID 필드
    2. 다음을 클릭하세요: Register app 버튼을 클릭하세요 Firebase 앱 추가 iOS 등록 버튼
  5. 다음 단계를 Download config file 단계

    Firebase 앱 추가 iOS 다운로드 건너뛰기 버튼
  6. 다음 단계를 Add firebase SDK 단계

    Firebase iOS 앱 추가: Firebase SDK 다운로드 건너뛰기 버튼
  7. 다음 단계를 Add initialization code 단계

    Firebase iOS 앱 추가: 초기화 Code 건너뛰기 버튼
  8. 다음을 클릭하세요: Continue to console 버튼을 클릭하세요

    Firebase iOS 앱 추가: 콘솔로 이동 버튼
  9. iOS 클라이언트 ID와 YOUR_DOT_REVERSED_IOS_CLIENT_ID

    1. Google Cloud Console로 이동: console.cloud.google.com

    2. 프로젝트 찾기

      1. 프로젝트 선택기를 클릭하세요 Google Cloud Console 프로젝트 선택기
      2. Firebase 프로젝트의 정확한 이름으로 검색한 뒤 클릭하세요. 제 경우에는 sociallogin-tutorial-app. Firebase 프로젝트 선택기
    3. 검색창을 열고 다음을 여세요 credentials

      1. 검색창 열기 Google Cloud Console 검색창
      2. 검색: credentials 를 클릭하세요 APIs and Services 해당 항목(스크린샷의 2번) Google Cloud Console 사용자 인증 정보 검색
    4. 다음을 클릭하세요: iOS client for [YOUR_APP_ID] (auto created by Google Service) 첫째, 제 경우에는 sociallogin-tutorial-app.

      Google Cloud Console Credentials iOS Client ID와
    5. 다음을 복사하세요 Client ID 더불어 iOS URL scheme. 이는 각각 다음을 의미합니다: iOSClientId 및 YOUR_DOT_REVERSED_IOS_CLIENT_ID.

      Google Cloud Console Credentials iOS Client ID 복사
  10. Web Client ID 가져오기

    1. Firebase console로 돌아가서 다음으로 이동하세요: Build -> Authentication Firebase Authentication 메뉴
    2. 다음을 클릭하세요: Sign-in method 버튼을 클릭하세요 Firebase Authentication 로그인 방법 버튼
    3. 다음을 클릭하세요: Google provider Firebase Authentication 로그인 방법 Google Provider
    4. 다음을 클릭하세요: Web SDK configuration 버튼을 클릭하세요 Firebase Authentication 로그인 방법 Web SDK 설정 버튼
    5. 다음을 복사하세요 Web client ID. 이것이 webClientId 플러그인의 initialize 메서드에서 사용할 값입니다. Firebase Authentication 로그인 방법 Web SDK 설정 Web Client ID
  11. Info.plist 파일 수정하기

    1. Xcode를 열고 다음 항목을 찾으세요 Info.plist 파일

      Xcode 프로젝트 네비게이터의 Info.plist 파일
    2. 이 파일을 우클릭해 Open As Source code로 여세요

      Open As Source Code 옵션이 포함된 우클릭 메뉴
    3. 맨 아래에 Plist 파일에서 보면 다음과 같은 </dict> 태그가 있습니다

      Info.plist 파일의 닫는 dict 태그
    4. 닫는 태그 바로 앞에 다음 코드 조각을 삽입하세요 </dict> 태그가 있습니다

      닫는 dict 태그 앞에 URL schemes code가 삽입된 Info.plist
      <key>CFBundleURLTypes</key>
      <array>
      <dict>
      <key>CFBundleURLSchemes</key>
      <array>
      <string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string>
      </array>
      </dict>
      </array>
      <key>GIDClientID</key>
      <string>YOUR_IOS_CLIENT_ID.apps.googleusercontent.com</string>
    5. 다음을 변경하세요 YOUR_DOT_REVERSED_IOS_CLIENT_ID 9단계에서 복사한 값(iOS URL scheme)으로

      URL schemes에 실제 reversed client ID가 삽입된 Info.plist
  12. 다음을 변경하세요 YOUR_IOS_CLIENT_ID 9단계에서 복사한 iOS Client ID

  13. 파일을 다음 이름으로 저장하세요: Command + S

  14. 다음 내용을 수정하세요: AppDelegate.swift

    1. AppDelegate 파일을 여세요

      Xcode 프로젝트 네비게이터에서 AppDelegate.swift 파일을 엽니다
    2. 삽입 import GoogleSignIn 파일 최상단에

      GoogleSignIn import가 추가된 AppDelegate.swift
    3. 다음 func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) 함수

      AppDelegate의 기존 application openURL 함수
    4. 함수를 다음과 같이 수정하세요

      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
      var handled: Bool
      handled = GIDSignIn.sharedInstance.handle(url)
      if handled {
      return true
      }
      return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
      }
      GoogleSignIn 처리가 추가된 application openURL 함수
    5. 파일을 저장하세요 Command + S

  15. 앱에서 Google 로그인 사용하기

    이제 앱에서 Google 로그인을 사용할 준비가 되었습니다. 다음 파일을 사용하세요: authUtils.ts Google 인증을 위한 예제 앱 파일입니다.

첫 로그인 시 Firebase Auth에 사용자가 자동으로 생성됩니다.

인증이 멈추거나 실패하는 경우:

  • 다음 사항을 확인하세요: idToken audience가 Firebase web client ID와 일치하는지
  • Firebase Console에서 Google Sign-In이 활성화되어 있는지
  • Info.plist에 올바른 URL schemes와 GIDClientID가 설정되었는지
  • 확인 사항: iOSServerClientId web client ID와 일치하는지
  • 다음 내용을 검토하세요: code 예제 앱 참고용

iOS Firebase Google Login 이후 단계

“iOS Firebase Google Login 이후 단계” 섹션

사용 중이라면 iOS에서 Firebase Google Login 인증 및 계정 흐름을 설계할 때, 이를 다음 항목과 연결하세요: @capgo/capacitor-social-login 사용하기 @capgo/capacitor-social-login 사용 시 네이티브 기능 구현을 위해, @capgo/capacitor-social-login @capgo/capacitor-social-login의 구현 세부 사항은, @capgo/capacitor-passkey @capgo/capacitor-passkey의 구현 세부 사항은 @capgo/capacitor-native-biometric @capgo/capacitor-native-biometric의 구현 세부 사항은, 2단계 인증 2단계 인증의 구현 세부 사항에 대해서는