メインコンテンツにジャンプ

Google Auth マイグレーションから @capgo/social-login まで

@GitHub

このガイドでは、からへの移行のための包括的なステップを提供し、改善された認証エクスペリエンスを保証します。新しいプラグインは、単一の統一された __CAPGO_KEEP_0__ の下で複数のソーシャル認証プロバイダーを統合します。 @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 の要件

Web クライアント ID の要件

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

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

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

セクション「Code Changes」

Section titled “Code Changes”

セクション「変更をインポート」

コピー
import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
import { SocialLogin } from '@capgo/capacitor-social-login';

__CAPGO_KEEP_0__

初期化セクション

設定は単純な呼び出しから構造化された呼び出しに変わります。 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
}
});
  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" />

クリップボードにコピー

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を含むユーザープロファイル情報

Additional Capabilities

追加機能

The new package supports multiple social authentication providers beyond Google:

この統合アプローチは次の利点を提供します:

  • 一貫した API をすべてのプロバイダーで使用
  • TypeScript のサポートが向上
  • エラー処理が改善
  • アクティブなメンテナンスとコミュニティサポート

詳細なセットアップ手順については、 メインドキュメント を参照してください。

Google Auth Migration から @capgo/social-login までの移行を続けてください

「Google Auth Migration から @capgo/social-login までの移行を続けてください」

Google Auth Migration から @__CAPGO_KEEP_0__/social-login を使用している場合 Google Auth Migration から @capgo/social-login を使用している場合 を計画し、認証とアカウントフローの接続を行うには @capgo/capacitor-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の実装詳細、 2要素認証 2要素認証の実装詳細