내용으로 건너뛰기

iOS에서 Google Firebase 로그인

GitHub

이 문서는 iOS에서 Google Sign-In을 Firebase 인증과 통합하는 방법을 설명합니다. Firebase 인증을 사용하기 전에 Firebase 인증을 사용할 수 있는지 확인한 것으로 가정합니다. Firebase Google 일반 설정.

설정 단계

설정 단계
  1. 프로젝트 개요로 이동하세요. console.cloud.google.com

    Firebase 프로젝트 개요
  2. 버튼 Add app Firebase 앱 추가 버튼

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

    Firebase iOS 앱 추가 버튼
  4. 폼의 첫 번째 부분을 채우세요

    1. 채우세요 Apple bundle ID
      1. Xcode에서 앱을 열어보세요 npx cap open ios
      2. Xcode 프로젝트 탐색기에서 App 프로젝트 탐색기에서 앱을 더블 클릭하세요
      3. Xcode 프로젝트 탐색기에서 앱을 선택한 상태로 확인하세요 Targets -> App Xcode에서 App을 선택한 Targets 섹션
      4. 찾아보세요 Bundle Identifier Xcode 프로젝트 설정의 Bundle Identifier 필드
      5. 복사하여 Bundle Identifier Firebase 콘솔에 붙여넣기 Firebase Add App iOS Bundle ID 필드
    2. 버튼 클릭 Register app __CAPGO_KEEP_0__ 파이어베이스 앱 추가 iOS 등록 버튼
  5. 스키핑 Download config file 단계

    파이어베이스 앱 추가 iOS 다운로드 생략 버튼
  6. 스키핑 Add firebase SDK 단계

    파이어베이스 앱 추가 iOS 다운로드 생략 파이어베이스 SDK 버튼
  7. 스키핑 Add initialization code 단계

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

    Firebase 앱 추가 iOS Console으로 계속
  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. 검색 credentialsAPIs and Services 스크린샷의 2번 구글 클라우드 콘솔 인증서 검색
    4. 클릭 iOS client for [YOUR_APP_ID] (auto created by Google Service) 1. 나의 경우는 sociallogin-tutorial-app.

      구글 클라우드 콘솔 인증서 iOS 클라이언트 ID
    5. 복사 Client IDiOS URL scheme이것은 각각 당신의 iOSClientIdYOUR_DOT_REVERSED_IOS_CLIENT_ID.

      Firebase 콘솔로 돌아가서
  10. Firebase Authentication 메뉴로 이동하세요

    1. 버튼을 클릭하세요 Build -> Authentication __CAPGO_KEEP_0__
    2. __CAPGO_KEEP_1__ Sign-in method __CAPGO_KEEP_2__ 구글 로그인
    3. 클릭하여 Google 서비스 구글 로그인
    4. 클릭하여 Web SDK configuration 버튼 웹 SDK 설정
    5. 복사하세요. 이 설정은 Web client ID플러그인에서 사용하는 webClientId 메소드의 initialize 웹 __CAPGO_KEEP_0__ 설정 Firebase Authentication Sign-in Method Web SDK Configuration Web Client ID
  11. 애플리케이션의 Info.plist을 수정하세요.

    1. Xcode를 열고 프로젝트 탐색기에서 Info.plist 파일

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

      오른쪽 클릭 메뉴에서 Open As Source Code 옵션
    3. 파일의 하단 부분에서 Plist 파일의 하단 부분에서 </dict> 태그

      Info.plist 파일의 Closing dict 태그
    4. Info.plist 파일의 Closing dict 태그를 닫기 전에 </dict> 닫는 태그

      URL scheme 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 scheme에 실제 역전된 클라이언트 ID를 삽입한 Info.plist
  12. 9번 단계에서 복사한 iOS Client ID를 입력하세요 YOUR_IOS_CLIENT_ID STARTS

  13. 파일을 저장하세요. Command + S

  14. 수정하세요. AppDelegate.swift

    1. AppDelegate를 열어보세요.

      Xcode 프로젝트 탐색기에서 AppDelegate.swift 파일을 열어보세요.
    2. 삽입하세요. import GoogleSignIn AppDelegate.swift 파일의 맨 위에 GoogleSignIn import를 추가하세요.

      AppDelegate.swift에서 찾으세요.
    3. AppDelegate.swift에서 함수를 찾으세요. func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) AppDelegate.swift에서 원래의 openURL 함수를 찾으세요.

      AppDelegate.swift에서 함수를 수정하세요.
    4. AppDelegate.swift에서 함수를 수정하세요.

      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 로그인을 앱에 사용할 준비가 되었습니다. Google 로그인을 사용하려면 authUtils.ts 예제 앱의 authUtils.ts 파일을 사용하여 Google과 인증하세요.

사용자가 Firebase Auth에 처음 로그인할 때 자동으로 계정이 생성됩니다.

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

  • Firebase web client ID와 매치되는 idToken 대상을 확인하세요.
  • Google Sign-In이 Firebase Console에서 활성화되어 있는지 확인하세요.
  • Info.plist에 올바른 URL schemes과 GIDClientID이 포함되어 있는지 확인하세요.
  • 확인 iOSServerClientId 웹 클라이언트 ID와 일치하는지 확인하세요.
  • 예시 앱 __CAPGO_KEEP_0__을 참조하세요. example app code Firebase Google Login on iOS에서 계속 진행하세요.

Firebase Google Login on iOS를 사용하여 인증 및 계정 흐름을 계획하고 있습니다. iOS에서 Firebase Google Login을 연결하는 방법 Firebase Google Login on iOS를 사용하여 인증 및 계정 흐름을 계획하고 있습니다. Firebase Google Login on iOS를 iOS에서 연결하세요. Using @capgo/capacitor-social-login for the native capability in Using @capgo/capacitor-social-login, @capgo/capacitor-social-login for the implementation detail in @capgo/capacitor-social-login, @capgo/capacitor-passkey for the implementation detail in @capgo/capacitor-passkey, @capgo/capacitor-native-biometric for the implementation detail in @capgo/capacitor-native-biometric, and 두 단계 인증 두 단계 인증 구현 세부 정보