Google Login セットアップ
インストール手順とフルマークダウンガイドのセットアップ用質問をコピーします。
Capgo Social Loginの設定方法を学びます。このガイドでは、Capgo Social LoginとGoogleログインを設定する方法について説明します。
- Googleログインを設定するには、以下のものが必要です:
Googleアカウント
一般設定このステップは、どのプラットフォームを使用するかを決めることに関係なく、必須です。
- このセクションでは、Googleが表示するログイン画面を設定します。 Google Cloud Consoleにアクセスしてください。
- プロジェクトセレクターをクリックしてください。
- プロジェクトがなければ、 新しいプロジェクトを作成してください.
- Google Consoleで
New project
- 新しいプロジェクトの名前を入力して
Create
- プロジェクト名が正しく選択されていることを確認してください
- Google Consoleで
- Capgoの設定を始めます
OAuth consent screen-
検索バーをクリックしてください
-
検索して
OAuth consent screenクリックしてください
-
ConsentScreenの設定
クリックしてください
create
-
- アプリの情報を入力してください
-
始めましょう
App Information
- __CAPGO_KEEP_0__を入力してください
App Name - __CAPGO_KEEP_0__を入力してください
user support email
-
あなた __CAPGO_KEEP_0__ アプリロゴを追加してください。
-
あなた SHOULD configuring the
App domain
-
You HAVE TO provide the developer’s email
-
Click on
save and continue
- __CAPGO_KEEP_0__を入力してください
-
- Configure the scopes
-
Click on
add or remove scopes
-
Select the following scopes and click
update
-
クリック
save and continue
-
- テストユーザーを追加
- クリックしてください
add users
- Googleアカウントのメールアドレスを入力し、Enterキーを押してください
add
- テストユーザー画面の「保存して続行」ボタン
save and continue
- クリックしてください
- 完了ページの下部にある「ダッシュボードに戻る」ボタン
back to dashboard
- Submit your app for verification
Differences between online access and offline access
Section titled “Differences between online access and offline access”There are multiple ways to use Google Login with Capacitor. Here is a table that summarizes the differences between the two:
| Online access | Offline access | |
|---|---|---|
| Requires a backend | ❌ | ✅ |
| 長期アクセストークン | ❌ | ✅ |
| 簡単なセットアップ | ✅ | ❌ |
ユーザーがログインしたい場合、すぐにカスタムJWTを発行することになります。アプリはGoogle APIを呼びません。
-
この場合、オンラインアクセスを選択してください。
アプリがクライアントからGoogle APIを呼びますが、バックエンドから呼びません。
-
この場合、オンラインアクセスを選択してください。
アプリがバックエンドからGoogle APIを呼びますが、ユーザーがアプリを使用しているときに限ります。
-
この場合、オンラインアクセスを選択してください。
texts
-
あなたのアプリは、ユーザーがアプリを使用していなくても、定期的にユーザーのカレンダーをチェックします
この場合、オフラインアクセスを選択してください
オンラインアクセスの例
オンラインアクセスの例このチュートリアルのこの部分では、ユーザーをバックエンドで検証する方法を示します
この例は非常に単純で、以下の技術に基づいています
この例の code をここで見つけることができます ここ
ユーザーが見ることができます:
The idea is rather simple. You send a simple GET request to https://www.googleapis.com/oauth2/v3/tokeninfo and this returns you whether the token is valid or not and if it it is, it gives you the user's email. It also gives you some other info about the user token
From there, you could issue the user with your own JWT or issue some sort of session cookie. The possibilities are endless, for the final auth implementation.
If you do want to call Google API’s, I would strongly recommend looking at Google’s OAuth 2.0 Playground. From there you can easily see what APIs you can call.
__CAPGO_KEEP_0__
Using __CAPGO_KEEP_0__ with your own backendSection titled “__CAPGO_KEEP_0__ with your own backend”
- HTTPサーバー
この例では、以下の技術を使用して、オフラインアクセスを提供するアプリケーションを作成します。
-
LowDb (シンプルなデータベース)
この例のcodeは ここ
クライアントcodeは以下のようになります。
import { Capacitor } from '@capacitor/core';import { GoogleLoginOfflineResponse, SocialLogin } from '@capgo/capacitor-social-login';import { usePopoutStore } from '@/popoutStore'; // <-- specific to my app
const baseURL = "[redacted]";
async function fullLogin() { await SocialLogin.initialize({ google: { webClientId: '[redacted]', iOSClientId: '[redacted]', iOSServerClientId: 'The same value as webClientId', mode: 'offline' // <-- important } }) const response = await SocialLogin.login({ provider: 'google', options: { forceRefreshToken: true // <-- important } })
if (response.provider === 'google') { const result = response.result as GoogleLoginOfflineResponse const res = await fetch(`${baseURL}/auth/google_offline`, { headers: { "Content-Type": "application/json" }, body: JSON.stringify({ serverAuthCode: result.serverAuthCode, platform: Capacitor.getPlatform() }), method: "POST" })
if (res.status !== 200) { popoutStore.popout("Full google login failed", "check console"); return }
const { jwt } = await res.json(); const userinfo = await fetch(`${baseURL}/auth/get_google_user`, { headers: { Authorization: `Bearer ${jwt}` } }) if (userinfo.status !== 200) { popoutStore.popout("Full google (userinfo) login failed", "check console"); return } popoutStore.popout("userinfo res", await userinfo.text()); }}注意してください。アプリ内に呼び出しはありません。それは意図的にありません。Google オフラインモードでは、リフレッシュは、バックエンドがリフレッシュトークンを安全に保存するまで行われません。 SocialLogin.refresh() Google オフラインモードでは、リフレッシュは、バックエンドがリフレッシュトークンを安全に保存するまで行われません。 serverAuthCode Google ログイン設定から続けてください。
Google ログイン設定から続けてください。
Google ログイン設定を使用して、認証とアカウントフローの計画を行っている場合、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-social-loginに接続してください。Google ログイン設定を使用して、認証とアカウントフローの計画を行っている場合、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-social-loginに接続してください。 Using @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-social-login Using @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-social-login @capgo/capacitor-social-login @capgo/capacitor-social-login for the native capability in Using @capgo/capacitor-social-login for the implementation detail in @capgo/capacitor-social-login @capgo/capacitor-passkey @capgo/capacitor-passkeyの実装詳細について @capgo/capacitor-native-biometric @capgo/capacitor-native-biometricの実装詳細について、 2要素認証 2要素認証の実装詳細について