您可以透過 Firebase Authentication 將簡訊傳送至使用者的手機,讓使用者登入。使用者透過簡訊中的一次性代碼登入。
如要輕鬆在應用程式中新增電話號碼登入功能,最簡單的方法是使用 FirebaseUI,其中包含置入式登入小工具,可實作電話號碼登入、密碼登入和聯合登入的登入流程。本文說明如何使用 Firebase SDK 導入手機號碼登入流程。
事前準備
- 如果您尚未將 Firebase 新增至 Android 專案,請先新增。
-
在模組 (應用程式層級) Gradle 檔案 (通常是
<project>/<app-module>/build.gradle.kts
或<project>/<app-module>/build.gradle
) 中,加入 Android 適用的 Firebase Authentication 程式庫依附元件。建議使用 Firebase Android BoM 控制程式庫版本。 <0xdependencies { // Import the BoM for the Firebase platform implementation(platform("com.google.firebase:firebase-bom:34.0.0")) // Add the dependency for the Firebase Authentication library // When using the BoM, you don't specify versions in Firebase library dependencies implementation("com.google.firebase:firebase-auth") }
只要使用 Firebase Android BoM,應用程式就會一律使用相容的 Firebase Android 程式庫版本。
(替代做法) 不使用 BoM 新增 Firebase 程式庫依附元件
如果選擇不使用 Firebase BoM,則必須在依附元件行中指定每個 Firebase 程式庫版本。
請注意,如果應用程式使用多個 Firebase 程式庫,強烈建議使用 BoM 管理程式庫版本,確保所有版本都相容。
dependencies { // Add the dependency for the Firebase Authentication library // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation("com.google.firebase:firebase-auth:24.0.0") }
- 如果尚未將應用程式連結至 Firebase 專案,請從 Firebase 控制台進行連結。
- 如果您尚未在 Firebase 控制台中設定應用程式的 SHA-1 雜湊值,請進行設定。如要瞭解如何找出應用程式的 SHA-1 雜湊值,請參閱「 驗證用戶端」。
安全疑慮
雖然只使用電話號碼進行驗證很方便,但安全性不如其他可用方法,因為電話號碼很容易在使用者之間轉移。此外,如果裝置有多個使用者設定檔,任何可接收簡訊的使用者都能使用裝置的電話號碼登入帳戶。
如果應用程式採用電話號碼登入方式,請一併提供更安全的登入方式,並告知使用者使用電話號碼登入的安全性考量。
為 Firebase 專案啟用電話號碼登入功能
如要透過簡訊登入使用者,請先為 Firebase 專案啟用電話號碼登入方法:
- 在 Firebase 控制台中,開啟「驗證」部分。
- 在「登入方式」頁面中,啟用「電話號碼」登入方式。
啟用應用程式驗證
如要使用電話號碼驗證功能,Firebase 必須能夠驗證電話號碼登入要求是否來自您的應用程式。Firebase Firebase Authentication 可透過三種方式達成此目的:
- Play Integrity API:如果使用者裝置已安裝 Google Play services,且 Firebase Authentication 可透過 Play Integrity API 驗證裝置是否合法,即可繼續進行電話號碼登入程序。Play Integrity API 是在 Google 擁有的專案中啟用,而不是在您的專案中。Firebase Authentication這不會計入專案的任何 Play Integrity API 配額。Play Integrity 支援功能適用於 Authentication SDK 21.2.0 以上版本 (Firebase BoM 31.4.0 以上版本)。
如要使用 Play Integrity,請前往 Firebase 控制台的專案設定,指定應用程式的 SHA-256 指紋 (如果尚未指定)。如要瞭解如何取得應用程式的 SHA-256 指紋,請參閱「驗證用戶端」。
- reCAPTCHA 驗證:如果無法使用 Play Integrity,例如使用者裝置未安裝 Google Play services,Firebase Authentication則可使用 reCAPTCHA 驗證完成手機登入流程。使用者通常不必回答任何問題,就能完成 reCAPTCHA 驗證。請注意,這個流程需要將 SHA-1 與應用程式建立關聯。此外,您的 API 金鑰必須未設限,或已加入
PROJECT_ID.firebaseapp.com
的允許清單。觸發 reCAPTCHA 的情況包括:
- 如果使用者的裝置未安裝 Google Play services。
- 如果應用程式不是透過 Google Play Store 發布 (使用 Authentication SDK 21.2.0 以上版本)。
- 如果取得的 SafetyNet 權杖無效 (適用於 Authentication SDK 版本 < v21.2.0)。
使用 SafetyNet 或 Play Integrity 驗證應用程式時,簡訊範本中的
%APP_NAME%
欄位會填入 Google Play Store 判斷的應用程式名稱。 在觸發 reCAPTCHA 的情況下,%APP_NAME%
會填入PROJECT_ID.firebaseapp.com
。
forceRecaptchaFlowForTesting
強制執行 reCAPTCHA 驗證流程。
使用虛構電話號碼時,您可以使用 setAppVerificationDisabledForTesting
停用應用程式驗證。
疑難排解
使用 reCAPTCHA 進行應用程式驗證時發生「Missing initial state」錯誤
如果 reCAPTCHA 流程順利完成,但未將使用者重新導向回原生應用程式,就可能發生這種情況。如果發生這種情況,使用者會重新導向至備援網址
PROJECT_ID.firebaseapp.com/__/auth/handler
。在 Firefox 瀏覽器中,系統預設會停用開啟原生應用程式連結的功能。如果在 Firefox 上看到上述錯誤,請按照「設定 Firefox for Android 在原生應用程式中開啟連結」一文中的步驟,啟用開啟應用程式連結的功能。
將驗證碼傳送至使用者的手機
如要啟動電話號碼登入程序,請向使用者顯示介面,提示他們輸入電話號碼。法律規定因國家/地區而異,但最佳做法是告知使用者,如果他們使用手機登入,可能會收到驗證簡訊,且須支付一般簡訊費用,藉此設定使用者期望。
然後將電話號碼傳遞至 PhoneAuthProvider.verifyPhoneNumber
方法,要求 Firebase 驗證使用者的電話號碼。例如:
Kotlin
val options = PhoneAuthOptions.newBuilder(auth) .setPhoneNumber(phoneNumber) // Phone number to verify .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit .setActivity(this) // Activity (for callback binding) .setCallbacks(callbacks) // OnVerificationStateChangedCallbacks .build() PhoneAuthProvider.verifyPhoneNumber(options)
Java
PhoneAuthOptions options = PhoneAuthOptions.newBuilder(mAuth) .setPhoneNumber(phoneNumber) // Phone number to verify .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit .setActivity(this) // (optional) Activity for callback binding // If no activity is passed, reCAPTCHA verification can not be used. .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks .build(); PhoneAuthProvider.verifyPhoneNumber(options);
verifyPhoneNumber
方法是可重入的:如果您多次呼叫該方法 (例如在活動的 onStart
方法中),除非原始要求逾時,否則 verifyPhoneNumber
方法不會傳送第二則簡訊。
如果應用程式在使用者登入前關閉 (例如使用者正在使用簡訊應用程式),您可以使用這項行為繼續電話號碼登入程序。呼叫 verifyPhoneNumber
後,請設定旗標,指出驗證正在進行中。接著,請在 Activity 的 onSaveInstanceState
方法中儲存標記,並在 onRestoreInstanceState
中還原標記。最後,在活動的 onStart
方法中,檢查驗證是否已在進行中,如果是,請再次呼叫 verifyPhoneNumber
。驗證完成或失敗時,請務必清除標記 (請參閱「
驗證回呼」)。
如要輕鬆處理螢幕旋轉和其他 Activity 重新啟動的執行個體,請將 Activity 傳遞至 verifyPhoneNumber
方法。活動停止時,回呼會自動分離,因此您可以在回呼方法中自由編寫 UI 轉場效果程式碼。
您也可以透過 Auth 執行個體上的 setLanguageCode
方法指定驗證語言,將 Firebase 傳送的簡訊本地化。
Kotlin
auth.setLanguageCode("fr") // To apply the default app language instead of explicitly setting it. // auth.useAppLanguage()
Java
auth.setLanguageCode("fr"); // To apply the default app language instead of explicitly setting it. // auth.useAppLanguage();
呼叫 PhoneAuthProvider.verifyPhoneNumber
時,您也必須提供 OnVerificationStateChangedCallbacks
的執行個體,其中包含可處理要求結果的回呼函式實作。例如:
Kotlin
callbacks = object : PhoneAuthProvider.OnVerificationStateChangedCallbacks() { override fun onVerificationCompleted(credential: PhoneAuthCredential) { // This callback will be invoked in two situations: // 1 - Instant verification. In some cases the phone number can be instantly // verified without needing to send or enter a verification code. // 2 - Auto-retrieval. On some devices Google Play services can automatically // detect the incoming verification SMS and perform verification without // user action. Log.d(TAG, "onVerificationCompleted:$credential") signInWithPhoneAuthCredential(credential) } override fun onVerificationFailed(e: FirebaseException) { // This callback is invoked in an invalid request for verification is made, // for instance if the the phone number format is not valid. Log.w(TAG, "onVerificationFailed", e) if (e is FirebaseAuthInvalidCredentialsException) { // Invalid request } else if (e is FirebaseTooManyRequestsException) { // The SMS quota for the project has been exceeded } else if (e is FirebaseAuthMissingActivityForRecaptchaException) { // reCAPTCHA verification attempted with null Activity } // Show a message and update the UI } override fun onCodeSent( verificationId: String, token: PhoneAuthProvider.ForceResendingToken, ) { // The SMS verification code has been sent to the provided phone number, we // now need to ask the user to enter the code and then construct a credential // by combining the code with a verification ID. Log.d(TAG, "onCodeSent:$verificationId") // Save verification ID and resending token so we can use them later storedVerificationId = verificationId resendToken = token } }
Java
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { @Override public void onVerificationCompleted(@NonNull PhoneAuthCredential credential) { // This callback will be invoked in two situations: // 1 - Instant verification. In some cases the phone number can be instantly // verified without needing to send or enter a verification code. // 2 - Auto-retrieval. On some devices Google Play services can automatically // detect the incoming verification SMS and perform verification without // user action. Log.d(TAG, "onVerificationCompleted:" + credential); signInWithPhoneAuthCredential(credential); } @Override public void onVerificationFailed(@NonNull FirebaseException e) { // This callback is invoked in an invalid request for verification is made, // for instance if the the phone number format is not valid. Log.w(TAG, "onVerificationFailed", e); if (e instanceof FirebaseAuthInvalidCredentialsException) { // Invalid request } else if (e instanceof FirebaseTooManyRequestsException) { // The SMS quota for the project has been exceeded } else if (e instanceof FirebaseAuthMissingActivityForRecaptchaException) { // reCAPTCHA verification attempted with null Activity } // Show a message and update the UI } @Override public void onCodeSent(@NonNull String verificationId, @NonNull PhoneAuthProvider.ForceResendingToken token) { // The SMS verification code has been sent to the provided phone number, we // now need to ask the user to enter the code and then construct a credential // by combining the code with a verification ID. Log.d(TAG, "onCodeSent:" + verificationId); // Save verification ID and resending token so we can use them later mVerificationId = verificationId; mResendToken = token; } };
驗證回呼
在大多數應用程式中,您會實作 onVerificationCompleted
、onVerificationFailed
和 onCodeSent
回呼。您也可以根據應用程式需求實作 onCodeAutoRetrievalTimeOut
。
onVerificationCompleted(PhoneAuthCredential)
這個方法會在下列兩種情況中呼叫:
- 即時驗證:在某些情況下,系統會即時驗證電話號碼,不必傳送或輸入驗證碼。
- 自動擷取:在部分裝置上,Google Play 服務可以自動偵測收到的驗證簡訊,並執行驗證,不必使用者操作。(部分電信業者可能不支援這項功能)。這會使用 SMS Retriever API,其中包含簡訊結尾的 11 個字元雜湊值。
PhoneAuthCredential
物件登入使用者。
onVerificationFailed(FirebaseException)
這個方法會在驗證要求無效時呼叫,例如要求指定無效的電話號碼或驗證碼。
onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken)
(選用步驟) 系統會先透過簡訊將驗證碼傳送到提供的電話號碼,然後再呼叫這個方法。
呼叫這個方法時,大多數應用程式會顯示 UI,提示使用者輸入簡訊中的驗證碼。(同時,自動驗證可能會在背景進行)。接著,使用者輸入驗證碼後,您可以使用驗證碼和傳遞至方法的驗證 ID 建立 PhoneAuthCredential
物件,進而登入使用者。不過,部分應用程式可能會等到呼叫 onCodeAutoRetrievalTimeOut
後,才顯示驗證碼 UI (不建議)。
onCodeAutoRetrievalTimeOut(String verificationId)
(選用步驟) 如果 verifyPhoneNumber
指定的逾時時間已過,但 onVerificationCompleted
尚未觸發,系統就會呼叫這個方法。如果裝置沒有 SIM 卡,系統會立即呼叫這個方法,因為無法自動擷取簡訊。
部分應用程式會封鎖使用者輸入內容,直到自動驗證時間到期為止,然後才顯示 UI,提示使用者輸入簡訊中的驗證碼 (不建議)。
建立 PhoneAuthCredential 物件
使用者輸入 Firebase 傳送至手機的驗證碼後,請使用驗證碼和傳遞至 onCodeSent
或 onCodeAutoRetrievalTimeOut
回呼的驗證 ID,建立 PhoneAuthCredential
物件。(呼叫
onVerificationCompleted
時,您會直接取得 PhoneAuthCredential
物件,因此可以略過這個步驟)。
如要建立 PhoneAuthCredential
物件,請呼叫 PhoneAuthProvider.getCredential
:
Kotlin
val credential = PhoneAuthProvider.getCredential(verificationId!!, code)
Java
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code);
登入使用者帳戶
取得 PhoneAuthCredential
物件後 (無論是在 onVerificationCompleted
回呼中或透過呼叫 PhoneAuthProvider.getCredential
),請將 PhoneAuthCredential
物件傳遞至 FirebaseAuth.signInWithCredential
,完成登入流程:
Kotlin
private fun signInWithPhoneAuthCredential(credential: PhoneAuthCredential) { auth.signInWithCredential(credential) .addOnCompleteListener(this) { task -> if (task.isSuccessful) { // Sign in success, update UI with the signed-in user's information Log.d(TAG, "signInWithCredential:success") val user = task.result?.user } else { // Sign in failed, display a message and update the UI Log.w(TAG, "signInWithCredential:failure", task.exception) if (task.exception is FirebaseAuthInvalidCredentialsException) { // The verification code entered was invalid } // Update UI } } }
Java
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) { mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information Log.d(TAG, "signInWithCredential:success"); FirebaseUser user = task.getResult().getUser(); // Update UI } else { // Sign in failed, display a message and update the UI Log.w(TAG, "signInWithCredential:failure", task.getException()); if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) { // The verification code entered was invalid } } } }); }
使用虛構電話號碼進行測試
您可以透過 Firebase 控制台,設定開發用的虛構電話號碼。使用虛構電話號碼進行測試可享有以下好處:
- 測試電話號碼驗證功能,不會耗用配額。
- 測試電話號碼驗證,不必傳送實際的簡訊。
- 使用相同電話號碼連續進行測試,不會受到節流限制。如果審查人員在測試時使用相同的電話號碼,這樣就能盡量避免在應用程式商店審查程序中遭到拒絕。
- 在開發環境中輕鬆測試,不必費心處理其他事項,例如在 iOS 模擬器或 Android 模擬器中開發,不必使用 Google Play 服務。
- 編寫整合測試時,不會受到一般在正式環境中對實際電話號碼套用的安全檢查阻礙。
虛構電話號碼必須符合下列規定:
- 請務必使用虛構的電話號碼,且該號碼不得已存在。 Firebase Authentication 不允許您將真實使用者使用的現有電話號碼設為測試號碼。 其中一個方法是使用以 555 為前置號碼的美國測試電話號碼,例如: +1 650-555-3434
- 電話號碼的長度和其他限制必須符合正確格式。系統仍會對這些號碼進行與一般使用者電話號碼相同的驗證。
- 您最多可以新增 10 個開發用電話號碼。
- 使用難以猜測的測試電話號碼/代碼,並經常變更。
建立虛構的電話號碼和驗證碼
- 在 Firebase 控制台中,開啟「驗證」部分。
- 在「登入方法」分頁中,啟用電話號碼供應商 (如果尚未啟用)。
- 開啟「測試用電話號碼」手風琴選單。
- 提供要測試的電話號碼,例如:+1 650-555-3434。
- 提供該號碼的 6 位數驗證碼,例如:654321。
- 新增電話號碼。如有需要,只要將游標懸停在對應列上,然後點按垃圾桶圖示,即可刪除電話號碼和驗證碼。
手動測試
您可以在應用程式中直接使用虛構電話號碼。這樣一來,您就能在開發階段執行手動測試,而不必擔心配額問題或節流。您也可以直接從 iOS 模擬器或 Android Emulator 進行測試,不必安裝 Google Play 服務。
提供虛構電話號碼並傳送驗證碼時,系統不會傳送實際的簡訊。您必須提供先前設定的驗證碼,才能完成登入。
登入完成後,系統會使用該電話號碼建立 Firebase 使用者。使用者行為和屬性與實際電話號碼使用者相同,且可透過相同方式存取 Realtime Database/Cloud Firestore 和其他服務。在此程序中產生的 ID 權杖,與實際電話號碼使用者的簽章相同。
如要進一步限制存取權,也可以透過這些使用者的自訂聲明設定測試角色,將他們區分為假冒使用者。
如要手動觸發 reCAPTCHA 流程進行測試,請使用 forceRecaptchaFlowForTesting()
方法。
// Force reCAPTCHA flow FirebaseAuth.getInstance().getFirebaseAuthSettings().forceRecaptchaFlowForTesting();
整合測試
除了手動測試之外,Firebase Authentication 也提供 API,協助您為電話號碼驗證測試編寫整合測試。這些 API 會停用 reCAPTCHA 需求,以及 iOS 中的網頁和無聲推播通知,藉此停用應用程式驗證。因此,您可以在這些流程中進行自動化測試,且實作起來也更輕鬆。此外,這些 API 也可協助您在 Android 上測試即時驗證流程。
在 Android 上,請先呼叫 setAppVerificationDisabledForTesting()
,再呼叫 signInWithPhoneNumber
。這樣一來,系統會自動停用應用程式驗證,讓您略過電話號碼驗證,不必手動解決。即使停用 Play Integrity 和 reCAPTCHA,使用真實電話號碼仍無法完成登入。這個 API 只能使用虛構電話號碼。
// Turn off phone auth app verification. FirebaseAuth.getInstance().getFirebaseAuthSettings() .setAppVerificationDisabledForTesting();
使用虛構號碼撥打 verifyPhoneNumber
會觸發 onCodeSent
回呼,您必須在其中提供相應的驗證碼。這項功能可讓您在 Android 模擬器中進行測試。
Java
String phoneNum = "+16505554567"; String testVerificationCode = "123456"; // Whenever verification is triggered with the whitelisted number, // provided it is not set for auto-retrieval, onCodeSent will be triggered. FirebaseAuth auth = FirebaseAuth.getInstance(); PhoneAuthOptions options = PhoneAuthOptions.newBuilder(auth) .setPhoneNumber(phoneNum) .setTimeout(60L, TimeUnit.SECONDS) .setActivity(this) .setCallbacks(new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { @Override public void onCodeSent(@NonNull String verificationId, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) { // Save the verification id somewhere // ... // The corresponding whitelisted code above should be used to complete sign-in. MainActivity.this.enableUserManuallyInputCode(); } @Override public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) { // Sign in with the credential // ... } @Override public void onVerificationFailed(@NonNull FirebaseException e) { // ... } }) .build(); PhoneAuthProvider.verifyPhoneNumber(options);
Kotlin
val phoneNum = "+16505554567" val testVerificationCode = "123456" // Whenever verification is triggered with the whitelisted number, // provided it is not set for auto-retrieval, onCodeSent will be triggered. val options = PhoneAuthOptions.newBuilder(Firebase.auth) .setPhoneNumber(phoneNum) .setTimeout(30L, TimeUnit.SECONDS) .setActivity(this) .setCallbacks(object : PhoneAuthProvider.OnVerificationStateChangedCallbacks() { override fun onCodeSent( verificationId: String, forceResendingToken: PhoneAuthProvider.ForceResendingToken, ) { // Save the verification id somewhere // ... // The corresponding whitelisted code above should be used to complete sign-in. this@MainActivity.enableUserManuallyInputCode() } override fun onVerificationCompleted(phoneAuthCredential: PhoneAuthCredential) { // Sign in with the credential // ... } override fun onVerificationFailed(e: FirebaseException) { // ... } }) .build() PhoneAuthProvider.verifyPhoneNumber(options)
此外,您也可以呼叫 setAutoRetrievedSmsCodeForPhoneNumber
,設定虛構號碼及其對應的驗證碼,在 Android 中測試自動擷取流程。
呼叫 verifyPhoneNumber
時,會直接使用 PhoneAuthCredential
觸發 onVerificationCompleted
。這項功能僅適用於虛構電話號碼。
將應用程式發布至 Google Play 商店時,請務必停用這項功能,且應用程式中沒有任何虛構電話號碼經過硬式編碼。
Java
// The test phone number and code should be whitelisted in the console. String phoneNumber = "+16505554567"; String smsCode = "123456"; FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(); FirebaseAuthSettings firebaseAuthSettings = firebaseAuth.getFirebaseAuthSettings(); // Configure faking the auto-retrieval with the whitelisted numbers. firebaseAuthSettings.setAutoRetrievedSmsCodeForPhoneNumber(phoneNumber, smsCode); PhoneAuthOptions options = PhoneAuthOptions.newBuilder(firebaseAuth) .setPhoneNumber(phoneNumber) .setTimeout(60L, TimeUnit.SECONDS) .setActivity(this) .setCallbacks(new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { @Override public void onVerificationCompleted(@NonNull PhoneAuthCredential credential) { // Instant verification is applied and a credential is directly returned. // ... } // ... }) .build(); PhoneAuthProvider.verifyPhoneNumber(options);
Kotlin
// The test phone number and code should be whitelisted in the console. val phoneNumber = "+16505554567" val smsCode = "123456" val firebaseAuth = Firebase.auth val firebaseAuthSettings = firebaseAuth.firebaseAuthSettings // Configure faking the auto-retrieval with the whitelisted numbers. firebaseAuthSettings.setAutoRetrievedSmsCodeForPhoneNumber(phoneNumber, smsCode) val options = PhoneAuthOptions.newBuilder(firebaseAuth) .setPhoneNumber(phoneNumber) .setTimeout(60L, TimeUnit.SECONDS) .setActivity(this) .setCallbacks(object : PhoneAuthProvider.OnVerificationStateChangedCallbacks() { override fun onVerificationCompleted(credential: PhoneAuthCredential) { // Instant verification is applied and a credential is directly returned. // ... } // ... }) .build() PhoneAuthProvider.verifyPhoneNumber(options)
後續步驟
使用者首次登入後,系統會建立新的使用者帳戶,並連結至使用者登入時使用的憑證 (即使用者名稱和密碼、電話號碼或驗證供應商資訊)。這個新帳戶會儲存在 Firebase 專案中,可用於識別專案中每個應用程式的使用者,無論使用者登入方式為何。
-
在應用程式中,您可以從
FirebaseUser
物件取得使用者的基本個人資料資訊。請參閱「 管理使用者」。 在 Firebase Realtime Database 和 Cloud Storage 安全規則中,您可以從
auth
變數取得已登入使用者的專屬使用者 ID, 並使用該 ID 控制使用者可存取的資料。
您可以將驗證供應商憑證連結至現有使用者帳戶,允許使用者透過多個驗證供應商登入應用程式。
如要登出使用者,請呼叫
signOut
:
Kotlin
Firebase.auth.signOut()
Java
FirebaseAuth.getInstance().signOut();