Skip to content

Commit 9d6b98b

Browse files
committed
Add phone auth and upgrade firebase and google service version
1 parent b833b0c commit 9d6b98b

6 files changed

Lines changed: 65 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Port Firebase Java SDK to Python
1111
## Usage
1212
### Android gradle project
1313
```groovy
14-
implementation 'io.github.simplejnius:sjfirebase:1.0.0'
14+
implementation 'io.github.simplejnius:sjfirebase:1.2.0'
1515
implementation 'com.google.firebase:firebase-auth'
1616
implementation 'com.google.firebase:firebase-database'
1717
implementation 'com.google.firebase:firebase-firestore'
@@ -20,7 +20,7 @@ implementation 'com.google.firebase:firebase-analytics'
2020
```
2121
### Buildozer Android project
2222
```properties
23-
android.gradle_dependencies = io.github.simplejnius:sjfirebase:1.0.0,
23+
android.gradle_dependencies = io.github.simplejnius:sjfirebase:1.2.0,
2424
com.google.firebase:firebase-auth,com.google.firebase:firebase-database,
2525
com.google.firebase:firebase-firestore,com.google.firebase:firebase-storage,
2626
com.google.firebase:firebase-analytics

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
alias(libs.plugins.detekt)
88
alias(libs.plugins.versions)
99
base
10-
id("com.google.gms.google-services") version "4.4.0" apply false
10+
id("com.google.gms.google-services") version "4.4.1" apply false
1111
}
1212

1313
allprojects {

buildSrc/src/main/java/Coordinates.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object AppCoordinates {
88
}
99

1010
object LibraryAndroidCoordinates {
11-
const val LIBRARY_VERSION = "1.1.0"
11+
const val LIBRARY_VERSION = "1.2.0"
1212
const val LIBRARY_VERSION_CODE = 1
1313
}
1414

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ android.useAndroidX=true
1919
android.enableJetifier=true
2020
# Kotlin code style for this project: "official" or "obsolete":
2121
# kotlin.code.style=official
22-
version=1.1.0
22+
version=1.2.0
2323
# kotlin.stdlib.jdk.variants.substitution=false
2424

sjfirebase/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ dependencies {
6060
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
6161
// implementation("org.jetbrains.kotlin:kotlin-reflect")
6262
// Import the BoM for the Firebase platform
63-
implementation(platform("com.google.firebase:firebase-bom:32.6.0"))
63+
implementation(platform("com.google.firebase:firebase-bom:32.8.1"))
6464

6565
// Add the dependency for the Firebase Authentication library
6666
// When using the BoM, you don't specify versions in Firebase library dependencies
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.simplejnius.sjfirebase;
2+
3+
import android.app.Activity;
4+
5+
import androidx.annotation.NonNull;
6+
7+
import com.google.firebase.auth.FirebaseAuth;
8+
import com.google.firebase.auth.PhoneAuthCredential;
9+
import com.google.firebase.auth.PhoneAuthOptions;
10+
import com.google.firebase.auth.PhoneAuthProvider;
11+
import com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks;
12+
13+
import java.util.concurrent.TimeUnit;
14+
15+
public class SJFirebaseAuthPhone {
16+
private static final String TAG = "AuthPhone";
17+
private static FirebaseAuth m_auth;
18+
19+
public static FirebaseAuth get_instance() {
20+
m_auth = FirebaseAuth.getInstance();
21+
return m_auth;
22+
}
23+
public static void startPhoneNumberVerification(
24+
String phone_number,
25+
Long timeout,
26+
@NonNull Activity activity,
27+
OnVerificationStateChangedCallbacks callbacks
28+
) {
29+
PhoneAuthOptions options = PhoneAuthOptions.newBuilder(get_instance())
30+
.setPhoneNumber(phone_number)
31+
.setTimeout(timeout, TimeUnit.SECONDS)
32+
.setActivity(activity)
33+
.setCallbacks(callbacks)
34+
.build();
35+
PhoneAuthProvider.verifyPhoneNumber(options);
36+
37+
}
38+
39+
public static void resendVerificationCode(
40+
String phone_number,
41+
Long timeout,
42+
@NonNull Activity activity,
43+
OnVerificationStateChangedCallbacks callbacks,
44+
PhoneAuthProvider.ForceResendingToken token
45+
) {
46+
PhoneAuthOptions options = PhoneAuthOptions.newBuilder(get_instance())
47+
.setPhoneNumber(phone_number)
48+
.setTimeout(timeout, TimeUnit.SECONDS)
49+
.setActivity(activity)
50+
.setCallbacks(callbacks)
51+
.setForceResendingToken(token)
52+
.build();
53+
PhoneAuthProvider.verifyPhoneNumber(options);
54+
}
55+
56+
private PhoneAuthCredential verifyPhoneNumberWithCode(String verificationId, String code) {
57+
return PhoneAuthProvider.getCredential(verificationId, code);
58+
}
59+
}

0 commit comments

Comments
 (0)