メインコンテンツへスキップ

スタートガイド

GitHub

AIアシストによるセットアップでプラグインをインストールできます。以下のコマンドを使用して、お使いのAIツールに Capgo のスキルを追加してください:

ターミナル
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次に、以下のプロンプトを使用します:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-firebase-authentication` plugin in my project.

手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:

ターミナル
bun add @capgo/capacitor-firebase-authentication
npx cap sync
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.applyActionCode({ oobCode: 'oob-code' });
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.confirmPasswordReset({
oobCode: 'oob-code',
newPassword: 'new-password',
});
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.confirmVerificationCode({
verificationId: 'phoneCodeSent',
verificationCode: 'phoneCodeSent',
});
// The result holds sensitive values: use it without logging it.
  • リスナー: 画面がアンマウントされたらハンドルを削除します。
  • ネイティブ同期: 実行 npx cap sync プラグインのアップグレード後。
  • 信頼できる情報源: 信頼 src/definitions.ts GitHub リポジトリ内。

メールでユーザーに送信された検証用 code を適用します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.applyActionCode({ oobCode: 'oob-code' });

パスワードリセット処理を完了します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.confirmPasswordReset({
oobCode: 'oob-code',
newPassword: 'new-password',
});

電話番号の検証プロセスを完了します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.confirmVerificationCode({
verificationId: 'phoneCodeSent',
verificationCode: 'phoneCodeSent',
});
// The result holds sensitive values: use it without logging it.

メールアドレスとパスワードを使用して、新しいユーザーアカウントを作成します。 アカウントの作成に成功すると、ユーザーは自動的にサインインされます。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.createUserWithEmailAndPassword({
email: 'user@example.com',
password: 'password',
});
// The result holds sensitive values: use it without logging it.

ユーザーを削除してサインアウトします。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.deleteUser();

指定したメールアドレスのサインイン方法を取得します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.fetchSignInMethodsForEmail({ email: 'user@example.com' });
console.log(result);

現在サインインしているユーザーを取得します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.getCurrentUser();
// The result holds sensitive values: use it without logging it.

リダイレクトによるサインインフローから SignInResult アプリがWebサインインフローを開始し、バックグラウンド中にOSがアプリを終了した場合。

Android でのみ利用可能です。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.getPendingAuthResult();
// The result holds sensitive values: use it without logging it.

現在サインインしているユーザーの Firebase Auth ID Token を取得します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.getIdToken();
// The result holds sensitive values: use it without logging it.

Firebase サービスでユーザーを識別するために使用される、デシリアライズされた JSON Web Token (JWT) を返します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.getIdTokenResult();
// The result holds sensitive values: use it without logging it.

リダイレクトによるサインインフローから SignInResult を返します。

サインインに失敗した場合は、エラーが発生します。 リダイレクト操作が呼び出されていない場合は、 SignInResult null ユーザーの場合。

Webのみ利用可能です。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.getRedirectResult();
// The result holds sensitive values: use it without logging it.

テナントIDを取得します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.getTenantId();
console.log(result);

受信リンクが、以下の用途に適したメールリンクによるサインインかどうかを確認します。 signInWithEmailLink.

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.isSignInWithEmailLink({ emailLink: 'https://example.com' });
// The result holds sensitive values: use it without logging it.

ユーザーアカウントをApple認証プロバイダーに連携します。

ユーザーはネイティブレイヤーでログインしている必要があります。 The skipNativeAuth この設定オプションはここでは効果がありません。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithApple();
// The result holds sensitive values: use it without logging it.

ユーザーアカウントをEmail認証プロバイダーに連携します。

ユーザーはネイティブレイヤーでログインしている必要があります。 The skipNativeAuth この設定オプションはここでは効果がありません。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithEmailAndPassword({
email: 'user@example.com',
password: 'password',
});
// The result holds sensitive values: use it without logging it.

ユーザーアカウントをEmail認証プロバイダーに連携します。

ユーザーはネイティブレイヤーでログインしている必要があります。 The skipNativeAuth この設定オプションはここでは効果がありません。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithEmailLink({
email: 'user@example.com',
emailLink: 'https://example.com',
});
// The result holds sensitive values: use it without logging it.

ユーザーアカウントをFacebook認証プロバイダーに連携します。

ユーザーはネイティブレイヤーでログインしている必要があります。 The skipNativeAuth この設定オプションはここでは効果がありません。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithFacebook();
// The result holds sensitive values: use it without logging it.

ユーザーアカウントを Game Center 認証プロバイダーにリンクします。

ユーザーはネイティブレイヤーでログインしている必要があります。 The skipNativeAuth この設定オプションはここでは効果がありません。

iOS でのみ利用できます。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithGameCenter();
// The result holds sensitive values: use it without logging it.

ユーザーアカウントを GitHub 認証プロバイダーにリンクします。

ユーザーはネイティブレイヤーでログインしている必要があります。 The skipNativeAuth この設定オプションはここでは効果がありません。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithGithub();
// The result holds sensitive values: use it without logging it.

ユーザーアカウントを Google 認証プロバイダーにリンクします。

ユーザーはネイティブレイヤーでログインしている必要があります。 The skipNativeAuth この設定オプションはここでは効果がありません。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithGoogle();
// The result holds sensitive values: use it without logging it.

ユーザーアカウントを Microsoft 認証プロバイダーにリンクします。

ユーザーはネイティブレイヤーでログインしている必要があります。 The skipNativeAuth この設定オプションはここでは効果がありません。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithMicrosoft();
// The result holds sensitive values: use it without logging it.

ユーザーアカウントを OpenID Connect プロバイダーにリンクします。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithOpenIdConnect({ providerId: 'provider-id-123' });
// The result holds sensitive values: use it without logging it.

ユーザーアカウントを電話番号認証プロバイダーにリンクします。

ユーザーはネイティブレイヤーでログインしている必要があります。 The skipNativeAuth この設定オプションはここでは効果がありません。

以下の phoneVerificationCompleted 検証が完了したときに通知される listener。 使用するには phoneVerificationFailed 検証が失敗したときに通知を受け取るためのリスナー。 使用するには phoneCodeSent 検証IDを取得するためのリスナー。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithPhoneNumber({ phoneNumber: "+16505550101" });

ユーザーアカウントを Play Games 認証プロバイダーにリンクします。

ユーザーはネイティブレイヤーでログインしている必要があります。 The skipNativeAuth この設定オプションはここでは効果がありません。

Android でのみ利用可能です。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithPlayGames();
// The result holds sensitive values: use it without logging it.

ユーザーアカウントを Twitter 認証プロバイダーにリンクします。

ユーザーはネイティブレイヤーでログインしている必要があります。 The skipNativeAuth この設定オプションはここでは効果がありません。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithTwitter();
// The result holds sensitive values: use it without logging it.

ユーザーアカウントを Yahoo 認証プロバイダーにリンクします。

ユーザーはネイティブレイヤーでログインしている必要があります。 The skipNativeAuth この設定オプションはここでは効果がありません。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithYahoo();
// The result holds sensitive values: use it without logging it.

サインイン済みの場合、ユーザーアカウントのデータをリロードします。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.reload();

指定されたアクセストークンを無効化します。現在は Apple OAuth アクセストークンのみをサポートしています。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.revokeAccessToken({ token: 'token-123' });

現在サインインしているユーザーに認証メールを送信します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.sendEmailVerification();

パスワードリセットメールを送信します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.sendPasswordResetEmail({ email: 'user@example.com' });

指定したメールアドレスのユーザーに、サインイン用メールリンクを送信します。

メールリンクでのサインインを完了するには、次を呼び出します: signInWithEmailLink ユーザーに送信されたメールに含まれるメールアドレスとメールリンクを引数に渡します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.sendSignInLinkToEmail({
email: 'user@example.com',
actionCodeSettings: { url: 'https://example.com' },
});

認証操作のユーザー向け言語 code を設定します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.setLanguageCode({ languageCode: "en-US" });

現在保存されている認証セッションの永続化タイプを設定します。

Webのみ利用可能です。

import { FirebaseAuthentication, Persistence } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.setPersistence({ persistence: Persistence.IndexedDbLocal });

テナント ID を設定します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.setTenantId({ tenantId: 'tenant-id-123' });

匿名ユーザーとしてサインインします。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInAnonymously();
// The result holds sensitive values: use it without logging it.

Apple サインインフローを開始します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithApple();
// The result holds sensitive values: use it without logging it.

Custom Token のサインインフローを開始します。

このメソッドは以下と組み合わせて使用できません skipNativeAuth Android および iOS では。 この場合、 signInWithCustomToken Firebase JS の SDK インターフェースを直接使用する必要があります。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithCustomToken({ token: 'token-123' });
// The result holds sensitive values: use it without logging it.

メールアドレスとパスワードを使用してサインインフローを開始します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithEmailAndPassword({
email: 'user@example.com',
password: 'password',
});
// The result holds sensitive values: use it without logging it.

メールアドレスとサインイン用メールリンクを使用してサインインします。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithEmailLink({
email: 'user@example.com',
emailLink: 'https://example.com',
});
// The result holds sensitive values: use it without logging it.

Facebook のサインインフローを開始します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithFacebook();
// The result holds sensitive values: use it without logging it.

Game Center のサインインフローを開始します。

iOS でのみ利用できます。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithGameCenter();
// The result holds sensitive values: use it without logging it.

GitHub のサインインフローを開始します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithGithub();
// The result holds sensitive values: use it without logging it.

Google のサインインフローを開始します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithGoogle();
// The result holds sensitive values: use it without logging it.

Microsoft のサインインフローを開始します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithMicrosoft();
// The result holds sensitive values: use it without logging it.

OpenID Connect のサインインフローを開始します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithOpenIdConnect({ providerId: 'provider-id-123' });
// The result holds sensitive values: use it without logging it.

電話番号を使用してサインインフローを開始します。

以下の phoneVerificationCompleted 検証が完了したときに通知されるリスナー。 使用するには phoneVerificationFailed 検証が失敗したときに通知されるリスナー。 使用するには phoneCodeSent 検証 ID を取得するためのリスナー。

Android と iOS でのみ利用できます。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithPhoneNumber({ phoneNumber: "+16505550101" });

Play Games のサインインフローを開始します。

Android でのみ利用可能です。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithPlayGames();
// The result holds sensitive values: use it without logging it.

Twitterのサインインフローを開始します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithTwitter();
// The result holds sensitive values: use it without logging it.

Yahooのサインインフローを開始します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithYahoo();
// The result holds sensitive values: use it without logging it.

サインアウトフローを開始します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signOut();

ユーザーアカウントからプロバイダーのリンクを解除します。

import { FirebaseAuthentication, ProviderId } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.unlink({ providerId: ProviderId.APPLE });
// The result holds sensitive values: use it without logging it.

現在サインインしているユーザーのメールアドレスを更新します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.updateEmail({ newEmail: 'user@example.com' });

現在サインインしているユーザーのパスワードを更新します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.updatePassword({ newPassword: 'new-password' });

ユーザーのプロファイルデータを更新します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.updateProfile({
displayName: 'display',
photoUrl: 'https://example.com',
});

ユーザー向けの言語 code をアプリのデフォルト言語として設定します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.useAppLanguage();

Authentication エミュレータと通信できるようにアプリを設定します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.useEmulator({ host: "127.0.0.1" });

現在サインインしているユーザーのメールアドレスを更新する前に、新しいメールアドレスを検証します。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.verifyBeforeUpdateEmail({ newEmail: 'user@example.com' });

App Tracking Transparency の現在のステータスを確認します。

iOSでのみ利用可能です。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.checkAppTrackingTransparencyPermission();
console.log(result);

App Tracking Transparency の許可を求めるシステムダイアログを表示します。

注意: ユーザーがデバイスの設定でトラッキング要求を無効にしている可能性があります。詳細は Appleのドキュメント.

iOSでのみ利用可能です。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.requestAppTrackingTransparencyPermission();
console.log(result);
export interface ApplyActionCodeOptions {
/**
* A verification code sent to the user.
*
* @since 0.2.2
*/
oobCode: string;
}
export interface ConfirmPasswordResetOptions {
/**
* A verification code sent to the user.
*
* @since 0.2.2
*/
oobCode: string;
/**
* The new password.
*
* @since 0.2.2
*/
newPassword: string;
}
export interface ConfirmVerificationCodeOptions {
/**
* The verification ID received from the `phoneCodeSent` listener.
*
* The `verificationCode` option must also be provided.
*
* @since 5.0.0
*/
verificationId: string;
/**
* The verification code either received from the `phoneCodeSent` listener or entered by the user.
*
* The `verificationId` option must also be provided.
*
* @since 5.0.0
*/
verificationCode: string;
}
export interface SignInResult {
/**
* The currently signed-in user, or null if there isn't any.
*
* @since 0.1.0
*/
user: User | null;
/**
* Credentials returned by an auth provider.
*
* @since 0.1.0
*/
credential: AuthCredential | null;
/**
* Additional user information from a federated identity provider.
*
* @since 0.5.1
*/
additionalUserInfo: AdditionalUserInfo | null;
}
export interface CreateUserWithEmailAndPasswordOptions {
/**
* @since 0.2.2
*/
email: string;
/**
* @since 0.2.2
*/
password: string;
}
export interface FetchSignInMethodsForEmailOptions {
/**
* The user's email address.
*
* @since 6.0.0
*/
email: string;
}
export interface FetchSignInMethodsForEmailResult {
/**
* The sign-in methods for the specified email address.
*
* This list is empty when [Email Enumeration Protection](https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection)
* is enabled, irrespective of the number of authentication methods available for the given email.
*
* @since 6.0.0
*/
signInMethods: string[];
}
export interface GetCurrentUserResult {
/**
* The currently signed-in user, or null if there isn't any.
*
* @since 0.1.0
*/
user: User | null;
}
export interface GetIdTokenOptions {
/**
* Force refresh regardless of token expiration.
*
* @since 0.1.0
*/
forceRefresh: boolean;
}
export interface GetIdTokenResult {
/**
* The Firebase Auth ID token JWT string.
*
* @since 0.1.0
*/
token: string;
}
export interface GetIdTokenResultOptions {
/**
* Force refresh regardless of token expiration.
*
* @since 7.4.0
*/
forceRefresh: boolean;
}
export interface GetIdTokenResultResult {
/**
* The authentication time in milliseconds since the epoch.
*
* This is the time the user authenticated (signed in) and not the time the token was refreshed.
*
* @since 7.4.0
*/
authTime: number;
/**
* The ID token expiration time in milliseconds since the epoch.
*
* @since 7.4.0
*/
expirationTime: number;
/**
* The ID token issuance time in milliseconds since the epoch.
*
* @since 7.4.0
*/
issuedAtTime: number;
/**
* The sign-in provider through which the ID token was obtained.
*
* @since 7.4.0
*/
signInProvider: string | null;
/**
* The type of second factor associated with this session, provided the user was multi-factor
* authenticated (eg. phone, etc).
*
* @since 7.4.0
*/
signInSecondFactor: string | null;
/**
* The entire payload claims of the ID token including the standard reserved claims as well as
* the custom claims.
*
* @since 7.4.0
*/
claims: Record<string, unknown>;
}

このページはプラグインの src/definitions.tsから生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。

Getting Startedの続きを進める

「Getting Started からの続き」セクション

使用している場合 スタートガイド 認証とアカウントフローを計画するには、これを次と連携させてください @capgo/capacitor-social-login @capgo/capacitor-social-login の実装の詳細については、 @capgo/capacitor-passkey @capgo/capacitor-passkey の実装詳細については、 @capgo/capacitor-native-biometric @capgo/capacitor-native-biometric の実装の詳細については、 2要素認証 二要素認証の実装の詳細については、また、 SSO (エンタープライズ) SSO (Enterprise) の実装の詳細については。