コンテンツにジャンプ

iOS上のGoogleログイン

Social Login GitHub

このガイドでは、Capgo Social Login for iOSとGoogleログインをセットアップする方法を学びます。 既読の「一般的なセットアップガイド」を読んだことを前提としています。 一般的なセットアップガイド.

このセクションでは、iOSでGoogleログインを設定する方法を学びます。

  1. GoogleコンソールでiOSクライアントIDを作成する

    1. 検索バーをクリックする

      Googleコンソールの検索バー
    2. で検索する credentials と検索結果の APIs and Services 2番目のアイテム(スクリーンショットに示されている2番目)

      APIsとServicesが強調表示されているクレデンシャルオプションを示す検索結果
    3. をクリックする create credentials

      Googleコンソールのクレデンシャル作成ボタン
    4. を選択する OAuth client ID

      OAuthクライアントIDオプション
    5. Select the Application typeiOS

      アプリケーションタイプの選択画面でiOSオプションが強調表示されている
    6. Find the bundle ID

      1. Xcodeを開く

      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. Google Console から戻って、 Bundle Identifier に貼り付けます。 Bundle ID

        Bundle ID フィールドに Google Console iOS クライアント作成フォーム
    7. オプションで、App Store にアプリを公開した場合は、 App Store ID または Team ID に追加します。

    8. 詳細をすべて入力したら、iOS クライアント作成フォームの下部にある create

      ボタンをクリックします。
    9. クライアント ID 作成確認ダイアログの OK

      ボタンをクリックします。
    10. 新しく作成した iOS クライアントを開きます。

      新しく作成した iOS クライアントの資格情報リストに表示されます。
    11. __CAPGO_KEEP_0__をコピーしてください

      クライアントIDの詳細を表示して、クライアントIDとクライアントIDの逆順をコピーします
  2. アプリのInfo.plistを変更してください

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

      Xcodeプロジェクトナビゲータで表示されるInfo.plistファイル
    2. このファイルに右クリックしてソースとして開きます code

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

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

      Info.plistファイルのURLスキーム codeを閉じる辞書タグの前に挿入
      <key>CFBundleURLTypes</key>
      <array>
      <dict>
      <key>CFBundleURLSchemes</key>
      <array>
      <string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string>
      </array>
      </dict>
      </array>
    5. Change the YOUR_DOT_REVERSED_IOS_CLIENT_ID を前のステップでコピーした値に変更

      Info.plistに実際のリバースクライアントIDを挿入したURLスキームを設定
    6. ファイルを保存する Command + S

  3. 変更する AppDelegate.swift

    1. Xcodeプロジェクトナビゲータで

      AppDelegate.swiftファイルを開く
    2. Insert import GoogleSignIn at the top of the file

      AppDelegate.swiftにGoogleSignIn importを追加したファイルの先頭に挿入
    3. ファイルの中で func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) 関数

      AppDelegate.swiftのOriginal application 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を取り入れたModified application openURL関数
    5. ファイルを保存して Command + S

  4. JavaScript/TypeScriptのcodeでGoogleログインを設定

    1. Import SocialLoginCapacitor

      import { SocialLogin } from '@capgo/capacitor-social-login';
      import { Capacitor } from '@capacitor/core';
    2. 初期化メソッドを呼び出してください(これは、1度だけ呼び出してください)

      基本設定(オンラインモード - 最も多くのアプリケーション向けに推奨):

      // onMounted is Vue specific
      onMounted(() => {
      SocialLogin.initialize({
      google: {
      iOSClientId: '673324426943-redacted.apps.googleusercontent.com',
      mode: 'online' // Default mode
      }
      })
      })

      追加のクライアントIDを使用した高度な設定:

      onMounted(() => {
      SocialLogin.initialize({
      google: {
      webClientId: 'YOUR_WEB_CLIENT_ID', // Optional: for web platform support
      iOSClientId: 'YOUR_IOS_CLIENT_ID', // Required: from step 1
      iOSServerClientId: 'YOUR_WEB_CLIENT_ID', // Optional: same as webClientId, needed for some advanced features
      mode: 'online' // 'online' or 'offline'
      }
      })
      })
    3. Implement the login function. Create a button and run the following code on click

      クリップボードにコピー

      const res = await SocialLogin.login({
      provider: 'google',
      options: {}
      })
      // handle the response - contains user data
      console.log(JSON.stringify(res))

      For offline mode:

      const res = await SocialLogin.login({
      provider: 'google',
      options: {
      forceRefreshToken: true // Recommended for offline mode
      }
      })
      // res contains serverAuthCode, not user data
      // Send serverAuthCode to your backend to get user information
      // Do not call SocialLogin.refresh() in offline mode
      console.log('Server auth code:', res.result.serverAuthCode)
  5. アプリケーションをテスト

    1. アプリをビルドして実行 cap sync

    2. すべてが正しく行われたら、Google ログインフローが正常に動作するはずです

      iOS 上の Google ログインフロー DEMO、サインインプロセスと成功した認証を示しています

既知の問題

「既知の問題」

プライバシースクリーン プラグインの不互換性

「プライバシースクリーン プラグインの不互換性」

Google Login プラグインは @capacitor/プライバシースクリーンで互換性がありません。

両方のプラグインを同時に使用する場合、プライバシースクリーンがGoogleログインのウェブビューを中断します。 対処法: await PrivacyScreen.disable(); を呼び出す前に

import { PrivacyScreen } from '@capacitor/privacy-screen';
import { SocialLogin } from '@capgo/capacitor-social-login';
await PrivacyScreen.disable();
await SocialLogin.login({
provider: 'google',
options: {}
});

セクションのタイトル “iOS上のGoogleログインから続けて” iOS上で Googleログインを使用していて、認証とアカウントフローの計画を行いたい場合は、 @capgo/capacitor-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 Two-factor authentication Edit page