メインコンテンツにジャンプ

Firebase Google Login on iOS

GitHub

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

  1. console.cloud.google.com console.cloudflare.com

    Firebase Project Overview
  2. Click on the Add app button

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

    Firebase Add App iOS Button
  4. フォームの最初の部分を入力してください

    1. Fill Apple bundle ID
      1. Open Xcode をアプリの使用で開きます npx cap open ios
      2. Double click on App Xcode プロジェクト ナビゲータの App ターゲット
      3. Ensure that you are on Targets -> App Xcode の Targets セクションに App が選択されている
      4. Find your Bundle Identifier Xcode プロジェクト設定の Bundle Identifier フィールド
      5. Copy the Bundle Identifier とFirebaseコンソールに貼り付けてください Firebase Add App iOS Bundle IDフィールド
    2. Click on the Register app ボタン Firebase Add App iOS 登録ボタン
  5. Skip the Download config file ステップ

    Firebase Add App iOS ダウンロードをスキップするボタン
  6. Skip the Add firebase SDK ステップ

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

    Firebase Add App iOS Skip Add Initialization Code Button
  8. button Continue to console Firebase Add App iOS Continue to Console Button

    iOS用のクライアントIDと
  9. をご覧ください YOUR_DOT_REVERSED_IOS_CLIENT_ID

    1. console.cloud.google.com を探してください

    2. プロジェクトセレクター

      1. Firebaseプロジェクトの完全な名前でプロジェクトを検索し、クリックしてください。私の場合は Search up your project by the exact name of your Firebase project and click on it. In my case, it is
      2. Click on the project selector sociallogin-tutorial-app. Firebase Project セレクター Project
    3. __CAPGO_KEEP_0__ を開き、__CAPGO_KEEP_1__ を開き credentials

      1. __CAPGO_KEEP_0__ を開き Google Cloud Console 検索バー
      2. __CAPGO_KEEP_2__ を入力し credentials と __CAPGO_KEEP_3__ をクリックし APIs and Services __CAPGO_KEEP_4__ (スクリーンショットの 2 番目に表示されるもの) Google Cloud Console 資格情報検索
    4. __CAPGO_KEEP_5__ をクリックし iOS client for [YOUR_APP_ID] (auto created by Google Service) __CAPGO_KEEP_6__。私の場合は、 sociallogin-tutorial-app.

      Google Cloud Console 資格情報 iOS Client ID
    5. __CAPGO_KEEP_0__ をコピーする Client ID および iOS URL schemeこのガイドの次の部分で説明されているように、ファイルのアプリ内で使用する iOSClientId Note YOUR_DOT_REVERSED_IOS_CLIENT_ID.

      このガイドの次の部分で説明されているように、ファイルのアプリ内で使用する
  10. Note

    1. Go back to the Firebase console and go to Build -> Authentication Firebase Authentication Menu
    2. Click on the Sign-in method button Firebase Authentication Sign-in Method Button
    3. Click on the Google provider Firebase Authentication Sign-in Method Google Provider
    4. Click on the Web SDK configuration button Firebase Authentication Sign-in Method Web SDK Configuration Button
    5. Copy the Web client IDこのアプリケーションは webClientId このアプリケーション内で initialize プラグインのメソッドです。 Firebase Authentication Sign-in Method Web SDK 設定 Web Client ID
  11. アプリの Info.plist を変更する

    1. Xcode を開き、プロジェクト ナビゲーターで Info.plist ファイル

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

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

      Info.plistファイルのクロージングディクタータグ
    4. Insert the following fragment just before the closing </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. Change the YOUR_DOT_REVERSED_IOS_CLIENT_ID をステップ9でコピーしたiOS URLスキームの値に変更

      URLスキームに実際のリバースクライアントIDを挿入したInfo.plist
  12. Change the YOUR_IOS_CLIENT_ID to the iOS Client ID you copied in step 9

  13. Save the file with Command + S

  14. Modify the AppDelegate.swift

    1. Open the AppDelegate

      AppDelegate.swift file in Xcode project navigator
    2. Insert import GoogleSignIn at the top of the file

      AppDelegate.swift with GoogleSignIn import added
    3. Find the func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) function

      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ログインを authUtils.ts 例のアプリのファイルを使用して、Googleで認証します。

Firebase Authに初めてサインインすると、ユーザーが自動的に作成されます

トラブルシューティング

トラブルシューティング

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

  • Verify the idToken FirebaseのWebクライアントIDと一致するように
  • FirebaseコンソールでGoogle Sign-Inが有効になっていることを確認する
  • Info.plistに正しいURLスキームとGIDClientIDが含まれていることを確認する
  • Verify iOSServerClientId FirebaseのWebクライアントIDと一致するように
  • 例のアプリケーション__CAPGO_KEEP_0__ example app code Firebase Google Login on iOSから続けてください

Firebase Google Login on iOSを使用して 認証とアカウントフローの計画を行っている場合、 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-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の実装詳細 @capgo/capacitor-native-biometric 2要素認証 2要素認証の実装詳細について