跳过内容

Getting Started

终端窗口
bun add @capgo/capacitor-firebase-authentication
bunx cap sync
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';

Applies a verification code sent to the user by email.

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

完成密码重置流程

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

完成手机验证码验证流程

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

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

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 复制到剪贴板

仅适用于 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();

getTenantId

获取租户 ID

复制到剪贴板

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getTenantId();
复制到剪贴板

使用 Apple 身份验证提供者链接用户帐户。 signInWithEmailLink.

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

linkWithApple

复制到剪贴板

复制到剪贴板

复制到剪贴板 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);

linkWithFacebook

《linkWithFacebook》

将用户账户与Facebook认证提供者连接。

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

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

linkWithGameCenter

《linkWithGameCenter》

将用户账户与Game Center认证提供者连接。

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

仅适用于iOS。

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

linkWithGithub

《linkWithGithub》

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

用户必须在原生层上登录。 配置选项在这里无效. skipNativeAuth 复制到剪贴板

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

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

复制到剪贴板 skipNativeAuth 标题:linkWithMicrosoft

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

复制到剪贴板

标题:linkWithApple 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 __CAPGO_KEEP_0__

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

linkWithPlayGames

《linkWithPlayGames》

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

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

仅适用于Android。

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

linkWithTwitter

《linkWithTwitter》

将用户账户与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();

复制到剪贴板

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

发送验证码邮件

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

发送密码重置邮件

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

发送登录邮件链接

To complete sign in with the email link, call signInWithEmailLink with the email address and the email link supplied in the email sent to the user.

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);

signInAnonymously

标题:匿名登录

作为匿名用户登录。

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

signInWithApple

使用 Apple 登录

开始 Apple 登录流程

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

signInWithCustomToken

使用自定义令牌登录

开始自定义令牌登录流程

在 Android 和 iOS 上不能与此方法一起使用。 在这种情况下,您必须使用 Firebase JS __CAPGO_KEEP_0__ 的 skipNativeAuth 复制到剪贴板 signInWithCustomToken interface of the Firebase JS SDK directly.

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

signInWithEmailAndPassword

复制到剪贴板

Section titled “signInWithApple”

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

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

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

signInWithFacebook

signInWithFacebook标题

启动Facebook登录流程。

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

signInWithGameCenter

signInWithGameCenter标题

启动Game Center登录流程。

仅适用于iOS。

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

signInWithGithub

signInWithGithub标题

启动GitHub登录流程。

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

启动 Google 登录流程。

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

启动 Microsoft 登录流程。

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

启动 OpenID Connect 登录流程。

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

signInWithPhoneNumber

标题:使用手机号登录

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

使用 phoneVerificationCompleted listener 来接收验证完成的通知。 使用 phoneVerificationFailed listener 来接收验证失败的通知。 使用 phoneCodeSent listener 来获取验证 ID。 仅适用于 Android 和 iOS。 复制到剪贴板

signInWithPlayGames

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

signInWithPlayGames

signInWithTwitter

开始 Twitter 登录流程.

__CAPGO_KEEP_0__

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

signInWithTwitter

__CAPGO_KEEP_0__

__CAPGO_KEEP_0__

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);

更新用户资料。

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

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

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

为您的应用添加模拟器,以便与身份验证模拟器进行通信。

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

标题:检查应用程序跟踪透明度权限

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

仅在iOS上可用。

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

requestAppTrackingTransparencyPermission

标题:请求应用程序跟踪透明度权限

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

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

仅在iOS上可用。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.requestAppTrackingTransparencyPermission();
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;
}
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

标题:创建用户帐户密码选项
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;
}
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;
}

GetIdTokenResultResult

标题:获取 ID 令牌结果
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 上游发生变化时,请重新同步。

继续从 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 中的实现细节中 双因素身份验证 在双因素身份验证中实现细节,并 企业SSO 在企业SSO中实现细节。