Google Auth Migration to @capgo/social-login
このプラグインのインストール手順と全マークダウンガイドを含む設定用の質問をコピーします。
このガイドでは、からへの移行を含め、Smooth Transition と Improved Authentication Experience を確実に実現するための、Comprehensive Steps を提供します。 @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.
古いパッケージを削除します:
移行ガイド-
Remove the old package:
ターミナルウィンドウ npm uninstall @codetrix-studio/capacitor-google-auth -
新しいパッケージをインストールする:
ターミナルウィンドウ npm install @capgo/capacitor-social-loginnpx cap sync
Google Auth の設定における重要な変更
「Google Auth の設定における重要な変更」Web クライアント ID の要件
「Web クライアント ID の要件」重要な変更: Web クライアント ID をすべてのプラットフォームで使用する必要があります。
必要なのは、以下のことを実行することだけです。
- Google Cloud Console で Web クライアント ID を作成する必要があります (クレデンシャルを取得する方法)
- この Web クライアント ID をすべてのプラットフォームの "
webClientIdフィールドに使用します - Android の場合、SHA1 と共に Android クライアント ID を作成する必要がありますが、このトークンは使用されません (Android の設定ガイド)
Code Changes
セクション "Code Changes"変更をインポートする
セクション "変更をインポートする"import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';import { SocialLogin } from '@capgo/capacitor-social-login';初期化
初期化セクション設定は単純な呼び出しから構造化された呼び出しに変わります。 GoogleAuth.initialize() Google の構成がネストされます。 SocialLogin.initialize() コピー
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 }});__CAPGO_KEEP_0__
プラットフォーム固有の変更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 }}- 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') - __CAPGO_KEEP_0__: 有効期限付きアクセストークンの詳細
- : 認証用のIDトークン: メールアドレス、名前、画像URLを含むユーザープロファイル
- 追加機能「追加機能」セクション
新しいパッケージでは、Google 以外の複数のソーシャル認証プロバイダをサポートしています:
Apple Sign-InFacebook Login
統一されたアプローチにより、以下の機能が提供されます。
- すべてのプロバイダーで API が一貫して実装されます。
- TypeScript のサポートが向上しました。
- エラー処理が改善されました。
- アクティブなメンテナンスとコミュニティサポートが提供されます。
詳細なセットアップ手順については、 メインドキュメントを参照してください。 追加のプロバイダー用の詳細なセットアップ手順については、メインドキュメントを参照してください。