Skip to content

Commit 404d1f1

Browse files
committed
rebase and merge GitLiveApp#729 with auth support
1 parent c815eee commit 404d1f1

File tree

78 files changed

+889
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+889
-187
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This is a (temporary?) fork with the following merged upstream pull requests, up
1717
### Pull Requests
1818

1919
- https://github.com/GitLiveApp/firebase-kotlin-sdk/pull/738
20+
- https://github.com/GitLiveApp/firebase-kotlin-sdk/pull/729
2021
- https://github.com/GitLiveApp/firebase-kotlin-sdk/pull/698
2122

2223
### Firebase SDK

firebase-analytics/build.gradle.kts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,15 @@ kotlin {
105105
iosArm64()
106106
iosX64()
107107
iosSimulatorArm64()
108+
tvosArm64()
109+
tvosX64()
110+
tvosSimulatorArm64()
111+
macosArm64()
112+
macosX64()
108113
cocoapods {
109114
ios.deploymentTarget = libs.versions.ios.deploymentTarget.get()
115+
tvos.deploymentTarget = libs.versions.tvos.deploymentTarget.get()
116+
osx.deploymentTarget = libs.versions.macos.deploymentTarget.get()
110117
framework {
111118
baseName = "FirebaseAnalytics"
112119
}
@@ -140,7 +147,11 @@ kotlin {
140147
all {
141148
languageSettings.apply {
142149
progressiveMode = true
143-
if (name.lowercase().contains("ios")) {
150+
if (name.lowercase().contains("ios")
151+
|| name.lowercase().contains("apple")
152+
|| name.lowercase().contains("tvos")
153+
|| name.lowercase().contains("macos")
154+
) {
144155
optIn("kotlinx.cinterop.ExperimentalForeignApi")
145156
}
146157
}

firebase-app/build.gradle.kts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,16 @@ kotlin {
106106
iosArm64()
107107
iosX64()
108108
iosSimulatorArm64()
109+
tvosArm64()
110+
tvosX64()
111+
tvosSimulatorArm64()
112+
macosArm64()
113+
macosX64()
109114

110115
cocoapods {
111116
ios.deploymentTarget = libs.versions.ios.deploymentTarget.get()
117+
tvos.deploymentTarget = libs.versions.tvos.deploymentTarget.get()
118+
osx.deploymentTarget = libs.versions.macos.deploymentTarget.get()
112119
framework {
113120
baseName = "FirebaseApp"
114121
}
@@ -142,7 +149,11 @@ kotlin {
142149
all {
143150
languageSettings.apply {
144151
progressiveMode = true
145-
if (name.lowercase().contains("ios")) {
152+
if (name.lowercase().contains("ios")
153+
|| name.lowercase().contains("apple")
154+
|| name.lowercase().contains("tvos")
155+
|| name.lowercase().contains("macos")
156+
) {
146157
optIn("kotlinx.cinterop.ExperimentalForeignApi")
147158
}
148159
}

firebase-auth/build.gradle.kts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,15 @@ kotlin {
106106
iosArm64()
107107
iosX64().enableKeychainForTests()
108108
iosSimulatorArm64().enableKeychainForTests()
109+
tvosArm64()
110+
tvosX64()
111+
tvosSimulatorArm64()
112+
macosArm64()
113+
macosX64()
109114
cocoapods {
110115
ios.deploymentTarget = libs.versions.ios.deploymentTarget.get()
116+
tvos.deploymentTarget = libs.versions.tvos.deploymentTarget.get()
117+
osx.deploymentTarget = libs.versions.macos.deploymentTarget.get()
111118
framework {
112119
baseName = "FirebaseAuth"
113120
}
@@ -142,7 +149,11 @@ kotlin {
142149
languageSettings.apply {
143150
progressiveMode = true
144151
optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
145-
if (name.lowercase().contains("ios")) {
152+
if (name.lowercase().contains("ios")
153+
|| name.lowercase().contains("apple")
154+
|| name.lowercase().contains("tvos")
155+
|| name.lowercase().contains("macos")
156+
) {
146157
optIn("kotlinx.cinterop.ExperimentalForeignApi")
147158
optIn("kotlinx.cinterop.BetaInteropApi")
148159
}

firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/auth.kt renamed to firebase-auth/src/appleMain/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -19,92 +19,6 @@ import platform.Foundation.NSError
1919
import platform.Foundation.NSString
2020
import platform.Foundation.NSURL
2121

22-
public actual val Firebase.auth: FirebaseAuth
23-
get() = FirebaseAuth(FIRAuth.auth())
24-
25-
public actual fun Firebase.auth(app: FirebaseApp): FirebaseAuth = FirebaseAuth(
26-
FIRAuth.authWithApp(app.ios as objcnames.classes.FIRApp),
27-
)
28-
29-
public actual class FirebaseAuth internal constructor(public val ios: FIRAuth) {
30-
31-
public actual val currentUser: FirebaseUser?
32-
get() = ios.currentUser()?.let { FirebaseUser(it) }
33-
34-
public actual val authStateChanged: Flow<FirebaseUser?> get() = callbackFlow {
35-
val handle = ios.addAuthStateDidChangeListener { _, user -> trySend(user?.let { FirebaseUser(it) }) }
36-
awaitClose { ios.removeAuthStateDidChangeListener(handle) }
37-
}
38-
39-
public actual val idTokenChanged: Flow<FirebaseUser?> get() = callbackFlow {
40-
val handle = ios.addIDTokenDidChangeListener { _, user -> trySend(user?.let { FirebaseUser(it) }) }
41-
awaitClose { ios.removeIDTokenDidChangeListener(handle) }
42-
}
43-
44-
public actual var languageCode: String
45-
get() = ios.languageCode() ?: ""
46-
set(value) {
47-
ios.setLanguageCode(value)
48-
}
49-
50-
public actual suspend fun applyActionCode(code: String): Unit = ios.await { applyActionCode(code, it) }
51-
public actual suspend fun confirmPasswordReset(code: String, newPassword: String): Unit = ios.await { confirmPasswordResetWithCode(code, newPassword, it) }
52-
53-
public actual suspend fun createUserWithEmailAndPassword(email: String, password: String): AuthResult = AuthResult(ios.awaitResult { createUserWithEmail(email = email, password = password, completion = it) })
54-
55-
@Suppress("UNCHECKED_CAST")
56-
public actual suspend fun fetchSignInMethodsForEmail(email: String): List<String> = ios.awaitResult<FIRAuth, List<*>?> { fetchSignInMethodsForEmail(email, it) }.orEmpty() as List<String>
57-
58-
public actual suspend fun sendPasswordResetEmail(email: String, actionCodeSettings: ActionCodeSettings?) {
59-
ios.await { actionCodeSettings?.let { actionSettings -> sendPasswordResetWithEmail(email, actionSettings.toIos(), it) } ?: sendPasswordResetWithEmail(email = email, completion = it) }
60-
}
61-
62-
public actual suspend fun sendSignInLinkToEmail(email: String, actionCodeSettings: ActionCodeSettings): Unit = ios.await { sendSignInLinkToEmail(email, actionCodeSettings.toIos(), it) }
63-
64-
public actual fun isSignInWithEmailLink(link: String): Boolean = ios.isSignInWithEmailLink(link)
65-
66-
public actual suspend fun signInWithEmailAndPassword(email: String, password: String): AuthResult = AuthResult(ios.awaitResult { signInWithEmail(email = email, password = password, completion = it) })
67-
68-
public actual suspend fun signInWithCustomToken(token: String): AuthResult = AuthResult(ios.awaitResult { signInWithCustomToken(token, it) })
69-
70-
public actual suspend fun signInAnonymously(): AuthResult = AuthResult(ios.awaitResult { signInAnonymouslyWithCompletion(it) })
71-
72-
public actual suspend fun signInWithCredential(authCredential: AuthCredential): AuthResult = AuthResult(ios.awaitResult { signInWithCredential(authCredential.ios, it) })
73-
74-
public actual suspend fun signInWithEmailLink(email: String, link: String): AuthResult = AuthResult(ios.awaitResult { signInWithEmail(email = email, link = link, completion = it) })
75-
76-
public actual suspend fun signOut(): Unit = ios.throwError { signOut(it) }
77-
78-
public actual suspend fun updateCurrentUser(user: FirebaseUser): Unit = ios.await { updateCurrentUser(user.ios, it) }
79-
public actual suspend fun verifyPasswordResetCode(code: String): String = ios.awaitResult { verifyPasswordResetCode(code, it) }
80-
81-
public actual suspend fun <T : ActionCodeResult> checkActionCode(code: String): T {
82-
val result: FIRActionCodeInfo = ios.awaitResult { checkActionCode(code, it) }
83-
@Suppress("UNCHECKED_CAST")
84-
return when (result.operation()) {
85-
FIRActionCodeOperationEmailLink -> SignInWithEmailLink
86-
FIRActionCodeOperationVerifyEmail -> VerifyEmail(result.email())
87-
FIRActionCodeOperationPasswordReset -> PasswordReset(result.email())
88-
FIRActionCodeOperationRecoverEmail -> RecoverEmail(result.email(), result.previousEmail()!!)
89-
FIRActionCodeOperationVerifyAndChangeEmail -> VerifyBeforeChangeEmail(result.email(), result.previousEmail()!!)
90-
FIRActionCodeOperationRevertSecondFactorAddition -> RevertSecondFactorAddition(result.email(), null)
91-
FIRActionCodeOperationUnknown -> throw UnsupportedOperationException(result.operation().toString())
92-
else -> throw UnsupportedOperationException(result.operation().toString())
93-
} as T
94-
}
95-
96-
public actual fun useEmulator(host: String, port: Int): Unit = ios.useEmulatorWithHost(host, port.toLong())
97-
}
98-
99-
public actual class AuthResult(public val ios: FIRAuthDataResult) {
100-
public actual val user: FirebaseUser?
101-
get() = FirebaseUser(ios.user())
102-
public actual val credential: AuthCredential?
103-
get() = ios.credential()?.let { AuthCredential(it) }
104-
public actual val additionalUserInfo: AdditionalUserInfo?
105-
get() = ios.additionalUserInfo()?.let { AdditionalUserInfo(it) }
106-
}
107-
10822
public actual class AdditionalUserInfo(
10923
public val ios: FIRAdditionalUserInfo,
11024
) {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.gitlive.firebase.auth
6+
7+
import cocoapods.FirebaseAuth.*
8+
9+
public actual open class AuthCredential(public open val ios: FIRAuthCredential) {
10+
public actual val providerId: String
11+
get() = ios.provider()
12+
}
13+
14+
public actual class PhoneAuthCredential(override val ios: FIRPhoneAuthCredential) : AuthCredential(ios)
15+
public actual class OAuthCredential(override val ios: FIROAuthCredential) : AuthCredential(ios)
16+
17+
public actual object EmailAuthProvider {
18+
public actual fun credential(
19+
email: String,
20+
password: String,
21+
): AuthCredential = AuthCredential(FIREmailAuthProvider.credentialWithEmail(email = email, password = password))
22+
23+
public actual fun credentialWithLink(
24+
email: String,
25+
emailLink: String,
26+
): AuthCredential = AuthCredential(FIREmailAuthProvider.credentialWithEmail(email = email, link = emailLink))
27+
}
28+
29+
public actual object FacebookAuthProvider {
30+
public actual fun credential(accessToken: String): AuthCredential = AuthCredential(FIRFacebookAuthProvider.credentialWithAccessToken(accessToken))
31+
}
32+
33+
public actual object GithubAuthProvider {
34+
public actual fun credential(token: String): AuthCredential = AuthCredential(FIRGitHubAuthProvider.credentialWithToken(token))
35+
}
36+
37+
public actual object GoogleAuthProvider {
38+
public actual fun credential(idToken: String?, accessToken: String?): AuthCredential {
39+
requireNotNull(idToken) { "idToken must not be null" }
40+
requireNotNull(accessToken) { "accessToken must not be null" }
41+
return AuthCredential(FIRGoogleAuthProvider.credentialWithIDToken(idToken, accessToken))
42+
}
43+
}
44+
45+
public actual object TwitterAuthProvider {
46+
public actual fun credential(token: String, secret: String): AuthCredential = AuthCredential(FIRTwitterAuthProvider.credentialWithToken(token, secret))
47+
}

0 commit comments

Comments
 (0)