From a6aed54a9bb8d3f49606d6cf67f0d3127097ecb3 Mon Sep 17 00:00:00 2001 From: Megha Bangalore Date: Mon, 5 Oct 2020 17:40:04 -0700 Subject: [PATCH 1/8] Quickstart updates Explicitly specific activity for callbackbinding, use PhoneAuthOptions --- .../quickstart/auth/java/PhoneAuthActivity.java | 16 ++++++++++------ .../quickstart/auth/kotlin/PhoneAuthActivity.kt | 14 ++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java b/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java index 6f3c71c35..5760d270d 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java @@ -175,12 +175,16 @@ protected void onRestoreInstanceState(Bundle savedInstanceState) { private void startPhoneNumberVerification(String phoneNumber) { // [START start_phone_auth] - PhoneAuthProvider.getInstance().verifyPhoneNumber( - phoneNumber, // Phone number to verify - 60, // Timeout duration - TimeUnit.SECONDS, // Unit of timeout - this, // Activity (for callback binding) - mCallbacks); // OnVerificationStateChangedCallbacks + + PhoneAuthOptions options = + PhoneAuthOptions.newBuilder(mAuth) + .setPhoneNumber(phoneNumber) // Phone number to verify + .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit + .setActivity(this) // Activity (for callback binding) + .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks + .build(); + PhoneAuthProvider.getInstance() + .verifyPhoneNumber(options); // [END start_phone_auth] mVerificationInProgress = true; diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt index 79d3fab73..a451f51ab 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt @@ -151,12 +151,14 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { private fun startPhoneNumberVerification(phoneNumber: String) { // [START start_phone_auth] - PhoneAuthProvider.getInstance().verifyPhoneNumber( - phoneNumber, // Phone number to verify - 60, // Timeout duration - TimeUnit.SECONDS, // Unit of timeout - this, // Activity (for callback binding) - callbacks) // OnVerificationStateChangedCallbacks + PhoneAuthOptions options = + PhoneAuthOptions.newBuilder(mAuth) + .setPhoneNumber(phoneNumber) // Phone number to verify + .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit + .setActivity(this) // Activity (for callback binding) + .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks + .build(); + PhoneAuthProvider.getInstance().verifyPhoneNumber(options); // [END start_phone_auth] verificationInProgress = true From e839b788fe10a46ad3f668ae8f0024955bad40dd Mon Sep 17 00:00:00 2001 From: Megha Bangalore Date: Mon, 5 Oct 2020 17:56:28 -0700 Subject: [PATCH 2/8] add imports --- .../firebase/quickstart/auth/java/PhoneAuthActivity.java | 1 + .../firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java b/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java index 5760d270d..e6a1c8c16 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java @@ -18,6 +18,7 @@ import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException; import com.google.firebase.auth.FirebaseUser; import com.google.firebase.auth.PhoneAuthCredential; +import com.google.firebase.auth.PhoneAuthOptions; import com.google.firebase.auth.PhoneAuthProvider; import com.google.firebase.quickstart.auth.R; import com.google.firebase.quickstart.auth.databinding.ActivityPhoneAuthBinding; diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt index a451f51ab..38d56e81c 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt @@ -12,6 +12,7 @@ import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException import com.google.firebase.auth.FirebaseUser import com.google.firebase.auth.PhoneAuthCredential +import com.google.firebase.auth.PhoneAuthOptions import com.google.firebase.auth.PhoneAuthProvider import com.google.firebase.auth.ktx.auth import com.google.firebase.ktx.Firebase @@ -151,7 +152,7 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { private fun startPhoneNumberVerification(phoneNumber: String) { // [START start_phone_auth] - PhoneAuthOptions options = + val options = PhoneAuthOptions.newBuilder(mAuth) .setPhoneNumber(phoneNumber) // Phone number to verify .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit From 0d9e7760f76b3437139def3b64d8ad82a363d7b6 Mon Sep 17 00:00:00 2001 From: Megha Bangalore Date: Wed, 7 Oct 2020 17:22:53 -0700 Subject: [PATCH 3/8] use options with authProvider --- .../auth/java/PhoneAuthActivity.java | 20 +++++++++---------- .../auth/kotlin/PhoneAuthActivity.kt | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java b/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java index e6a1c8c16..14058ac4d 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java @@ -176,7 +176,6 @@ protected void onRestoreInstanceState(Bundle savedInstanceState) { private void startPhoneNumberVerification(String phoneNumber) { // [START start_phone_auth] - PhoneAuthOptions options = PhoneAuthOptions.newBuilder(mAuth) .setPhoneNumber(phoneNumber) // Phone number to verify @@ -184,8 +183,7 @@ private void startPhoneNumberVerification(String phoneNumber) { .setActivity(this) // Activity (for callback binding) .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks .build(); - PhoneAuthProvider.getInstance() - .verifyPhoneNumber(options); + PhoneAuthProvider.verifyPhoneNumber(options); // [END start_phone_auth] mVerificationInProgress = true; @@ -201,13 +199,15 @@ private void verifyPhoneNumberWithCode(String verificationId, String code) { // [START resend_verification] private void resendVerificationCode(String phoneNumber, PhoneAuthProvider.ForceResendingToken token) { - PhoneAuthProvider.getInstance().verifyPhoneNumber( - phoneNumber, // Phone number to verify - 60, // Timeout duration - TimeUnit.SECONDS, // Unit of timeout - this, // Activity (for callback binding) - mCallbacks, // OnVerificationStateChangedCallbacks - token); // ForceResendingToken from callbacks + PhoneAuthOptions options = + PhoneAuthOptions.newBuilder(mAuth) + .setPhoneNumber(phoneNumber) // Phone number to verify + .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit + .setActivity(this) // Activity (for callback binding) + .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks + .setForceResendingToken(token) // ForceResendingToken from callbacks + .build(); + PhoneAuthProvider.verifyPhoneNumber(options); } // [END resend_verification] diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt index 38d56e81c..7b6454612 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt @@ -152,14 +152,13 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { private fun startPhoneNumberVerification(phoneNumber: String) { // [START start_phone_auth] - val options = - PhoneAuthOptions.newBuilder(mAuth) + val options = PhoneAuthOptions.newBuilder(mAuth) .setPhoneNumber(phoneNumber) // Phone number to verify .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit .setActivity(this) // Activity (for callback binding) .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks .build(); - PhoneAuthProvider.getInstance().verifyPhoneNumber(options); + PhoneAuthProvider.verifyPhoneNumber(options); // [END start_phone_auth] verificationInProgress = true @@ -177,13 +176,14 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { phoneNumber: String, token: PhoneAuthProvider.ForceResendingToken? ) { - PhoneAuthProvider.getInstance().verifyPhoneNumber( - phoneNumber, // Phone number to verify - 60, // Timeout duration - TimeUnit.SECONDS, // Unit of timeout - this, // Activity (for callback binding) - callbacks, // OnVerificationStateChangedCallbacks - token) // ForceResendingToken from callbacks + val options = PhoneAuthOptions.newBuilder(mAuth) + .setPhoneNumber(phoneNumber) // Phone number to verify + .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit + .setActivity(this) // Activity (for callback binding) + .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks + .setForceResendingToken(token) // ForceResendingToken from callbacks + .build(); + PhoneAuthProvider.verifyPhoneNumber(options); } // [END resend_verification] From da0ed2bc5a7fda91b9672bceb806eedea7bf919c Mon Sep 17 00:00:00 2001 From: Megha Bangalore Date: Wed, 28 Oct 2020 13:23:36 -0700 Subject: [PATCH 4/8] 20.0.0 ; , spacing --- auth/app/build.gradle | 2 +- .../auth/kotlin/PhoneAuthActivity.kt | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/auth/app/build.gradle b/auth/app/build.gradle index 15b9eaa55..8a781d21a 100644 --- a/auth/app/build.gradle +++ b/auth/app/build.gradle @@ -44,7 +44,7 @@ dependencies { // Firebase Authentication (Java) implementation 'com.google.firebase:firebase-analytics:17.5.0' - implementation 'com.google.firebase:firebase-auth:19.4.0' + implementation 'com.google.firebase:firebase-auth:20.0.0' // Firebase Authentication (Kotlin) implementation 'com.google.firebase:firebase-auth-ktx:19.4.0' diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt index 7b6454612..d0ffbc60e 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt @@ -153,12 +153,12 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { private fun startPhoneNumberVerification(phoneNumber: String) { // [START start_phone_auth] val options = PhoneAuthOptions.newBuilder(mAuth) - .setPhoneNumber(phoneNumber) // Phone number to verify - .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit - .setActivity(this) // Activity (for callback binding) - .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks - .build(); - PhoneAuthProvider.verifyPhoneNumber(options); + .setPhoneNumber(phoneNumber) // Phone number to verify + .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit + .setActivity(this) // Activity (for callback binding) + .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks + .build() + PhoneAuthProvider.verifyPhoneNumber(options) // [END start_phone_auth] verificationInProgress = true @@ -177,13 +177,13 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { token: PhoneAuthProvider.ForceResendingToken? ) { val options = PhoneAuthOptions.newBuilder(mAuth) - .setPhoneNumber(phoneNumber) // Phone number to verify - .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit - .setActivity(this) // Activity (for callback binding) - .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks - .setForceResendingToken(token) // ForceResendingToken from callbacks - .build(); - PhoneAuthProvider.verifyPhoneNumber(options); + .setPhoneNumber(phoneNumber) // Phone number to verify + .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit + .setActivity(this) // Activity (for callback binding) + .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks + .setForceResendingToken(token) // ForceResendingToken from callbacks + .build() + PhoneAuthProvider.verifyPhoneNumber(options) } // [END resend_verification] From 0101c213b8623d75f8f1139313e6aaa2397b312c Mon Sep 17 00:00:00 2001 From: Megha Bangalore Date: Wed, 28 Oct 2020 13:26:42 -0700 Subject: [PATCH 5/8] bom import --- auth/app/build.gradle | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/auth/app/build.gradle b/auth/app/build.gradle index 8a781d21a..d591505e0 100644 --- a/auth/app/build.gradle +++ b/auth/app/build.gradle @@ -38,16 +38,18 @@ dependencies { implementation project(':internal:lintchecks') implementation 'androidx.multidex:multidex:2.0.1' - implementation 'androidx.constraintlayout:constraintlayout:2.0.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.2' implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0' implementation 'com.google.android.material:material:1.2.1' + // Import the Firebase BoM (see: https://firebase.google.com/docs/android/learn-more#bom) + implementation platform('com.google.firebase:firebase-bom:26.0.0') + // Firebase Authentication (Java) - implementation 'com.google.firebase:firebase-analytics:17.5.0' - implementation 'com.google.firebase:firebase-auth:20.0.0' + implementation 'com.google.firebase:firebase-auth' // Firebase Authentication (Kotlin) - implementation 'com.google.firebase:firebase-auth-ktx:19.4.0' + implementation 'com.google.firebase:firebase-auth-ktx' // Google Sign In SDK (only required for Google Sign In) implementation 'com.google.android.gms:play-services-auth:18.1.0' From 5ca1bfd72d3d18b516e55d1239036a29d585513e Mon Sep 17 00:00:00 2001 From: Megha Bangalore Date: Wed, 28 Oct 2020 13:44:26 -0700 Subject: [PATCH 6/8] derp --- .../firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt index d0ffbc60e..a60d1cc45 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt @@ -152,7 +152,7 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { private fun startPhoneNumberVerification(phoneNumber: String) { // [START start_phone_auth] - val options = PhoneAuthOptions.newBuilder(mAuth) + val options = PhoneAuthOptions.newBuilder(auth) .setPhoneNumber(phoneNumber) // Phone number to verify .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit .setActivity(this) // Activity (for callback binding) @@ -176,7 +176,7 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { phoneNumber: String, token: PhoneAuthProvider.ForceResendingToken? ) { - val options = PhoneAuthOptions.newBuilder(mAuth) + val options = PhoneAuthOptions.newBuilder(auth) .setPhoneNumber(phoneNumber) // Phone number to verify .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit .setActivity(this) // Activity (for callback binding) From c5d73eaa218e3f53bebbfe3e55d05b15ef54aa1d Mon Sep 17 00:00:00 2001 From: Megha Bangalore Date: Wed, 28 Oct 2020 18:43:40 -0700 Subject: [PATCH 7/8] Update PhoneAuthActivity.kt --- .../quickstart/auth/kotlin/PhoneAuthActivity.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt index a60d1cc45..c1b1b9c01 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt @@ -156,7 +156,7 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { .setPhoneNumber(phoneNumber) // Phone number to verify .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit .setActivity(this) // Activity (for callback binding) - .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks + .setCallbacks(callbacks) // OnVerificationStateChangedCallbacks .build() PhoneAuthProvider.verifyPhoneNumber(options) // [END start_phone_auth] @@ -176,14 +176,15 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { phoneNumber: String, token: PhoneAuthProvider.ForceResendingToken? ) { - val options = PhoneAuthOptions.newBuilder(auth) + val optionsBuilder = PhoneAuthOptions.newBuilder(auth) .setPhoneNumber(phoneNumber) // Phone number to verify .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit .setActivity(this) // Activity (for callback binding) - .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks - .setForceResendingToken(token) // ForceResendingToken from callbacks - .build() - PhoneAuthProvider.verifyPhoneNumber(options) + .setCallbacks(callbacks) // OnVerificationStateChangedCallbacks + if (token != null) { + optionsBuilder.setForceResendingToken(token) // callback's ForceResendingToken + } + PhoneAuthProvider.verifyPhoneNumber(options.build()) } // [END resend_verification] From 3e7f0c2a214ac49a49b015f36cd32525a010d756 Mon Sep 17 00:00:00 2001 From: Megha Bangalore Date: Wed, 28 Oct 2020 18:48:26 -0700 Subject: [PATCH 8/8] Update PhoneAuthActivity.kt --- .../google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt index c1b1b9c01..818f1b709 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt @@ -184,7 +184,7 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { if (token != null) { optionsBuilder.setForceResendingToken(token) // callback's ForceResendingToken } - PhoneAuthProvider.verifyPhoneNumber(options.build()) + PhoneAuthProvider.verifyPhoneNumber(optionsBuilder.build()) } // [END resend_verification]