forked from GitLiveApp/firebase-kotlin-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.kt
86 lines (74 loc) · 3.6 KB
/
auth.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
*/
@file:Suppress("EXTENSION_SHADOWED_BY_MEMBER")
package dev.gitlive.firebase.auth
import dev.gitlive.firebase.Firebase
import dev.gitlive.firebase.FirebaseApp
import dev.gitlive.firebase.FirebaseException
import kotlinx.coroutines.flow.Flow
expect val Firebase.auth: FirebaseAuth
expect fun Firebase.auth(app: FirebaseApp): FirebaseAuth
expect class FirebaseAuth {
val currentUser: FirebaseUser?
val authStateChanged: Flow<FirebaseUser?>
val idTokenChanged: Flow<FirebaseUser?>
var languageCode: String
suspend fun applyActionCode(code: String)
suspend fun <T: ActionCodeResult> checkActionCode(code: String): T
suspend fun confirmPasswordReset(code: String, newPassword: String)
suspend fun createUserWithEmailAndPassword(email: String, password: String): AuthResult
suspend fun fetchSignInMethodsForEmail(email: String): List<String>
suspend fun sendPasswordResetEmail(email: String, actionCodeSettings: ActionCodeSettings? = null)
suspend fun sendSignInLinkToEmail(email: String, actionCodeSettings: ActionCodeSettings)
fun isSignInWithEmailLink(link: String): Boolean
suspend fun signInWithEmailAndPassword(email: String, password: String): AuthResult
suspend fun signInWithCustomToken(token: String): AuthResult
suspend fun signInAnonymously(): AuthResult
suspend fun signInWithCredential(authCredential: AuthCredential): AuthResult
suspend fun signInWithEmailLink(email: String, link: String): AuthResult
suspend fun signOut()
suspend fun updateCurrentUser(user: FirebaseUser)
suspend fun verifyPasswordResetCode(code: String): String
fun useEmulator(host: String, port: Int)
}
expect class AuthResult {
val user: FirebaseUser?
}
expect class AuthTokenResult {
// val authTimestamp: Long
val claims: Map<String, Any>
// val expirationTimestamp: Long
// val issuedAtTimestamp: Long
val signInProvider: String?
val token: String?
}
sealed class ActionCodeResult {
object SignInWithEmailLink : ActionCodeResult()
class PasswordReset internal constructor(val email: String) : ActionCodeResult()
class VerifyEmail internal constructor(val email: String) : ActionCodeResult()
class RecoverEmail internal constructor(val email: String, val previousEmail: String) : ActionCodeResult()
class VerifyBeforeChangeEmail internal constructor(val email: String, val previousEmail: String) : ActionCodeResult()
class RevertSecondFactorAddition internal constructor(val email: String, val multiFactorInfo: MultiFactorInfo?) : ActionCodeResult()
}
data class ActionCodeSettings(
val url: String,
val androidPackageName: AndroidPackageName? = null,
val dynamicLinkDomain: String? = null,
val canHandleCodeInApp: Boolean = false,
val iOSBundleId: String? = null
)
data class AndroidPackageName(
val packageName: String,
val installIfNotAvailable: Boolean = true,
val minimumVersion: String? = null
)
expect open class FirebaseAuthException : FirebaseException
expect class FirebaseAuthActionCodeException : FirebaseAuthException
expect class FirebaseAuthEmailException : FirebaseAuthException
expect class FirebaseAuthInvalidCredentialsException : FirebaseAuthException
expect class FirebaseAuthInvalidUserException : FirebaseAuthException
expect class FirebaseAuthMultiFactorException: FirebaseAuthException
expect class FirebaseAuthRecentLoginRequiredException : FirebaseAuthException
expect class FirebaseAuthUserCollisionException : FirebaseAuthException
expect class FirebaseAuthWebException : FirebaseAuthException