コンテンツにジャンプ

Getting Started

  1. パッケージをインストールしてください

    ターミナルウィンドウ
    bun add @capgo/capacitor-social-login
  2. ネイティブプロジェクトと同期

    ターミナルウィンドウ
    bunx cap sync
  3. アプリ起動時に初期化

    import { SocialLogin } from '@capgo/capacitor-social-login';
    await SocialLogin.initialize({
    google: {
    webClientId: 'your-google-web-client-id',
    iOSServerClientId: 'your-google-server-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.mode: 'offline' ログインから返される。ログアウト、isLoggedIn、getAuthorizationCode、refreshは利用できません。 serverAuthCode ログインから返される。ログアウト、isLoggedIn、getAuthorizationCode、refreshは利用できません。

使用するには、バックエンドのトークン交換にのみ使用してください。アプリ内で呼び出す必要がある場合は、代わりに使用してください。 serverAuthCode 使用するには、バックエンドのトークン交換にのみ使用してください。アプリ内で呼び出す必要がある場合は、代わりに使用してください。 SocialLogin.refresh() Apple google.mode: 'online' 厳格なトークンハンドリングとAndroidの簡略化されたセットアップ用に設定します。

厳格なトークンハンドリングとAndroidの簡略化されたセットアップ用に設定します。

OAuth2 Webリダイレクトフロー

OAuth2 Webリダイレクトフロー useProperTokenExchange: true OAuth2 Webリダイレクトフロー useBroadcastChannel: true OAuth2 Webリダイレクトフロー

OAuth2 Webリダイレクトフロー

OAuth2 web redirect flowのセクション

ウェブフローでページから離れる場合に使用します。 OAuth2LoginOptions.flow: 'redirect' __CAPGO_KEEP_0__のプロバイダー設定

Capacitorのプロバイダー設定のセクション

Section titled “Provider configuration in Capacitor”

コピー

import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.example.app',
appName: 'My App',
webDir: 'dist',
plugins: {
SocialLogin: {
providers: {
google: true,
facebook: true,
apple: true,
twitter: false,
},
},
},
};
統合の概要