定義與使用者相關的多因素相關屬性和操作的介面。
簽名:
export interface MultiFactorUser
特性
財產 | 類型 | 描述 |
---|---|---|
登記因素 | 多因素資訊[] | 傳回用戶註冊的第二因素的清單。 |
方法
方法 | 描述 |
---|---|
註冊(斷言,顯示名稱) | 註冊由使用者的MultiFactorAssertion標識的第二個因素。 |
獲取會話() | 傳回第二因素註冊操作的會話標識符。這用於識別嘗試註冊第二個因素的用戶。 |
取消註冊(選項) | 取消註冊指定的第二個因素。 |
MultiFactorUser.enrolledFactors
傳回用戶註冊的第二因素的清單。
簽名:
readonly enrolledFactors: MultiFactorInfo[];
MultiFactorUser.enroll()
註冊由使用者的MultiFactorAssertion標識的第二個因素。
解析時,使用者令牌將更新以反映 JWT 負載中的變更。接受用於向最終使用者標識第二個因素的附加顯示名稱參數。此操作需要最近重新進行身份驗證才能成功。成功註冊後,現有 Firebase 會話(刷新代幣)將被撤銷。註冊新因素時,系統會向使用者的電子郵件發送電子郵件通知。
簽名:
enroll(assertion: MultiFactorAssertion, displayName?: string | null): Promise<void>;
參數
範圍 | 類型 | 描述 |
---|---|---|
斷言 | 多因素斷言 | 用於註冊的多因素斷言。 |
顯示名稱 | 字串|無效的 | 第二個因素的顯示名稱。 |
返回:
承諾<無效>
例子
const multiFactorUser = multiFactor(auth.currentUser);
const multiFactorSession = await multiFactorUser.getSession();
// Send verification code.
const phoneAuthProvider = new PhoneAuthProvider(auth);
const phoneInfoOptions = {
phoneNumber: phoneNumber,
session: multiFactorSession
};
const verificationId = await phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, appVerifier);
// Obtain verification code from user.
const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
await multiFactorUser.enroll(multiFactorAssertion);
// Second factor enrolled.
MultiFactorUser.getSession()
傳回第二因素註冊操作的會話標識符。這用於識別嘗試註冊第二個因素的用戶。
簽名:
getSession(): Promise<MultiFactorSession>;
返回:
Promise< MultiFactorSession >
透過MultiFactorSession解決的承諾。
例子
const multiFactorUser = multiFactor(auth.currentUser);
const multiFactorSession = await multiFactorUser.getSession();
// Send verification code.
const phoneAuthProvider = new PhoneAuthProvider(auth);
const phoneInfoOptions = {
phoneNumber: phoneNumber,
session: multiFactorSession
};
const verificationId = await phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, appVerifier);
// Obtain verification code from user.
const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
await multiFactorUser.enroll(multiFactorAssertion);
MultiFactorUser.unenroll()
取消註冊指定的第二個因素。
若要指定要刪除的因素,請傳遞MultiFactorInfo物件(從MultiFactorUser.enrolledFactors檢索) ) 或因子的 UID 字串。當帳戶取消註冊時,會話不會被撤銷。可能會向使用者發送電子郵件通知,通知他們更改。此操作需要最近重新進行身份驗證才能成功。當取消註冊現有因素時,系統會向使用者的電子郵件發送電子郵件通知。
簽名:
unenroll(option: MultiFactorInfo | string): Promise<void>;
參數
範圍 | 類型 | 描述 |
---|---|---|
選項 | 多因素資訊|細繩 | 取消註冊的多因素選項。 |
返回:
承諾<無效>
- 當取消註冊操作完成時解析的
Promise
。
例子
const multiFactorUser = multiFactor(auth.currentUser);
// Present user the option to choose which factor to unenroll.
await multiFactorUser.unenroll(multiFactorUser.enrolledFactors[i])