コンテンツにジャンプ

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.

古いパッケージを削除します:

移行ガイド
  1. Remove the old package:

    ターミナルウィンドウ
    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 の要件」

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

必要なのは、以下のことを実行することだけです。

  1. Google Cloud Console で Web クライアント ID を作成する必要があります (クレデンシャルを取得する方法)
  2. この Web クライアント ID をすべてのプラットフォームの " webClientId フィールドに使用します
  3. Android の場合、SHA1 と共に Android クライアント ID を作成する必要がありますが、このトークンは使用されません (Android の設定ガイド)
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
}
});
  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')
  • __CAPGO_KEEP_0__: 有効期限付きアクセストークンの詳細
  • : 認証用のIDトークン: メールアドレス、名前、画像URLを含むユーザープロファイル
  • 追加機能「追加機能」セクション

新しいパッケージでは、Google 以外の複数のソーシャル認証プロバイダをサポートしています:

Apple Sign-In

Facebook Login

統一されたアプローチにより、以下の機能が提供されます。

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

詳細なセットアップ手順については、 メインドキュメントを参照してください。 追加のプロバイダー用の詳細なセットアップ手順については、メインドキュメントを参照してください。