Skip to content

Increase auth coverage #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f283697
Update FirebaseCore.def
avdyushin Aug 5, 2020
381f2f7
Adding missing Auth calls
Daeda88 Aug 10, 2020
f8e0884
Add iOS implementation
Daeda88 Aug 11, 2020
9263267
Add providers
Daeda88 Aug 12, 2020
6abae5b
Trying to resolve Firestore issues
Daeda88 Aug 12, 2020
6406b52
Merge branch 'upgrade_firebase_sdk' into increase_auth_coverage
Daeda88 Aug 14, 2020
aabd62b
Added iOS methods
Daeda88 Aug 14, 2020
1226c1c
Add Javascript
Daeda88 Aug 18, 2020
f8777aa
Cleaned up .def files
Daeda88 Aug 18, 2020
32814a1
Add Test
Daeda88 Aug 19, 2020
d46ae84
Fixed compile for tests
Daeda88 Aug 19, 2020
cc3b359
Merge branch 'upgrade_firebase_sdk' into increase_auth_coverage
Daeda88 Aug 19, 2020
58c866d
Add missing firetore frameworks
Daeda88 Aug 19, 2020
cdd58bd
Merge branch 'upgrade_firebase_sdk' into increase_auth_coverage
Daeda88 Aug 19, 2020
6dc7a47
Account for nullable results
Daeda88 Aug 20, 2020
138dd4c
Use Carthage instead of zip for linking.
Daeda88 Aug 21, 2020
9fa36c2
Track firestore version
Daeda88 Aug 21, 2020
cd5ea0a
Merge branch 'upgrade_firebase_sdk' into increase_auth_coverage
Daeda88 Aug 21, 2020
a821235
Merge remote-tracking branch 'GitLiveApp/master' into upgrade_firebas…
Daeda88 Aug 21, 2020
f3fe3db
Update yaml
Daeda88 Aug 21, 2020
d498d87
Merge branch 'upgrade_firebase_sdk' into increase_auth_coverage
Daeda88 Aug 21, 2020
64621ce
Remove useless podspec
Daeda88 Aug 21, 2020
1f36fe2
Code cleanup
Daeda88 Aug 21, 2020
9fdccc1
Merge branch 'upgrade_firebase_sdk' into increase_auth_coverage
Daeda88 Aug 21, 2020
b9e5542
Merge remote-tracking branch 'GitLiveApp/master' into increase_auth_c…
Daeda88 Aug 24, 2020
7de88af
Merge remote-tracking branch 'GitLiveApp/master' into increase_auth_c…
Daeda88 Oct 5, 2020
dcbe856
Fixing remarks
Daeda88 Oct 7, 2020
bcf4fe5
Move ActionData into operator
Daeda88 Oct 7, 2020
8ba54ae
fix test
Daeda88 Oct 7, 2020
5a215b3
Revert passing a Sealed class to credentials.
nbransby Oct 20, 2020
826f1b3
make ActionCodeSettings a data class
nbransby Oct 20, 2020
151571d
Revert "fix test"
nbransby Oct 20, 2020
295b2a7
simplify fetchSignInMethodsForEmail by removing SignInMethodQueryResult
nbransby Oct 20, 2020
06f3ada
Merge branch 'master' into increase_auth_coverage
nbransby Oct 20, 2020
a4af2d0
Added fix to script.
Reedyuk Oct 20, 2020
823ab90
Adjusted script
Reedyuk Oct 20, 2020
5211edb
Added check of homebrew.
Reedyuk Oct 20, 2020
45ae540
Removed brew install due to being already installed on github machines.
Reedyuk Oct 20, 2020
e224920
rename all credentialWithX functions to just credential
nbransby Oct 20, 2020
9e3be34
remove awaitExpectedResult
nbransby Oct 20, 2020
74c13fc
finish ios auth fixes
nbransby Oct 21, 2020
88ac9c0
Merge branch 'master' into increase_auth_coverage
nbransby Oct 21, 2020
57e3fe5
Update README.md
nbransby Oct 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ jobs:
arguments: :updateVersions
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Install Homebrew
run: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- name: Install Carthage
run: brew install carthage
- name: Publish
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ jobs:
java-version: 1.8
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Install Homebrew
run: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- name: Install Carthage
run: brew install carthage
- name: Assemble
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ The following libraries are available for the various Firebase products.

| Service or Product | Gradle Dependency | API Coverage |
| ------------------------------------------------------------------------------------ | :-----------------------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Authentication](https://firebase.google.com/docs/auth#kotlin-android) | [`dev.gitlive:firebase-auth:0.2.0`](https://search.maven.org/artifact/dev.gitlive/firebase-auth/0.2.0/pom) | [![40%](https://img.shields.io/badge/-50%25-red?style=flat-square)](/firebase-auth/src/commonMain/kotlin/dev/gitlive/firebase/auth/auth.kt) |
| [Realtime Database](https://firebase.google.com/docs/database#kotlin-android) | [`dev.gitlive:firebase-database:0.2.0`](https://search.maven.org/artifact/dev.gitlive/firebase-database/0.2.0/pom) | [![70%](https://img.shields.io/badge/-70%25-orange?style=flat-square)](/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt) |
| [Cloud Firestore](https://firebase.google.com/docs/firestore#kotlin-android) | [`dev.gitlive:firebase-firestore:0.2.0`](https://search.maven.org/artifact/dev.gitlive/firebase-firestore/0.2.0/pom) | [![60%](https://img.shields.io/badge/-60%25-orange?style=flat-square)](/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt) |
| [Cloud Functions](https://firebase.google.com/docs/functions/callable#kotlin-android)| [`dev.gitlive:firebase-functions:0.2.0`](https://search.maven.org/artifact/dev.gitlive/firebase-functions/0.2.0/pom) | [![80%](https://img.shields.io/badge/-80%25-green?style=flat-square)](/firebase-functions/src/commonMain/kotlin/dev/gitlive/firebase/functions/functions.kt) |
| [Cloud Messaging](https://firebase.google.com/docs/messaging#kotlin-android) | [`dev.gitlive:firebase-messaging:0.2.0`](https://search.maven.org/artifact/dev.gitlive/firebase-messaging/0.2.0/pom) | ![0%](https://img.shields.io/badge/-0%25-lightgrey?style=flat-square) |
| [Cloud Storage](https://firebase.google.com/docs/storage#kotlin-android) | [`dev.gitlive:firebase-storage:0.2.0`](https://search.maven.org/artifact/dev.gitlive/firebase-storage/0.2.0/pom) | ![0%](https://img.shields.io/badge/-0%25-lightgrey?style=flat-square) |
| [Authentication](https://firebase.google.com/docs/auth#kotlin-android) | [`dev.gitlive:firebase-auth:0.4.0`](https://search.maven.org/artifact/dev.gitlive/firebase-auth/0.4.0/pom) | [![80%](https://img.shields.io/badge/-80%25-green?style=flat-square)](/firebase-auth/src/commonMain/kotlin/dev/gitlive/firebase/auth/auth.kt) |
| [Realtime Database](https://firebase.google.com/docs/database#kotlin-android) | [`dev.gitlive:firebase-database:0.4.0`](https://search.maven.org/artifact/dev.gitlive/firebase-database/0.4.0/pom) | [![70%](https://img.shields.io/badge/-70%25-orange?style=flat-square)](/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt) |
| [Cloud Firestore](https://firebase.google.com/docs/firestore#kotlin-android) | [`dev.gitlive:firebase-firestore:0.4.0`](https://search.maven.org/artifact/dev.gitlive/firebase-firestore/0.4.0/pom) | [![60%](https://img.shields.io/badge/-60%25-orange?style=flat-square)](/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt) |
| [Cloud Functions](https://firebase.google.com/docs/functions/callable#kotlin-android)| [`dev.gitlive:firebase-functions:0.4.0`](https://search.maven.org/artifact/dev.gitlive/firebase-functions/0.4.0/pom) | [![80%](https://img.shields.io/badge/-80%25-green?style=flat-square)](/firebase-functions/src/commonMain/kotlin/dev/gitlive/firebase/functions/functions.kt) |
| [Cloud Messaging](https://firebase.google.com/docs/messaging#kotlin-android) | [`dev.gitlive:firebase-messaging:0.4.0`](https://search.maven.org/artifact/dev.gitlive/firebase-messaging/0.4.0/pom) | ![0%](https://img.shields.io/badge/-0%25-lightgrey?style=flat-square) |
| [Cloud Storage](https://firebase.google.com/docs/storage#kotlin-android) | [`dev.gitlive:firebase-storage:0.4.0`](https://search.maven.org/artifact/dev.gitlive/firebase-storage/0.4.0/pom) | ![0%](https://img.shields.io/badge/-0%25-lightgrey?style=flat-square) |

Is the Firebase library or API you need missing? [Create an issue](https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/new?labels=API+coverage&template=increase-api-coverage.md&title=Add+%5Bclass+name%5D.%5Bfunction+name%5D+to+%5Blibrary+name%5D+for+%5Bplatform+names%5D) to request additional API coverage or be awesome and [submit a PR](https://github.com/GitLiveApp/firebase-kotlin-sdk/fork)

Expand Down Expand Up @@ -138,12 +138,12 @@ If you are building a Kotlin multiplatform library which will be consumed from J

```json
"dependencies": {
"@gitlive/firebase-auth": "0.2.0",
"@gitlive/firebase-database": "0.2.0",
"@gitlive/firebase-firestore": "0.2.0",
"@gitlive/firebase-functions": "0.2.0",
"@gitlive/firebase-storage": "0.2.0",
"@gitlive/firebase-messaging": "0.2.0"
"@gitlive/firebase-auth": "0.4.0",
"@gitlive/firebase-database": "0.4.0",
"@gitlive/firebase-firestore": "0.4.0",
"@gitlive/firebase-functions": "0.4.0",
"@gitlive/firebase-storage": "0.4.0",
"@gitlive/firebase-messaging": "0.4.0"
}
```

Expand Down
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ subprojects {


tasks.withType<Sign>().configureEach {
onlyIf { !project.gradle.startParameter.taskNames.contains("publishToMavenLocal")
}
onlyIf { !project.gradle.startParameter.taskNames.contains("publishToMavenLocal") }
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package dev.gitlive.firebase.auth

import com.google.firebase.auth.ActionCodeEmailInfo
import com.google.firebase.auth.ActionCodeMultiFactorInfo
import com.google.firebase.auth.ActionCodeResult.*
import com.google.firebase.auth.FirebaseAuth.AuthStateListener
import dev.gitlive.firebase.Firebase
import dev.gitlive.firebase.FirebaseApp
Expand Down Expand Up @@ -43,19 +44,18 @@ actual class FirebaseAuth internal constructor(val android: com.google.firebase.
set(value) { android.setLanguageCode(value) }

actual suspend fun applyActionCode(code: String) = android.applyActionCode(code).await().run { Unit }
actual suspend fun checkActionCode(code: String): ActionCodeResult = ActionCodeResult(android.checkActionCode(code).await())
actual suspend fun confirmPasswordReset(code: String, newPassword: String) = android.confirmPasswordReset(code, newPassword).await().run { Unit }

actual suspend fun createUserWithEmailAndPassword(email: String, password: String) =
AuthResult(android.createUserWithEmailAndPassword(email, password).await())

actual suspend fun fetchSignInMethodsForEmail(email: String): SignInMethodQueryResult = SignInMethodQueryResult(android.fetchSignInMethodsForEmail(email).await())
actual suspend fun fetchSignInMethodsForEmail(email: String): List<String> = android.fetchSignInMethodsForEmail(email).await().signInMethods.orEmpty()

actual suspend fun sendPasswordResetEmail(email: String, actionCodeSettings: ActionCodeSettings?) {
android.sendPasswordResetEmail(email, actionCodeSettings?.android).await()
android.sendPasswordResetEmail(email, actionCodeSettings?.toAndroid()).await()
}

actual suspend fun sendSignInLinkToEmail(email: String, actionCodeSettings: ActionCodeSettings) = android.sendSignInLinkToEmail(email, actionCodeSettings.android).await().run { Unit }
actual suspend fun sendSignInLinkToEmail(email: String, actionCodeSettings: ActionCodeSettings) = android.sendSignInLinkToEmail(email, actionCodeSettings.toAndroid()).await().run { Unit }

actual suspend fun signInWithEmailAndPassword(email: String, password: String) =
AuthResult(android.signInWithEmailAndPassword(email, password).await())
Expand All @@ -72,75 +72,42 @@ actual class FirebaseAuth internal constructor(val android: com.google.firebase.

actual suspend fun updateCurrentUser(user: FirebaseUser) = android.updateCurrentUser(user.android).await().run { Unit }
actual suspend fun verifyPasswordResetCode(code: String): String = android.verifyPasswordResetCode(code).await()

actual suspend fun <T : ActionCodeResult> checkActionCode(code: String): T {
val result = android.checkActionCode(code).await()
@Suppress("UNCHECKED_CAST")
return when(result.operation) {
ERROR -> ActionCodeResult.Error
SIGN_IN_WITH_EMAIL_LINK -> ActionCodeResult.SignInWithEmailLink
VERIFY_EMAIL -> ActionCodeResult.VerifyEmail(result.info!!.email)
PASSWORD_RESET -> ActionCodeResult.PasswordReset(result.info!!.email)
RECOVER_EMAIL -> (result.info as ActionCodeEmailInfo).run {
ActionCodeResult.RecoverEmail(email, previousEmail)
}
VERIFY_BEFORE_CHANGE_EMAIL -> (result.info as ActionCodeEmailInfo).run {
ActionCodeResult.VerifyBeforeChangeEmail(email, previousEmail)
}
REVERT_SECOND_FACTOR_ADDITION -> (result.info as ActionCodeMultiFactorInfo).run {
ActionCodeResult.RevertSecondFactorAddition(email, MultiFactorInfo(multiFactorInfo))
}
else -> throw UnsupportedOperationException(result.operation.toString())
} as T
}

}

actual class AuthResult internal constructor(val android: com.google.firebase.auth.AuthResult) {
actual val user: FirebaseUser?
get() = android.user?.let { FirebaseUser(it) }
}

actual class ActionCodeResult(val android: com.google.firebase.auth.ActionCodeResult) {
actual val operation: Operation
get() = when (android.operation) {
com.google.firebase.auth.ActionCodeResult.PASSWORD_RESET -> Operation.PasswordReset(this)
com.google.firebase.auth.ActionCodeResult.VERIFY_EMAIL -> Operation.VerifyEmail(this)
com.google.firebase.auth.ActionCodeResult.RECOVER_EMAIL -> Operation.RecoverEmail(this)
com.google.firebase.auth.ActionCodeResult.ERROR -> Operation.Error
com.google.firebase.auth.ActionCodeResult.SIGN_IN_WITH_EMAIL_LINK -> Operation.SignInWithEmailLink
com.google.firebase.auth.ActionCodeResult.VERIFY_BEFORE_CHANGE_EMAIL -> Operation.VerifyBeforeChangeEmail(this)
com.google.firebase.auth.ActionCodeResult.REVERT_SECOND_FACTOR_ADDITION -> Operation.RevertSecondFactorAddition(this)
else -> Operation.Error
}
}

internal actual sealed class ActionCodeDataType<out T> {

actual abstract fun dataForResult(result: ActionCodeResult): T

actual object Email : ActionCodeDataType<String>() {
override fun dataForResult(result: ActionCodeResult): String = result.android.info!!.email
}
actual object PreviousEmail : ActionCodeDataType<String>() {
override fun dataForResult(result: ActionCodeResult): String = (result.android.info as ActionCodeEmailInfo).previousEmail
}
actual object MultiFactor : ActionCodeDataType<MultiFactorInfo?>() {
override fun dataForResult(result: ActionCodeResult): MultiFactorInfo? = (result.android.info as? ActionCodeMultiFactorInfo)?.multiFactorInfo?.let { MultiFactorInfo(it) }
}
}

actual class SignInMethodQueryResult(val android: com.google.firebase.auth.SignInMethodQueryResult) {
actual val signInMethods: List<String>
get() = android.signInMethods ?: emptyList()
}

actual class ActionCodeSettings private constructor(val android: com.google.firebase.auth.ActionCodeSettings) {

actual constructor(url: String,
androidPackageName: AndroidPackageName?,
dynamicLinkDomain: String?,
canHandleCodeInApp: Boolean,
iOSBundleId: String?
) : this(com.google.firebase.auth.ActionCodeSettings.newBuilder().apply {
this.url = url
androidPackageName?.let {
this.setAndroidPackageName(it.androidPackageName, it.installIfNotAvailable, it.minimumVersion)
}
this.dynamicLinkDomain = dynamicLinkDomain
this.handleCodeInApp = canHandleCodeInApp
this.iosBundleId = iosBundleId
}.build())

actual val canHandleCodeInApp: Boolean
get() = android.canHandleCodeInApp()
actual val androidPackageName: AndroidPackageName?
get() = android.androidPackageName?.let {
AndroidPackageName(it, android.androidInstallApp, android.androidMinimumVersion)
}
actual val iOSBundle: String?
get() = android.iosBundle
actual val url: String
get() = android.url
}
internal fun ActionCodeSettings.toAndroid() = com.google.firebase.auth.ActionCodeSettings.newBuilder()
.setUrl(url)
.also { androidPackageName?.run { it.setAndroidPackageName(packageName, installIfNotAvailable, minimumVersion) } }
.also { dynamicLinkDomain?.run { it.setDynamicLinkDomain(this) } }
.setHandleCodeInApp(canHandleCodeInApp)
.also { iOSBundleId?.run { it.setIOSBundleId(this) } }
.build()

actual typealias FirebaseAuthException = com.google.firebase.auth.FirebaseAuthException
actual typealias FirebaseAuthActionCodeException = com.google.firebase.auth.FirebaseAuthActionCodeException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package dev.gitlive.firebase.auth

import android.app.Activity
import com.google.firebase.FirebaseException
import com.google.firebase.auth.OAuthProvider
import com.google.firebase.auth.PhoneAuthProvider
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.coroutineScope
Expand Down Expand Up @@ -45,24 +46,12 @@ actual class OAuthProvider(val android: com.google.firebase.auth.OAuthProvider.B
actual constructor(provider: String, auth: FirebaseAuth) : this(com.google.firebase.auth.OAuthProvider.newBuilder(provider, auth.android), auth)

actual companion object {
actual fun credentials(type: OAuthCredentialsType): AuthCredential {
val credential = com.google.firebase.auth.OAuthProvider.newCredentialBuilder(type.providerId).apply {
when (type) {
is OAuthCredentialsType.AccessToken -> accessToken = type.accessToken
is OAuthCredentialsType.IdAndAccessToken -> {
accessToken = type.accessToken
setIdToken(type.idToken)
}
is OAuthCredentialsType.IdAndAccessTokenAndRawNonce -> {
accessToken = type.accessToken
setIdTokenWithRawNonce(type.idToken, type.rawNonce)
}
is OAuthCredentialsType.IdTokenAndRawNonce -> {
setIdTokenWithRawNonce(type.idToken, type.rawNonce)
}
}
}.build()
return (credential as? com.google.firebase.auth.OAuthCredential)?.let { OAuthCredential(it) } ?: AuthCredential(credential)
actual fun credential(providerId: String, accessToken: String?, idToken: String?, rawNonce: String?): OAuthCredential {
val builder = OAuthProvider.newCredentialBuilder(providerId)
accessToken?.let { builder.accessToken = it }
idToken?.let { builder.idToken = it }
rawNonce?.let { builder.setIdTokenWithRawNonce(idToken!!, it) }
return OAuthCredential(builder.build() as com.google.firebase.auth.OAuthCredential)
}
}

Expand Down Expand Up @@ -99,9 +88,7 @@ actual class PhoneAuthProvider(val android: com.google.firebase.auth.PhoneAuthPr
launch {
val code = verificationProvider.getVerificationCode()
try {
val credentials =
credential(verificationId, code)
response.complete(Result.success(credentials))
response.complete(Result.success(credential(verificationId, code)))
} catch (e: Exception) {
response.complete(Result.failure(e))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ actual class FirebaseUser internal constructor(val android: com.google.firebase.
actual suspend fun reauthenticate(credential: AuthCredential) = android.reauthenticate(credential.android).await().run { Unit }
actual suspend fun reauthenticateAndRetrieveData(credential: AuthCredential): AuthResult = AuthResult(android.reauthenticateAndRetrieveData(credential.android).await())
actual suspend fun sendEmailVerification(actionCodeSettings: ActionCodeSettings?) {
val request = actionCodeSettings?.android?.let { android.sendEmailVerification(it) } ?: android.sendEmailVerification()
request.await().run { Unit }
val request = actionCodeSettings?.let { android.sendEmailVerification(it.toAndroid()) } ?: android.sendEmailVerification()
request.await()
}
actual suspend fun unlink(provider: String): FirebaseUser? = android.unlink(provider).await().user?.let { FirebaseUser(it) }
actual suspend fun updateEmail(email: String) = android.updateEmail(email).await().run { Unit }
Expand All @@ -52,7 +52,8 @@ actual class FirebaseUser internal constructor(val android: com.google.firebase.
}.build()
android.updateProfile(request).await()
}
actual suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings?) = android.verifyBeforeUpdateEmail(newEmail, actionCodeSettings?.android).await().run { Unit }
actual suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings?) =
android.verifyBeforeUpdateEmail(newEmail, actionCodeSettings?.toAndroid()).await().run { Unit }
}

actual class UserInfo(val android: com.google.firebase.auth.UserInfo) {
Expand Down
Loading