Google認証のマイグレーションから@capgo/social-login
このプラグインのセットアッププロンプトをコピーします。
このガイドでは、 @codetrix-studio/capacitor-google-auth から @capgo/capacitor-social-login, ensuring a smooth transition and improved authentication experience. The new plugin unifies multiple social authentication providers under a single, consistent API.
インストール
「インストール」のセクション-
古いパッケージを削除してください:
ターミナル画面 npm uninstall @codetrix-studio/capacitor-google-auth -
新しいパッケージをインストールしてください:
ターミナル画面 npm install @capgo/capacitor-social-loginnpx cap sync
Google認証設定における重要な変更
「Google認証設定における重要な変更」のセクションWebクライアントIDの要件
「WebクライアントIDの要件」のセクション重要な変更: 最新のプラグインでは、すべてのプラットフォームでWebクライアントIDを使用する必要があります。
必要なのは
- Google Cloud ConsoleでWebクライアントIDを作成する必要があります。作成していない場合はクレデンシャルを取得する方法)
- すべてのプラットフォームで使用するWebクライアントIDを入力します。
webClientIdAndroidの場合、SHA1と共にAndroidクライアントIDを作成する必要がありますが、このIDはトークンを使用するためにのみ必要です ( - Androidの設定ガイド__CAPGO_KEEP_0__ Changes)
Code Changes
Section titled “Code Changes”pagePath
「変更をインポートする」セクションimport { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';import { SocialLogin } from '@capgo/capacitor-social-login';初期化
「初期化」セクション設定は単純な呼び出しから構造化された呼び出しに変わります。 GoogleAuth.initialize() 構造化された呼び出し SocialLogin.initialize() Googleの構成がネストされた構成になります:
GoogleAuth.initialize({ clientId: 'CLIENT_ID.apps.googleusercontent.com', scopes: ['profile', 'email'], grantOfflineAccess: true,});
await SocialLogin.initialize({ google: { webClientId: 'WEB_CLIENT_ID.apps.googleusercontent.com', // Use Web Client ID for all platforms iOSClientId: 'IOS_CLIENT_ID', // for iOS mode: 'offline' // replaces grantOfflineAccess }});サインイン
「サインイン」セクションログイン方法は GoogleAuth.signIn() に変わります SocialLogin.login() 明示的なプロバイダーの指定とともに:
const user = await GoogleAuth.signIn();const res = await SocialLogin.login({ provider: 'google', options: { scopes: ['email', 'profile'], forceRefreshToken: true // if you need refresh token }});プラットフォーム固有の変更
「プラットフォーム固有の変更」Android
「Android」- アップデート
MainActivity.java(Androidの完全なセットアップガイド):
import ee.forgr.capacitor.social.login.GoogleProvider; import ee.forgr.capacitor.social.login.SocialLoginPlugin; import ee.forgr.capacitor.social.login.ModifiedMainActivityForSocialLoginPlugin; import com.getcapacitor.PluginHandle; import com.getcapacitor.Plugin; import android.content.Intent; import android.util.Log;
public class MainActivity extends BridgeActivity { public class MainActivity extends BridgeActivity implements ModifiedMainActivityForSocialLoginPlugin {
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data);
if (requestCode >= GoogleProvider.REQUEST_AUTHORIZE_GOOGLE_MIN && requestCode < GoogleProvider.REQUEST_AUTHORIZE_GOOGLE_MAX) { PluginHandle pluginHandle = getBridge().getPlugin("SocialLogin"); if (pluginHandle == null) { Log.i("Google Activity Result", "SocialLogin login handle is null"); return; } Plugin plugin = pluginHandle.getInstance(); if (!(plugin instanceof SocialLoginPlugin)) { Log.i("Google Activity Result", "SocialLogin plugin instance is not SocialLoginPlugin"); return; } ((SocialLoginPlugin) plugin).handleGoogleLoginIntent(requestCode, data); } }
public void IHaveModifiedTheMainActivityForTheUseWithSocialLoginPlugin() {}}iOS
「iOS」-
AppDelegate.swift における大きな変更は必要ありません (iOS設定ガイド)
-
更新してください
capacitor.config.json新しいプラグインでは使用していません:
{ "plugins": { "GoogleAuth": { "scopes": ["profile", "email"], "serverClientId": "xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com", "forceCodeForRefreshToken": true }}Web
「Web」セクション- Google Sign-Inのメタタグを削除してください
index.html削除してください
<meta name="google-signin-client_id" content="{your client id here}" /><meta name="google-signin-scope" content="profile email" />応答タイプの変更
「応答タイプの変更」セクション認証応答は、プロバイダー情報、認可トークン、IDトークン、ユーザープロファイルデータを含む構造化されたオブジェクトを提供します:
interface GoogleLoginResponse { provider: 'google'; result: { accessToken: { token: string; expires: string; // ... other token fields } | null; idToken: string | null; profile: { email: string | null; familyName: string | null; givenName: string | null; id: string | null; name: string | null; imageUrl: string | null; }; };}レスポンス構造には次の要素があります:
- provider: 認証プロバイダーを識別します (
'google') - result.accessToken: 有効期限が切れるアクセストークンの詳細
- result.idToken: 認証用のIDトークン
- result.profile: メールアドレス、名前、画像URLなどユーザープロフィール情報
追加機能
「追加機能」セクション新しいパッケージでは、Google 以外の複数のソーシャル認証プロバイダーをサポートします:
統一されたアプローチにより、以下の利点が得られます:
- すべてのプロバイダーで API が一貫している
- TypeScript のサポートが向上
- エラー処理が改善
- アクティブなメンテナンスとコミュニティサポート
詳細なセットアップ手順については、 メインドキュメント を参照してください。
Google Auth Migration から @capgo/social-login に進みましょう
Google Auth マイグレーションから @capgo/social-login まで続けるあなたが使用している Google Auth マイグレーションから @capgo/social-login 認証とアカウントフローの計画に使用している場合、@__CAPGO_KEEP_0__/social-login に接続してください Using @capgo/capacitor-social-login のネイティブ機能のために 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 2要素認証 2要素認証の実装詳細について