コンテンツにジャンプする

Ionic Auth Connect の移行から @capgo/capacitor-social-login まで

GitHub

概要

概要

Capgo Capgoのソーシャルログインは、Google、Apple、Facebook、他社のIDプロバイダー用に、プロバイダー固有のOAuth2フローでIonic Auth Connectを置き換えます。iOS、Android、Webで動作するため、複数のプロバイダーを1つのプラグインでサポートします。

なぜこれが機能するか

なぜこれが機能するか

プラグインには、Auth Connectの互換性のためのラッパーとして名付けられた SocialLoginAuthConnect です。このラッパーは、Ionic Auth ConnectのプロバイダーIDを、組み込みのOAuth2エンジンにマップします。これにより、名前として auth0, azure などを使用できます。 okta.

インストール

インストール
ターミナル
npm install @capgo/capacitor-social-login
npx cap sync
// Before
import { AuthConnect } from '@ionic-enterprise/auth-connect';
// After
import { SocialLoginAuthConnect } from '@capgo/capacitor-social-login';

使用する authConnect Capacitor Ionic Auth Connect が使用したプロバイダー ID の同じものが得られます:

await SocialLoginAuthConnect.initialize({
authConnect: {
auth0: {
domain: 'https://your-tenant.auth0.com',
clientId: 'your-auth0-client-id',
redirectUrl: 'myapp://oauth/auth0',
audience: 'https://your-api.example.com',
},
azure: {
tenantId: 'common',
clientId: 'your-azure-client-id',
redirectUrl: 'myapp://oauth/azure',
},
cognito: {
domain: 'https://your-domain.auth.region.amazoncognito.com',
clientId: 'your-cognito-client-id',
redirectUrl: 'myapp://oauth/cognito',
},
okta: {
issuer: 'https://dev-12345.okta.com/oauth2/default',
clientId: 'your-okta-client-id',
redirectUrl: 'myapp://oauth/okta',
},
onelogin: {
issuer: 'https://your-tenant.onelogin.com/oidc/2',
clientId: 'your-onelogin-client-id',
redirectUrl: 'myapp://oauth/onelogin',
},
},
});

サポートされているプロバイダー ID

「サポートされているプロバイダー ID」のセクション
  • auth0
  • azure
  • cognito
  • okta
  • onelogin

ログイン、ログアウト、トークン アクセス

「ログイン、ログアウト、トークン アクセス」のセクション
const result = await SocialLoginAuthConnect.login({
provider: 'auth0',
});
const status = await SocialLoginAuthConnect.isLoggedIn({
provider: 'auth0',
});
const code = await SocialLoginAuthConnect.getAuthorizationCode({
provider: 'auth0',
});
await SocialLoginAuthConnect.logout({
provider: 'auth0',
});

プロバイダ固有のプリセット例

「プロバイダ固有のプリセット例」セクション
await SocialLoginAuthConnect.initialize({
authConnect: {
auth0: {
domain: 'https://your-tenant.auth0.com',
clientId: 'your-auth0-client-id',
redirectUrl: 'myapp://oauth/auth0',
audience: 'https://your-api.example.com',
},
},
});
const auth0Result = await SocialLoginAuthConnect.login({
provider: 'auth0',
});
console.log(auth0Result.result.idToken);
await SocialLoginAuthConnect.initialize({
authConnect: {
azure: {
tenantId: 'common',
clientId: 'your-azure-client-id',
redirectUrl: 'myapp://oauth/azure',
},
},
});
const azureResult = await SocialLoginAuthConnect.login({
provider: 'azure',
});
console.log(azureResult.result.resourceData);
await SocialLoginAuthConnect.initialize({
authConnect: {
cognito: {
domain: 'https://your-domain.auth.region.amazoncognito.com',
clientId: 'your-cognito-client-id',
redirectUrl: 'myapp://oauth/cognito',
},
},
});
const cognitoResult = await SocialLoginAuthConnect.login({
provider: 'cognito',
});
console.log(cognitoResult.result.idToken);

Okta preset example

Okta preset example
await SocialLoginAuthConnect.initialize({
authConnect: {
okta: {
issuer: 'https://dev-12345.okta.com/oauth2/default',
clientId: 'your-okta-client-id',
redirectUrl: 'myapp://oauth/okta',
},
},
});
const oktaResult = await SocialLoginAuthConnect.login({
provider: 'okta',
});
console.log(oktaResult.result.resourceData);

OneLogin preset example

OneLogin preset example
await SocialLoginAuthConnect.initialize({
authConnect: {
onelogin: {
issuer: 'https://your-tenant.onelogin.com/oidc/2',
clientId: 'your-onelogin-client-id',
redirectUrl: 'myapp://oauth/onelogin',
},
},
});
const oneloginResult = await SocialLoginAuthConnect.login({
provider: 'onelogin',
});
console.log(oneloginResult.result.idToken);

または domain あなたのテナントがカスタムエンドポイントを使用している場合、直接オーバーライドしてください。 issuerコピー

await SocialLoginAuthConnect.initialize({
authConnect: {
onelogin: {
issuer: 'https://your-tenant.onelogin.com/oidc/2',
clientId: 'your-onelogin-client-id',
redirectUrl: 'myapp://oauth/onelogin',
authorizationBaseUrl: 'https://your-tenant.onelogin.com/oidc/2/auth',
accessTokenEndpoint: 'https://your-tenant.onelogin.com/oidc/2/token',
resourceUrl: 'https://your-tenant.onelogin.com/oidc/2/me',
logoutUrl: 'https://your-tenant.onelogin.com/oidc/2/logout',
},
},
});

プリセットを使用しない場合は、一般的な OAuth2 ドキュメントで同じプロバイダーを直接設定します:

  1. 互換性レイヤーは OAuth2 ベースです プロバイダー名は保持され、Ionic のネイティブ実装の詳細は削除されます。

  2. リフレッシュトークンはスコープに依存します リクエスト offline_access または、リフレッシュトークンが必要な場合にプロバイダー固有のエクイバレントを使用してください。

  3. カスタムエンドポイントはプリセットを上書きできます プリセットが近いが正確ではない場合、異なるエンドポイントのみをオーバーライドしてください。

  4. Direct oauth2 エントリが勝つ あなたが両方の定義をしている場合 authConnect.auth0 そして oauth2.auth0、直接 oauth2 configが優先されます。

Social Loginの導入

Ionic Auth Connectから@capgo/capacitor-social-loginに進む

セクション: Ionic Auth Connectから@capgo/capacitor-social-loginに進む

Ionic Auth Connectを使用している場合 Ionic Auth Connectから@capgo/capacitor-social-loginに進む 認証とアカウントフローの計画に使用している場合、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-social-loginと接続する @capgo/capacitor-social-loginを使用 @capgo/capacitor-social-loginのネイティブ機能 @capgo/capacitor-social-loginの実装詳細 @capgo/capacitor-passkey @capgo/capacitor-passkeyの実装詳細 Ionic Auth Connectから@capgo/capacitor-social-loginに進む @capgo/capacitor-native-biometric for the implementation detail in @capgo/capacitor-native-biometric, and 2要素認証 2要素認証の実装詳細について