Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Mendaftarkan nomor telepon pengujian
Dokumen ini menunjukkan cara mendaftarkan nomor telepon ke Identity Platform
untuk tujuan pengembangan. Hal ini memungkinkan Anda menguji metode autentikasi yang
melibatkan pengiriman pesan SMS, seperti login dengan ponsel dan autentikasi
multi-faktor.
Menggunakan nomor pengujian (bukan nomor asli yang Anda miliki) memiliki beberapa manfaat:
Layanan ini terintegrasi dengan lancar dengan emulator iOS dan Android.
Hal ini menghilangkan overhead pengiriman SMS yang sebenarnya.
Anda dapat menjalankan pengujian berturut-turut dengan nomor telepon yang sama tanpa
throttling.
Anda dapat menulis pengujian integrasi tanpa diblokir oleh pemeriksaan keamanan.
Kuota penggunaan Anda tidak akan berkurang.
Anda dapat mendaftarkan hingga 10 nomor telepon untuk proses pengembangan.
Jika Anda menguji autentikasi ponsel, cari autentikasi ponsel di daftar penyedia,
lalu klik ikon Edit. Jika Anda menguji autentikasi
multi-faktor, pilih tab Multi-factor SMS, lalu klik Edit.
Di bagian Nomor telepon untuk pengujian, masukkan nomor telepon dan kode
verifikasi untuk mendaftar.
Nomor telepon harus menggunakan
format E.164, dan tidak boleh ditetapkan ke pengguna
Identity Platform yang sudah ada. Kode verifikasi harus terdiri dari enam digit.
Untuk tujuan keamanan, pilih angka yang sulit ditebak, dan hindari pola yang jelas seperti +1 123-456-7890.
Klik Simpan.
Nomor telepon pengujian diperlakukan seperti nomor telepon sungguhan oleh
Identity Platform, jadi simpan dengan aman dan putar secara berkala.
Pengujian manual
Anda dapat langsung mulai menggunakan nomor telepon pengujian di aplikasi, baik secara langsung
maupun menggunakan emulator iOS dan Android. Saat login dengan nomor telepon
pengujian, tidak ada kode verifikasi SMS yang dikirim; sebagai gantinya, masukkan kode yang Anda daftarkan
saat membuat nomor pengujian.
Setelah login, pengguna Identity Platform akan dibuat menggunakan nomor telepon pengujian. Pengguna ini memiliki perilaku dan properti yang sama dengan pengguna sungguhan,
termasuk token ID yang valid, yang berarti dapat mengakses semua aplikasi dan layanan Anda.
Untuk membatasi akses dari pengguna pengujian, sebaiknya buat peran pengujian dengan
izin terbatas dan tetapkan menggunakan
klaim kustom.
Pengujian integrasi
Selain pengujian manual, SDK klien berisi API yang dapat membantu
menulis pengujian integrasi. API ini menonaktifkan reCAPTCHA dan persyaratan verifikasi aplikasi, sehingga lebih mudah dilewati dengan otomatisasi.
Contoh berikut menunjukkan cara menguji login pengguna dengan nomor telepon:
JavaScript
// Turn off phone app verification.firebase.auth().settings.appVerificationDisabledForTesting=true;varphoneNumber="+16505554567";vartestVerificationCode="123456";// Render a fake reCAPTCHA and resolve without app verification.varappVerifier=newfirebase.auth.RecaptchaVerifier('recaptcha-container');// signInWithPhoneNumber will call appVerifier.verify(), which will resolve// with a fake reCAPTCHA response.firebase.auth().signInWithPhoneNumber(phoneNumber,appVerifier).then(function(confirmationResult){// confirmationResult can resolve using testVerificationCode.returnconfirmationResult.confirm(testVerificationCode)}).catch(function(error){// Error; SMS not sent// ...});
Pemverifikasi reCAPTCHA palsu yang terlihat dan tidak terlihat berperilaku berbeda saat verifikasi aplikasi dinonaktifkan:
reCAPTCHA Terlihat: Untuk menyimulasikan klik pengguna, reCAPTCHA akan menyelesaikan reCAPTCHA secara otomatis setelah penundaan singkat.
reCAPTCHA Tidak Terlihat: Untuk menyimulasikan verifikasi aplikasi, reCAPTCHA akan menyelesaikan reCAPTCHA secara otomatis saat appVerifier.verify() dipanggil.
reCAPTCHA tiruan akan tetap memicu callback-nya saat reCAPTCHA tersebut diselesaikan atau masa berlakunya berakhir.
Langkah berikutnya
Tambahkan autentikasi multi-faktor ke aplikasi
web,
iOS, atau
Android.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-11 UTC."],[[["\u003cp\u003eThis guide details how to register up to 10 test phone numbers with Identity Platform for development and testing, allowing you to simulate phone-based authentication methods.\u003c/p\u003e\n"],["\u003cp\u003eUsing test numbers eliminates the need for real SMS messages, prevents throttling, bypasses security checks, and doesn't affect your usage quota.\u003c/p\u003e\n"],["\u003cp\u003eTo register, navigate to the Identity Providers page in the Google Cloud console, input a phone number in E.164 format and a six-digit verification code under "Phone numbers for testing," ensuring the number isn't already in use by an existing Identity Platform user.\u003c/p\u003e\n"],["\u003cp\u003eTest phone numbers function like real numbers within Identity Platform, allowing you to use them directly or with iOS/Android emulators and requiring the registered verification code for sign-in.\u003c/p\u003e\n"],["\u003cp\u003eClient SDK APIs are available to simplify integration testing by disabling reCAPTCHA and app verification, demonstrated with a JavaScript example that also showcases mock reCAPTCHA behavior.\u003c/p\u003e\n"]]],[],null,["# Registering test phone numbers\n==============================\n\nThis document shows you how to register phone numbers with Identity Platform\nfor development purposes. This allows you to test authentication methods that\ninvolve sending an SMS message, such as phone sign-in and multi-factor\nauthentication.\n\nUsing a test number (rather than a real number you own) has several benefits:\n\n- It integrates seamlessly with the iOS and Android emulators.\n- It eliminates the overhead of sending an actual SMS.\n- You can execute consecutive tests with the same phone number without being throttled.\n- You can write integration tests without being blocked by security checks.\n- It doesn't consume your usage quota.\n\nYou can register up to 10 phone numbers for development.\n\nRegistering a test phone number\n-------------------------------\n\nTo register a test phone number:\n\n1. Go to the **Identity Providers** page in the Google Cloud console. \n\n [Go to the Identity Providers page](https://console.cloud.google.com/customer-identity/providers) \n\n2. If you are testing phone authentication, locate it in the list of providers,\n then click the **Edit** icon. If you are testing multi-factor\n authentication, select the **Multi-factor SMS** tab, then click **Edit**.\n\n3. Under **Phone numbers for testing**, enter a phone number and verification\n code to register.\n\n The phone number should use\n [E.164 format](https://wikipedia.org/wiki/E.164), and cannot already be assigned to an existing\n Identity Platform user. The verification code should be six digits.\n For security purposes, choose numbers that are difficult to guess, and avoid\n obvious patterns like `+1 123-456-7890`.\n4. Click **Save**.\n\nTesting phone numbers are treated like real phone numbers by\nIdentity Platform, so store them securely and rotate them at regular\nintervals.\n\nManual testing\n--------------\n\nYou can immediately begin using test phone numbers in your app, either directly\nor using the iOS and Android emulators. When signing in with a test phone\nnumber, no SMS verification code is sent; instead, enter the code you registered\nwhen creating the test number.\n\nAfter signing in, an Identity Platform user is created using the test phone\nnumber. This user has the same behavior and properties as a real user,\nincluding a valid ID token, meaning it can access all your apps and services.\n\nTo restrict access from your test users, consider creating a test role with\nlimited permissions and assigning it using\n[custom claims](/identity-platform/docs/how-to-configure-custom-claims).\n\nIntegration testing\n-------------------\n\nIn addition to manual testing, the client SDK contains APIs that can help\nwrite integration tests. These APIs disable the reCAPTCHA and app verification\nrequirements, making them easier bypass with automation.\n\nThe following example shows how to test signing in a user with a phone number: \n\n### JavaScript\n\n // Turn off phone app verification.\n firebase.auth().settings.appVerificationDisabledForTesting = true;\n\n var phoneNumber = \"+16505554567\";\n var testVerificationCode = \"123456\";\n\n // Render a fake reCAPTCHA and resolve without app verification.\n var appVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container');\n // signInWithPhoneNumber will call appVerifier.verify(), which will resolve\n // with a fake reCAPTCHA response.\n firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier)\n .then(function (confirmationResult) {\n // confirmationResult can resolve using testVerificationCode.\n return confirmationResult.confirm(testVerificationCode)\n }).catch(function (error) {\n // Error; SMS not sent\n // ...\n });\n\nVisible and invisible mock reCAPTCHA verifiers behave differently when\napp verification is disabled:\n\n- **Visible reCAPTCHA:** To simulate a user click, the reCAPTCHA will resolve\n itself automatically after a brief delay.\n\n- **Invisible reCAPTCHA** : To simulate app verification, the reCAPTCHA will\n resolve automatically when `appVerifier.verify()` is called.\n\nMock reCAPTCHAs will still trigger their callbacks when they resolve or expire.\n\nWhat's next\n-----------\n\n- Add multi-factor authentication to your [web](/identity-platform/docs/web/mfa), [iOS](/identity-platform/docs/ios/mfa), or [Android](/identity-platform/docs/android/mfa) app."]]