はじめに
インストール
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-social-login`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/social-login/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
「インストール」のセクションAI-Assisted Setupを使用してプラグインをインストールできます。AIツールにCapgoスキルを追加するには、以下のコマンドを実行してください。
npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins次に、以下のプロンプトを使用してください。
Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-social-login` plugin in my project.Manual Setupを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。
-
パッケージのインストール
ターミナル画面 npm install @capgo/capacitor-social-login -
ネイティブプロジェクトと同期
ターミナル画面 npx cap sync -
アプリ起動時に初期化
import { SocialLogin } from '@capgo/capacitor-social-login';await SocialLogin.initialize({google: {webClientId: 'your-google-web-client-id',iOSClientId: 'your-google-ios-client-id',iOSServerClientId: 'your-google-web-client-id',mode: 'online',},apple: {clientId: 'your-apple-service-id',useProperTokenExchange: true,useBroadcastChannel: true,},facebook: {appId: 'your-facebook-app-id',},twitter: {clientId: 'your-twitter-client-id',redirectUrl: 'myapp://oauth/twitter',},oauth2: {github: {appId: 'your-github-client-id',authorizationBaseUrl: 'https://github.com/login/oauth/authorize',accessTokenEndpoint: 'https://github.com/login/oauth/access_token',redirectUrl: 'myapp://oauth/github',scope: 'read:user user:email',pkceEnabled: true,},},});
コアフロー例
コアフロー例ログイン
ログインawait SocialLogin.login({ provider: 'google', options: { scopes: ['profile', 'email'] },});
await SocialLogin.login({ provider: 'oauth2', options: { providerId: 'github', scope: 'read:user user:email', },});セッションの確認
セクション「セッションの確認」const status = await SocialLogin.isLoggedIn({ provider: 'google' });await SocialLogin.logout({ provider: 'google' });認証コードとリフレッシュ
セクション「認証コードとリフレッシュ」// For providers that support this modeconst authCodeResult = await SocialLogin.getAuthorizationCode({ provider: 'google' });await SocialLogin.refresh({ provider: 'google', options: {} as never });高度なヘルパー
セクション「高度なヘルパー」const jwt = await SocialLogin.decodeIdToken({ idToken: 'eyJhbGciOi...',});
const { date } = await SocialLogin.getAccessTokenExpirationDate({ accessTokenExpirationDate: Date.now() + 3600 * 1000,});
const expired = await SocialLogin.isAccessTokenExpired({ accessTokenExpirationDate: Date.now() + 1000,});
const active = await SocialLogin.isRefreshTokenAvailable({ refreshToken: 'a-token' });プロバイダー固有の注記
セクション「プロバイダー固有の注記」Google オフラインモード
Google オフラインモードgoogle.mode: 'offline' returns serverAuthCode ログインから。 このモードではログアウト、isLoggedIn、getAuthorizationCode、およびrefreshは利用できません。
使用 serverAuthCode あなたのバックエンドのトークン交換にのみ使用してください。 アプリ内で呼び出す必要がある場合は代わりに SocialLogin.refresh() を使用してください。 google.mode: 'online' Apple
for strict token handling and useProperTokenExchange: true for Android simplified setup useBroadcastChannel: true Set
OAuth2 Web リダイレクト フロー
セクション「OAuth2 Web リダイレクト フロー」使用 OAuth2LoginOptions.flow: 'redirect' ページから離れるWebフロー向け
動的プロバイダー依存関係
セクション「動的プロバイダー依存関係」必要なプロバイダーを選択して、ネイティブアプリのサイズを削減できます。この機能は、特定のプロバイダーしか必要としないアプリでは最も便利です。
プロバイダー設定を追加 capacitor.config.ts:
import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = { appId: 'com.example.app', appName: 'MyApp', webDir: 'dist', plugins: { SocialLogin: { providers: { google: true, facebook: true, apple: true, twitter: false, }, logLevel: 1, }, },};
export default config;プロバイダー値の意味は次のとおりです。
true: 有効なプロバイダーであり、ネイティブ依存関係がバンドルされています。false: 無効なプロバイダーであり、ネイティブ依存関係がバンドルされていません。
重要な詳細:
- 実行
npx cap syncプロバイダーの設定を変更した後 - プロバイダーの設定が提供されない場合は、すべてのプロバイダーは
trueバックアップ互換性のために - プロバイダーを無効にする
falseプロバイダーを無効にする - システムAPIのみを使用するプロバイダーでも、実行時には利用できません。
- Apple Sign-In on Android uses OAuth without external SDK dependencies.
- Twitter/X uses standard OAuth 2.0 without external SDK dependencies.
依存関係なしでOAuthを使用します。
plugins: { SocialLogin: { providers: { google: true, facebook: false, apple: true, twitter: false, }, },}関連ドキュメント
関連ドキュメント- 統合の概要
- Better Auth統合
- OAuth2およびOIDCプロバイダー
- トラブルシューティング
- プライバシーマニフェストとiOS URLハンドラー
- Ionic Auth Connectから移行する
- Social Login Auth Connectの移行ガイド
- 古いプロバイダーから移行する
- Ionic Enterpriseプラグインの移行ソリューション
続けてGetting Startedから
「始めから始める」から続けて進むあなたが「始めから始める」を使用している場合 「始めから始める」 認証とアカウントフローの計画に使用している場合、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-social-loginを接続してください 「@capgo/capacitor-social-login」で使用するnative capability 「@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要素認証の実装詳細について