跳过内容

开始使用

GitHub

安装

安装

您可以使用我们的AI辅助设置来安装插件。使用以下命令将Capgo技能添加到您的AI工具中:

终端窗口
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
bunx cap sync
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';

API概述

API 简介

applyActionCode

应用ActionCode

Applies a verification code sent to the user by email.

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

confirmPasswordReset

确认密码重置

完成密码重置流程

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

confirmVerificationCode

确认验证码

完成手机验证码验证

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

createUserWithEmailAndPassword

创建用户

使用邮箱和密码创建新用户账户 如果新账户创建成功,用户会自动登录

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

删除用户并注销。

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

获取电子邮件地址的登录方式。

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

获取当前已登录用户。

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

返回 SignInResult 如果您的应用程序在后台启动了一个 web 登录流程,而操作系统在此期间清理了应用程序。

仅适用于 Android。

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

获取 Firebase Auth ID 令牌以识别当前已登录用户。

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

返回用于识别用户的 Firebase 服务的 JSON Web 令牌 (JWT)。

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

返回重定向式登录流程中的 SignInResult 结果

若登录失败,会以错误形式失败。 若未调用重定向操作,返回一个 SignInResult 若未调用重定向操作,返回一个

仅适用于 Web。

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

获取租户 ID。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getTenantId();
标题:isSignInWithEmailLink

检查是否为电子邮件链接的登录链接,适用于 signInWithEmailLink.

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

将用户帐户与 Apple 身份验证提供商关联。

用户必须在原生层上登录。 skipNativeAuth 此配置选项在这里无效。

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

将用户帐户与电子邮件身份验证提供者关联。

用户必须在原生层上登录。 skipNativeAuth 此配置选项在这里无效。

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

将用户帐户与电子邮件身份验证提供者关联。

用户必须在原生层上登录。 skipNativeAuth 此配置选项在这里无效。

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

将用户帐户与 Facebook 身份验证提供者关联。

用户必须在原生层上登录。 skipNativeAuth 此配置选项在此处无效。

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

将用户帐户与 Game Center 身份验证提供者关联。

用户必须在原生层上登录。 skipNativeAuth 此配置选项在此处无效。

仅适用于 iOS。

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

将用户帐户与 GitHub 身份验证提供者关联。

用户必须在原生层上登录。 skipNativeAuth 配置选项在此处无效。

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

将用户帐户与 Google 身份验证提供者关联。

用户必须在原生层上登录。 skipNativeAuth 配置选项在此处无效。

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

将用户帐户与 Microsoft 身份验证提供者关联。

用户必须在原生层上登录。 skipNativeAuth 此配置选项在这里无效。

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

将用户帐户与 OpenID Connect 提供商关联。

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

使用

用户必须在原生层上登录。 skipNativeAuth 此配置选项在这里无效。

使用 phoneVerificationCompleted 验证完成时的监听器 phoneVerificationFailed 监听验证失败时的事件回调。 使用 phoneCodeSent 获取验证 ID 的事件回调。

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

将用户帐户与Play Games身份验证提供者关联。

用户必须在原生层上登录。 此 skipNativeAuth 配置选项在此处无效。

仅适用于 Android。

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

将用户帐户与Twitter身份验证提供者关联。

用户必须在原生层上登录。 此 skipNativeAuth 此配置选项在此处无效。

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

将用户帐户与 Yahoo 身份验证提供者关联。

用户必须在原生层上登录。 skipNativeAuth 此配置选项在此处无效。

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

重新加载用户帐户数据,如果已登录。

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

撤销给定的访问令牌。目前仅支持 Apple OAuth 访问令牌。

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

sendEmailVerification

标题:发送验证邮件

向当前已登录用户发送验证邮件。

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

sendPasswordResetEmail

标题:发送密码重置邮件

向用户发送密码重置邮件。

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

向指定邮箱的用户发送登录邮件链接。

要完成使用邮箱链接登录,请调用 signInWithEmailLink 使用邮箱地址和邮箱链接(在发送给用户的邮件中提供)

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

用于身份验证操作的用户可见语言code。

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

设置当前保存的身份验证会话的持久性类型。

仅适用于Web。

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

设置租户ID。

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

作为匿名用户登录。

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

启动 Apple 登录流程。

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

启动自定义令牌登录流程。

此方法不能与 skipNativeAuth 在 Android 和 iOS 上使用。 在这种情况下,您必须使用 Firebase JS __CAPGO_KEEP_0__ 的接口。 signInWithCustomToken interface of the Firebase JS SDK directly.

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

标题:使用电子邮件和密码登录

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

使用电子邮件和登录电子邮件链接进行登录。

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

开始Facebook登录流程。

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

开始Game Center登录流程。

仅适用于iOS。

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

开始GitHub登录流程。

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

signInWithGoogle

signInWithGoogle

开始Google登录流程。

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

signInWithMicrosoft

signInWithMicrosoft

开始Microsoft登录流程。

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

signInWithOpenIdConnect

signInWithOpenIdConnect

开始OpenID Connect登录流程。

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

signInWithPhoneNumber

signInWithPhoneNumber

使用手机号码启动登录流程。

使用 phoneVerificationCompleted 监听器来接收验证完成的通知。 使用 phoneVerificationFailed 监听器来接收验证失败的通知。 使用 phoneCodeSent 监听器来获取验证 ID。

仅适用于 Android 和 iOS。

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

启动 Play Games 登录流程。

仅适用于 Android。

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

启动 Twitter 登录流程。

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

启动 Yahoo 登录流程。

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

启动注销流程。

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

从用户帐户中解除一个提供者。

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

更新当前已登录用户的电子邮件地址。

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

updatePassword

更新密码

更新用户资料

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

updateProfile

更新用户资料

更新用户资料

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

设置用户界面语言code为应用的默认语言。

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

为您的应用程序配置 Authentication 模拟器。

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

在更新当前已登录用户的电子邮件地址之前,验证新电子邮件地址。

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

checkAppTrackingTransparencyPermission

标题:“checkAppTrackingTransparencyPermission”

检查应用程序跟踪透明度的当前状态。

仅在 iOS 上可用。

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

requestAppTrackingTransparencyPermission

标题:“requestAppTrackingTransparencyPermission”

打开系统对话框以授权应用程序跟踪透明度。

注意: 用户可能在设备设置中禁用了跟踪请求,见 苹果的文档.

仅在 iOS 上可用

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

类型参考

类型参考

ApplyActionCodeOptions

执行代码操作选项
export interface ApplyActionCodeOptions {
/**
* A verification code sent to the user.
*
* @since 0.2.2
*/
oobCode: string;
}

ConfirmPasswordResetOptions

确认密码重置选项
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;
}

ConfirmVerificationCodeOptions

确认验证码选项
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;
}

SignInResult

SignInResult
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;
}

CreateUserWithEmailAndPasswordOptions

CreateUserWithEmailAndPasswordOptions
export interface CreateUserWithEmailAndPasswordOptions {
/**
* @since 0.2.2
*/
email: string;
/**
* @since 0.2.2
*/
password: string;
}

FetchSignInMethodsForEmailOptions

获取电子邮件登录方法选项
export interface FetchSignInMethodsForEmailOptions {
/**
* The user's email address.
*
* @since 6.0.0
*/
email: string;
}

FetchSignInMethodsForEmailResult

获取电子邮件登录方法结果
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[];
}

GetCurrentUserResult

GetCurrentUserResult
export interface GetCurrentUserResult {
/**
* The currently signed-in user, or null if there isn't any.
*
* @since 0.1.0
*/
user: User | null;
}

GetIdTokenOptions

获取 ID 令牌选项
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当公共 API 上游发生变化时,请重新同步。

如果您正在使用 入门 来规划身份验证和帐户流程,连接它与 在 @capgo/capacitor-social-login 中实现详细信息 在 @capgo/capacitor-social-login 中实现详细信息 在 @capgo/capacitor-passkey 中实现详细信息 在 @capgo/capacitor-passkey 中实现详细信息 @capgo/capacitor-native-生物识别 在 @capgo/capacitor-native-biometric 中实现详细信息 两因素身份验证 两因素身份验证的实现细节, SSO (企业) 了解 SSO (企业) 的实现细节。