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

__CAPGO_KEEP_0__

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

セクション「セットアップ手順」

プロジェクトの概要に移動してください。
  1. console.cloud.google.com console.cloud.google.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. Xcodeでアプリを使用する npx cap open ios
      2. __CAPGO_KEEP_0__をダブルクリック App Xcodeプロジェクトナビゲータのアプリターゲット
      3. アプリが選択されていることを確認してください Targets -> App Xcodeのターゲットセクション
      4. アプリの Bundle Identifier Xcodeプロジェクト設定のBundle Identifierフィールド
      5. コピーしてください Bundle Identifier と入力し、Firebaseコンソールに貼り付けます。 Firebaseにアプリを追加するiOS Bundle IDフィールド
    2. ボタンをクリックします。 Register app ボタン Firebaseにアプリを追加するiOSの登録ボタン
  5. ステップをスキップします。 Download config file Firebaseにアプリを追加するiOSのダウンロードをスキップするボタン

    ステップをスキップします。
  6. Firebaseにアプリを追加するiOSのダウンロードをスキップするFirebase __CAPGO_KEEP_0__ ボタン Add firebase SDK ステップをスキップします。

    Firebase Add App iOS Skip Download Firebase SDK Button
  7. Firebaseにアプリを追加するiOSのダウンロードをスキップする 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プロジェクトの完全な名前でプロジェクトを検索し、クリックしてください。私の場合は です
      2. プロジェクトセレクター sociallogin-tutorial-app. __CAPGO_KEEP_0__
    3. 検索バーを開き、検索 credentials

      1. 検索バーを開きます Google Cloud Consoleの検索バー
      2. を検索してください credentials をクリックしてください APIs and Services 1つ目 (スクリーンショットの2番目) Google Cloud Consoleの資格情報検索
    4. をクリックしてください 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__CAPGO_KEEP_0__の場合 iOSClientIdYOUR_DOT_REVERSED_IOS_CLIENT_ID.

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

    1. Firebaseコンソールに戻り、 Build -> Authentication Firebase Authenticationメニュー
    2. ボタンを Sign-in method Firebase Authenticationサインイン方法ボタン Firebase Authenticationサインイン方法Googleプロバイダ
    3. プロバイダを Google Firebase Authenticationサインイン方法Web__CAPGO_KEEP_0__設定ボタン ボタンを
    4. 設定を Web SDK configuration 設定を Firebase Authentication Sign-in Method Web SDK Configuration Button
    5. 設定を Web client ID. このアプリケーションは webClientIdinitialize プラグインのメソッド。 Firebase Authentication Sign-in Method Web SDK Configuration Web Client ID
  11. アプリの Info.plist を変更する

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

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

      ソースとして開く Code オプションが表示される右クリックメニュー
    3. アプリの Plist ファイルの下部に、 </dict> タグ

      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. ステップ9でコピーしたiOS URLスキームの値に変更 YOUR_DOT_REVERSED_IOS_CLIENT_ID URLスキームに実際のリバースクライアントIDを挿入したInfo.plist

      注意
  12. を変更する YOUR_IOS_CLIENT_ID ステップ9でコピーしたiOS Client IDに変更する

  13. ファイルを保存する Command + S

  14. を変更する AppDelegate.swift

    1. XcodeプロジェクトナビゲータでAppDelegate.swiftファイルを開く

      AppDelegate.swiftファイルの先頭に
    2. GoogleSignIn importを追加したAppDelegate.swift import GoogleSignIn ファイルの先頭に

      GoogleSignIn importを追加したAppDelegate.swift
    3. ファイルを探す 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 __CAPGO_KEEP_0__のFirebase WebクライアントIDと一致する
  • Firebase ConsoleでGoogle Sign-Inが有効になっていることを確認する
  • Info.plistに正しいURLスキームとGIDClientIDが含まれていることを確認する
  • Verify iOSServerClientId __CAPGO_KEEP_0__のWebクライアントIDと一致する
  • 参考のために codeの例アプリを確認する 編集ページ