내용으로 건너뛰기

iOS에서 Firebase Google 로그인

이 안내서에서는 iOS에서 Google Sign-In을 Firebase Authentication과 통합하는 방법을 설명합니다. Firebase Google 설정을 이미 완료했다고 가정합니다. __CAPGO_KEEP_0__.

  1. 프로젝트 개요를 확인하려면 console.cloud.google.com

    Firebase 프로젝트 개요
  2. 클릭 버튼 Add app 버튼

    Firebase Add App Button Firebase Add App Button
  3. 선택 iOS

    Firebase Add App iOS Button
  4. 폼의 첫 번째 부분을 완성하세요

    1. 완성 Apple bundle ID
      1. Xcode를 사용하여 앱을 열어주세요 npx cap open ios
      2. Double click on App Xcode 프로젝트 탐색기에서 앱 대상 클릭
      3. Ensure that you are on Targets -> App Xcode의 Targets 섹션에서 앱을 선택한 상태
      4. Find your Bundle Identifier Xcode 프로젝트 설정의 Bundle Identifier 필드에서 찾으세요
      5. Copy the Bundle Identifier Firebase 콘솔에 붙여넣기 Firebase Add App iOS Bundle ID 입력란
    2. 버튼을 클릭하세요. Register app 버튼 Firebase Add App iOS 등록 버튼
  5. 단계를 건너 뛰세요. Download config file 단계

    Firebase Add App iOS 다운로드 건너 뛰기 버튼
  6. 단계를 건너 뛰세요. Add firebase SDK Firebase Add App iOS 다운로드 건너 뛰기 Firebase __CAPGO_KEEP_0__ 버튼

    Firebase Add App iOS Skip Download Firebase SDK Button
  7. 단계 Add initialization code Firebase Add App iOS 다운로드 건너 뛰기 Firebase __CAPGO_KEEP_0__ 버튼

    Firebase Add App iOS Skip Add Initialization Code Button
  8. 클릭하여 Continue to console 버튼

    Firebase Add App iOS Continue to Console Button
  9. iOS 클라이언트 ID와 YOUR_DOT_REVERSED_IOS_CLIENT_ID

    1. Google Cloud Console로 console.cloud.google.com

    2. 프로젝트를 찾으세요

      1. 프로젝트 선택기 Firebase 프로젝트의 정확한 이름으로 프로젝트를 검색하고 클릭하세요. 나의 경우는
      2. Firebase Project Selector Project sociallogin-tutorial-app. Firebase Project Selector Project
    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) 1입니다. 나의 경우는 sociallogin-tutorial-app.

      Google Cloud Console 인증 정보 iOS 클라이언트 ID
    5. 복사 Client ID 그리고 iOS URL scheme이것은 각각 당신의 iOSClientIdYOUR_DOT_REVERSED_IOS_CLIENT_ID.

      Google Cloud Console Credentials iOS Client ID Copy
  10. 웹 클라이언트 ID를 가져오세요

    1. Firebase 콘솔로 돌아가서 다음 부분의 이 안내서에서 설명한 대로 앱의 Build -> Authentication 파이어베이스 인증 메뉴
    2. 버튼을 클릭하세요. Sign-in method 버튼 파이어베이스 인증 로그인 방법 버튼
    3. 버튼을 클릭하세요. Google 서비스 제공자 파이어베이스 인증 로그인 방법 Google 서비스 제공자
    4. 버튼을 클릭하세요. Web SDK configuration 파이어베이스 인증 로그인 방법 웹 __CAPGO_KEEP_0__ 설정 버튼 Firebase Authentication Sign-in Method Web SDK Configuration Button
    5. 키입니다. Web client IDwebClientId Firebase Authentication Sign-in Method Web __CAPGO_KEEP_0__ 설정 Web Client ID initialize 앱의 Info.plist를 수정하세요. Firebase Authentication Sign-in Method Web SDK Configuration Web Client ID
  11. 파일

    1. Xcode 프로젝트 탐색기에서 Info.plist 파일을 찾으세요. Info.plist 이 파일을 오른쪽 클릭하고 소스 __CAPGO_KEEP_0__로 열기

      소스 __CAPGO_KEEP_0__ 옵션을 보여주는 오른쪽 클릭 메뉴
    2. Right click this file and open it as source code

      Right-click menu showing Open As Source Code option
    3. 태그를 볼 수 있습니다. Plist Firebase Authentication Sign-in Method Web __CAPGO_KEEP_0__ Configuration Web Client ID </dict> Modify your app’s Info.plist

      Info.plist 파일의 다큐먼트 태그를 닫습니다.
    4. 닫는 태그 직전에 다음 프래그먼트를 삽입하세요. </dict> 태그

      URL 스키마 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 스키마의 실제 값으로 변경

      URL 스키마에 실제 역전된 클라이언트 ID를 삽입한 Info.plist
  12. Change the YOUR_IOS_CLIENT_ID __CAPGO_KEEP_0__

  13. Save the file with Command + S

  14. Modify the AppDelegate.swift

    1. Open the AppDelegate

      __CAPGO_KEEP_0__ file in Xcode project navigator
    2. Insert import GoogleSignIn __CAPGO_KEEP_0__ with GoogleSignIn import added

      Find the
    3. __CAPGO_KEEP_0__ func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) function

      원래 애플리케이션의 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 처리를 포함한 수정된 애플리케이션 openURL 함수
    5. 파일을 Command + S

  15. 앱에서 Google 로그인을 사용하는 방법

    이 단계에서는 앱에서 Google 로그인을 사용할 준비가 되었습니다. 다음과 같이 authUtils.ts 예제 앱의

Firebase Auth에 첫 번째 로그인 시 사용자 자동 생성

인증이 지연되거나 실패하는 경우:

  • Firebase 웹 클라이언트 ID와 일치하는지 확인하세요. idToken Firebase 콘솔에서 Google Sign-In이 활성화되어 있는지 확인하세요.
  • Info.plist에 올바른 URL schemes과 GIDClientID가 포함되어 있는지 확인하세요.
  • Firebase 웹 클라이언트 ID와 일치하는지 확인하세요.
  • 예시 앱 __CAPGO_KEEP_0__을 참조하세요. iOSServerClientId 참조용으로 예시 앱을 확인하세요.
  • 이전으로 example app code 예시 앱 __CAPGO_KEEP_0__