メニューに進む

Google Auth Migration to @capgo/social-login

@GitHub

このガイドでは、 @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.

  1. 古いパッケージを削除してください:

    ターミナル画面
    npm uninstall @codetrix-studio/capacitor-google-auth
  2. 新しいパッケージをインストールしてください:

    ターミナル画面
    npm install @capgo/capacitor-social-login
    npx cap sync

Google Auth の設定における重要な変更

「Google Auth の設定における重要な変更」のセクション

重要な変更: この更新されたプラグインでは、すべてのプラットフォームで Web クライアント ID を使用する必要があります。

必要な手順は次のとおりです。

  1. Google Cloud Console で Web クライアント ID を作成する必要があります。まだない場合は (クレデンシャルを取得する方法)
  2. すべてのプラットフォームでこの Web クライアント ID を使用します。 webClientId Android の場合、SHA1 と共に Android クライアント ID を作成する必要がありますが、このトークンは使用されません (
  3. Android の設定ガイド__CAPGO_KEEP_0__ の変更)

セクション "Code の変更"

Section titled “Code Changes”
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
}
});
  1. アップデートしてください 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() {}
}
  1. AppDelegate.swiftに大きな変更は必要ありません (iOS設定ガイド)

  2. 更新してください capacitor.config.json新しいプラグインでは使用していません:

{
"plugins": {
"GoogleAuth": {
"scopes": ["profile", "email"],
"serverClientId": "xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
"forceCodeForRefreshToken": true
}
}
  1. 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 まで続ける」

あなたが「@__CAPGO_KEEP_0__/social-login」で使用している場合 Google Auth マイグレーションを「@capgo/social-login」で使用して 認証とアカウントフローの計画に使用している場合、@__CAPGO_KEEP_0__/social-loginを接続してください 「@capgo/capacitor-social-login」を使用して 「@capgo/capacitor-social-login」でネイティブ機能を使用する場合 「@capgo/capacitor-social-login」で実装の詳細を使用する場合 「@capgo/capacitor-passkey」で 「@capgo/capacitor-passkey」で実装の詳細を使用する場合 「@capgo/capacitor-native-biometric」で 「@capgo/capacitor-native-biometric」で実装の詳細を使用する場合 for the implementation detail in @capgo/capacitor-native-biometric, and 2要素認証 2要素認証の実装詳細について