__CAPGO_KEEP_0__

はじめに

GitHub

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を使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。

  1. パッケージのインストール

    ターミナル画面
    npm install @capgo/capacitor-social-login
  2. ネイティブプロジェクトと同期

    ターミナル画面
    npx cap sync
  3. アプリ起動時に初期化

    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 mode
const 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

使用 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,
},
},
}
関連ドキュメント

あなたが「始めから始める」を使用している場合 「始めから始める」 認証とアカウントフローの計画に使用している場合、@__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要素認証の実装詳細について