メニューに進む

Google Login on Web

GitHub

このガイドでは、GoogleログインとCapgoのWebアプリケーション用のソーシャルログインを設定する方法を学びます。 既に一般的な設定ガイドを読んだと想定しています。 Web上でのGoogleログインの使用.

Web上でのGoogleログインの使用は比較的簡単です。 使用するには、以下の手順を実行する必要があります。

GoogleコンソールでWebクライアントを作成する

__CAPGO_KEEP_0__のインストール、同期、およびソースマークダウンガイドを含みます。

  1. Using Google login on the web is rather simple. In order to use it, you have to do the following:__CAPGO_KEEP_0__

    1. Click on the search bar

      Google Console search bar
    2. Search for credentials and click on the APIs and Services option (number 2 on the screenshot)

      Search results showing credentials option with APIs and Services highlighted
    3. Click on the create credentials

      Create credentials button in Google Console
    4. Select OAuth client ID

      OAuthクライアントIDオプションの作成メニューの資格情報
    5. Select the Application type as Web application

      アプリケーションタイプの選択画面のWebオプションが強調表示されている
    6. Name your client and click Create

      Webクライアント作成フォームの名前フィールドが強調表示されている
    7. Copy the client ID, you’ll use this as the webClientId in your application

      Client IDの詳細画面のWebクライアントIDをコピーする
  2. Configure the web client in the Google Console

    1. Please open the 資格情報ページ とWebクライアントをクリックしてください

      Webクライアントを表示する資格情報リスト
    2. ここで、 Authorized JavaScript originsあなたのアプリで使用する可能性のあるすべてのアドレスを含むように追加してください。私の場合は、localhostのみを使用しますが、カスタムポートを使用しているため、両方を追加する必要があります。 ONLY そして http://localhost をクリックしてください http://localhost:5173

      1. Authorized JavaScript originsセクションのADD URIボタン add URI

        URLを入力してください
      2. localhostのURLが入力されたADD URIダイアログ

        すべてのURLを追加するまで繰り返してください
      3. Please repeat until you added all the URLs

      4. 完成したら、画面はこのようになります

        __CAPGO_KEEP_0__
    3. ここで、以下のいずれかを追加してください Authorized redirect URIsCapacitorSocialLogin プラグインを使用するページによって異なりますが、私の場合は http://localhost:5173/auth

      1. ここをクリックしてください ADD URI

        __CAPGO_KEEP_0__
      2. ADD URI ボタンをクリックしてください ADD URL URL を入力して、

        再び
    4. ADD URI ダイアログにリダイレクト URL を入力 save

      クリックしてください
  3. 下部の Web クライアント設定の "保存" ボタンをクリックしてください login from JavaScript like so:

    1. First, import SocialLogin

      import { SocialLogin } from '@capgo/capacitor-social-login';
    2. Then, call initialize. This should be called ONLY once.

      // onMounted is Vue specific
      // webClientId is the client ID you got in the web client creation step not the android client ID.
      onMounted(() => {
      SocialLogin.initialize({
      google: {
      webClientId: '673324426943-avl4v9ubdas7a0u7igf7in03pdj1dkmg.apps.googleusercontent.com',
      }
      })
      })
    1. ログインボタンを作成して SocialLogin.login をクリックしたときに

      const res = await SocialLogin.login({
      provider: 'google',
      options: {}
      })
      // Handle the response
      console.log(JSON.stringify(res));

If you are using Google Login on Web to plan authentication and account flows, connect it with 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 Two-factor authentication 2要素認証の実装詳細について。