Google Authの移行を@capgo/social-login
このプラグインのインストール手順と全体のマークダウンガイドを含む設定プロンプトをコピーする
Overview
概要概要 @codetrix-studio/capacitor-google-auth to @capgo/capacitor-social-login, 安全でスムーズな移行を実現し、認証体験を向上させるために、新しいプラグインは複数のソーシャル認証プロバイダーを統合し、 API の下で一貫したものにします。
Installation
Section titled “インストール”-
古いパッケージを削除してください。
ターミナル画面 npm uninstall @codetrix-studio/capacitor-google-auth -
パッケージをインストールしてください。
ターミナル画面 npm install @capgo/capacitor-social-loginnpx cap sync
Google Auth の重要な変更
Section titled “Google Auth の重要な変更”Web Client ID の要件
Section titled “Web Client ID の要件”大幅な変更: Google Cloud ConsoleでWeb Client IDを更新します。
必要な手順は以下のとおりです。
- Google Cloud ConsoleでWeb Client IDを作成する必要があります。作成していない場合は(クレデンシャルを取得する方法)
- すべてのプラットフォームで使用するWeb Client IDを入力します。
webClientIdすべてのプラットフォームで使用するWeb Client IDを入力します。 - Androidの場合、SHA1と共にAndroid Client IDを作成する必要がありますが、このトークンは使用されません(Androidの設定ガイド)
Code 変更
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 }});プラットフォーム固有の変更
プラットフォーム固有の変更Android
Androidの設定ガイド- iOS
MainActivity.java(iOS):
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の設定ガイド-
iOSの設定ガイドiOSの設定ガイド)
-
設定をアップデートしてください
capacitor.config.json, 新しいプラグインでは使用していません:
{ "plugins": { "GoogleAuth": { "scopes": ["profile", "email"], "serverClientId": "xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com", "forceCodeForRefreshToken": true }}Web
Web- セクション「Web」
index.htmlGoogle Sign-Inのメタタグを削除してください
<meta name="google-signin-client_id" content="{your client id here}" /><meta name="google-signin-scope" content="profile email" />もし以前使用していました:
レスポンスタイプの変更セクション「レスポンスタイプの変更」
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') - access_token: 有効期限付きのアクセストークンの詳細
- IDトークン: 認証用のIDトークン
- プロファイル: メールアドレス、名前、画像URLなどユーザープロフィール情報
追加機能
「追加機能」セクション新しいパッケージではGoogle以外の複数のソーシャル認証プロバイダーをサポートしています:
この統一されたアプローチにより:
- すべてのプロバイダーで一貫したAPI
- TypeScriptのサポートが向上
- エラーハンドリングが改善
- アクティブなメンテナンスとコミュニティサポート
チェックする メインドキュメント Google Auth Migrationから@__CAPGO_KEEP_0__/social-loginに進む
セクションのタイトル:Google Auth Migrationから@capgo/social-loginに進む
Google Auth マイグレーションから @capgo/social-login まで続けるGoogle Auth のマイグレーションを使用 Google Auth マイグレーションを @capgo/social-login にマイグレーション Google Auth を使用して Google Auth を使用して @capgo/capacitor-social-login Google Auth を使用して @capgo/capacitor-social-login Google Auth を使用して @capgo/capacitor-social-login Google Auth を使用して @capgo/capacitor-passkey Google Auth を使用して @capgo/capacitor-passkey Google Auth を使用して @capgo/capacitor-native-biometric @capgo/capacitor-native-biometric for the implementation detail in @capgo/capacitor-native-biometric, and 2要素認証 2要素認証の実装詳細については