コンテンツにジャンプ

Firebase Google Login on iOS

GitHub

このガイドでは、iOSでGoogle Sign-InをFirebase Authenticationに統合する方法を説明します。Google Sign-InとFirebase Authenticationの一般的なセットアップをすでに完了していることを前提としています。 注意.

  1. Firebase Consoleのプロジェクト概要ページに移動してください。 console.cloud.google.com

    Firebase Project Overview
  2. この Add app button

    Firebase Add App Button Firebase Add App Button
  3. Select iOS

    Firebase Add App iOS Button
  4. Fill the first part of the form

    1. Fill the first part of the form Apple bundle ID
      1. Fill npx cap open ios
      2. Open Xcode at your app using App Double click on
      3. App target in Xcode project navigator Targets -> App Ensure that you are on
      4. Targets section in Xcode with App selected Bundle Identifier Find your
      5. Copy the Bundle Identifier をコピーし、 に貼り付けます。
    2. Click on the Register app button Firebase Add App iOS Register Button
  5. Skip the Download config file step

    iOSアプリにFirebaseを追加する
  6. ダウンロードをスキップする Add firebase SDK ステップ

    Firebase Add App iOS Skip Download Firebase SDK Button
  7. ダウンロードをスキップする Add initialization code Firebase

    Code
  8. ステップ Continue to console iOSアプリにFirebaseを追加する

    初期化を追加する
  9. __CAPGO_KEEP_0__ YOUR_DOT_REVERSED_IOS_CLIENT_ID

    1. ボタンをクリックする 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 番目の (スクリーンショットの 2 番目) Google Cloud Console の資格情報検索
    4. Click on the iOS client for [YOUR_APP_ID] (auto created by Google Service) 1. 私の場合は sociallogin-tutorial-app.

      Google Cloud Console の資格情報検索 iOS Client ID
    5. 資格情報の Client ID 資格情報の iOS URL scheme資格情報のコピーをします。 iOSClientIdYOUR_DOT_REVERSED_IOS_CLIENT_ID.

      iOS Client IDをコピー
  10. WebクライアントIDを取得

    1. Firebaseコンソールに戻り、 Build -> Authentication Firebase Authenticationメニュー
    2. ボタン Sign-in method Firebase Authenticationサインイン方法 ボタン
    3. サインインプロバイダーをクリックします。 Google サインインプロバイダーをクリック Firebase Authentication Sign-in Method Google Provider
    4. をクリックしてください。 Web SDK configuration ボタン Firebase Authentication Sign-in Method Web SDK 設定ボタン
    5. をコピーしてください。 これがあなたの Web client IDに表示されます。 webClientId の方法です。 initialize Firebase Authentication Sign-in Method Web __CAPGO_KEEP_0__ 設定 Web Client ID Firebase Authentication Sign-in Method Web SDK Configuration Web Client ID
  11. のファイル

    1. を探してください。 Info.plist ファイル

      Xcodeプロジェクトナビゲータ内のInfo.plistファイル
    2. このファイルを右クリックし、ソースとして開きます code

      右クリックメニューのOpen As Source Codeオプション
    3. 下部の Plist ファイル </dict> 中には

      タグ
    4. Info.plistファイル内のdictタグの閉じ </dict> Info.plistファイルの閉じ

      Info.plist with URL schemes code inserted before closing dict tag
      <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スキーム)

      Info.plistに実際の逆接続IDを挿入したURLスキーム
  12. ステップ9でコピーしたiOS Client IDに設定 YOUR_IOS_CLIENT_ID ファイルを

  13. 修正 Command + S

  14. AppDelegateを開く AppDelegate.swift

    1. Open the AppDelegate

      XcodeプロジェクトナビゲータでAppDelegate.swiftファイルを見つける
    2. 挿入 import GoogleSignIn ファイルの先頭に追加

      AppDelegate.swiftファイルにGoogleSignIn importを追加
    3. 以下の func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) 関数

      AppDelegateの元の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ログインをアプリに使用する準備が整っています。 Googleログインを使用するには、 __CAPGO_KEEP_0__ 例のアプリのauthUtils.tsファイルを使用して、Googleと認証してください。

初回のサインイン時に、Firebase Authにユーザーが自動的に作成されます。

認証がハングアップまたは失敗した場合:

  • Firebase Web Client IDと一致するように idToken Firebase ConsoleでGoogle Sign-Inが有効になっていることを確認してください。
  • Info.plistファイルに正しいURLスキームとGIDClientIDが含まれていることを確認してください。
  • Firebase Web Client IDと一致するように
  • Verify iOSServerClientId matches your web client ID
  • Review the example app code for reference

Keep going from Firebase Google Login on iOS

Section titled “Keep going from Firebase Google Login on iOS”

If you are using Firebase Google Login on iOS to plan authentication and account flows, connect it with Using @capgo/capacitor-social-login @capgo/capacitor-social-login for iOSのnative capabilityのために使用する @capgo/capacitor-social-login for iOSのnative capabilityのために使用する 実装詳細については @capgo/capacitor-social-login に @capgo/capacitor-passkey 実装詳細については @capgo/capacitor-passkey に @capgo/capacitor-native-biometric 実装詳細については @capgo/capacitor-native-biometric、 2要素認証 実装詳細については 2要素認証 に