Skip to content

Commit 6ee896e

Browse files
committed
Master merge
1 parent 740c5b4 commit 6ee896e

File tree

2 files changed

+10
-126
lines changed

2 files changed

+10
-126
lines changed

src/main/java/com/google/firebase/auth/FirebaseAuth.kt

Lines changed: 9 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,10 @@ class FirebaseUserImpl internal constructor(
9696
jsonParser
9797
.parseToJsonElement(String(Base64.getUrlDecoder().decode(idToken.split(".")[1])))
9898
.jsonObject
99-
.run { value as Map<String, Any?>? }
99+
.run { value as? Map<String, Any?>? }
100100
.orEmpty()
101101
}
102102

103-
<<<<<<< HEAD
104-
val JsonElement.value get(): Any? = when (this) {
105-
is JsonNull -> null
106-
is JsonArray -> map { it.value }
107-
is JsonObject -> jsonObject.mapValues { (_, it) -> it.value }
108-
is JsonPrimitive -> booleanOrNull ?: doubleOrNull ?: content
109-
else -> TODO()
110-
}
111-
=======
112103
internal val JsonElement.value get(): Any? =
113104
when (this) {
114105
is JsonNull -> null
@@ -117,7 +108,6 @@ class FirebaseUserImpl internal constructor(
117108
is JsonPrimitive -> booleanOrNull ?: doubleOrNull ?: content
118109
else -> TODO()
119110
}
120-
>>>>>>> 25efe1c (ktlint formatting + update of user data after signInWithCustomToken + photoUrl and displayName implementation)
121111

122112
override fun delete(): Task<Void> {
123113
val source = TaskCompletionSource<Void>()
@@ -261,19 +251,10 @@ class FirebaseAuth constructor(
261251
setResult: (responseBody: String) -> FirebaseUserImpl?,
262252
): TaskCompletionSource<AuthResult> {
263253
val source = TaskCompletionSource<AuthResult>()
264-
<<<<<<< HEAD
265254
val request = Request.Builder()
266255
.url(urlFactory.buildUrl(url))
267256
.post(body)
268257
.build()
269-
=======
270-
val request =
271-
Request
272-
.Builder()
273-
.url(urlFactory.buildUrl(url))
274-
.post(body)
275-
.build()
276-
>>>>>>> 25efe1c (ktlint formatting + update of user data after signInWithCustomToken + photoUrl and displayName implementation)
277258

278259
client.newCall(request).enqueue(
279260
object : Callback {
@@ -284,26 +265,12 @@ class FirebaseAuth constructor(
284265
source.setException(FirebaseException(e.toString(), e))
285266
}
286267

287-
<<<<<<< HEAD
288-
@Throws(IOException::class)
289-
override fun onResponse(call: Call, response: Response) {
290-
if (!response.isSuccessful) {
291-
source.setException(
292-
createAuthInvalidUserException("accounts", request, response)
293-
)
294-
} else {
295-
if(response.body()?.use { it.string() }?.also { responseBody ->
296-
user = setResult(responseBody)
297-
source.setResult(AuthResult { user })
298-
} == null) {
299-
=======
300268
@Throws(IOException::class)
301269
override fun onResponse(
302270
call: Call,
303271
response: Response,
304272
) {
305273
if (!response.isSuccessful) {
306-
>>>>>>> 25efe1c (ktlint formatting + update of user data after signInWithCustomToken + photoUrl and displayName implementation)
307274
source.setException(
308275
createAuthInvalidUserException("accounts", request, response),
309276
)
@@ -325,9 +292,6 @@ class FirebaseAuth constructor(
325292
}
326293

327294
companion object {
328-
@JvmStatic
329-
fun getInstance(): FirebaseAuth = getInstance(FirebaseApp.getInstance())
330-
331295
@JvmStatic
332296
fun getInstance(app: FirebaseApp): FirebaseAuth = app.get(FirebaseAuth::class.java)
333297

@@ -382,57 +346,33 @@ class FirebaseAuth constructor(
382346
private var urlFactory = UrlFactory(app)
383347

384348
fun signInAnonymously(): Task<AuthResult> {
385-
<<<<<<< HEAD
386349
val source = enqueueAuthPost(
387350
url = "identitytoolkit.googleapis.com/v1/accounts:signUp",
388351
body = RequestBody.create(json, JsonObject(mapOf("returnSecureToken" to JsonPrimitive(true))).toString()),
389352
setResult = { responseBody ->
390353
FirebaseUserImpl(app, jsonParser.parseToJsonElement(responseBody).jsonObject, isAnonymous = true)
391-
}
354+
},
392355
)
393-
=======
394-
val source =
395-
enqueueAuthPost(
396-
url = "identitytoolkit.googleapis.com/v1/accounts:signUp",
397-
body = RequestBody.create(json, JsonObject(mapOf("returnSecureToken" to JsonPrimitive(true))).toString()),
398-
setResult = { responseBody ->
399-
FirebaseUserImpl(app, jsonParser.parseToJsonElement(responseBody).jsonObject, isAnonymous = true)
400-
},
401-
)
402-
>>>>>>> 25efe1c (ktlint formatting + update of user data after signInWithCustomToken + photoUrl and displayName implementation)
403356
return source.task
404357
}
405358

406359
fun signInWithCustomToken(customToken: String): Task<AuthResult> {
407-
<<<<<<< HEAD
408360
val source = enqueueAuthPost(
409361
url = "www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken",
410362
body = RequestBody.create(
411363
json,
412-
JsonObject(mapOf("token" to JsonPrimitive(customToken), "returnSecureToken" to JsonPrimitive(true))).toString()
364+
JsonObject(mapOf("token" to JsonPrimitive(customToken), "returnSecureToken" to JsonPrimitive(true))).toString(),
413365
),
414366
setResult = { responseBody ->
415367
FirebaseUserImpl(app, jsonParser.parseToJsonElement(responseBody).jsonObject)
416-
=======
417-
val source =
418-
enqueueAuthPost(
419-
url = "www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken",
420-
body =
421-
RequestBody.create(
422-
json,
423-
JsonObject(mapOf("token" to JsonPrimitive(customToken), "returnSecureToken" to JsonPrimitive(true))).toString(),
424-
),
425-
setResult = { responseBody ->
426-
FirebaseUserImpl(app, jsonParser.parseToJsonElement(responseBody).jsonObject)
427-
},
428-
).task.addOnSuccessListener {
429-
updateByGetAccountInfo()
430-
>>>>>>> 25efe1c (ktlint formatting + update of user data after signInWithCustomToken + photoUrl and displayName implementation)
431-
}
432-
return source
368+
},
369+
).task.continueWith {
370+
updateByGetAccountInfo()
371+
}
372+
return source.result
433373
}
434374

435-
internal fun updateByGetAccountInfo(): Task<AuthResult> {
375+
private fun updateByGetAccountInfo(): Task<AuthResult> {
436376
val source = TaskCompletionSource<AuthResult>()
437377

438378
val body =
@@ -496,18 +436,6 @@ class FirebaseAuth constructor(
496436
return source.task
497437
}
498438

499-
<<<<<<< HEAD
500-
fun createUserWithEmailAndPassword(email: String, password: String): Task<AuthResult> {
501-
val source = enqueueAuthPost(
502-
url = "www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser",
503-
body = RequestBody.create(
504-
json,
505-
JsonObject(
506-
mapOf(
507-
"email" to JsonPrimitive(email),
508-
"password" to JsonPrimitive(password),
509-
"returnSecureToken" to JsonPrimitive(true)
510-
=======
511439
fun createUserWithEmailAndPassword(
512440
email: String,
513441
password: String,
@@ -530,33 +458,12 @@ class FirebaseAuth constructor(
530458
FirebaseUserImpl(
531459
app = app,
532460
data = jsonParser.parseToJsonElement(responseBody).jsonObject,
533-
>>>>>>> 25efe1c (ktlint formatting + update of user data after signInWithCustomToken + photoUrl and displayName implementation)
534461
)
535462
},
536463
)
537464
return source.task
538465
}
539466

540-
<<<<<<< HEAD
541-
542-
fun signInWithEmailAndPassword(email: String, password: String): Task<AuthResult> {
543-
val source = enqueueAuthPost(
544-
url = "www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword",
545-
body = RequestBody.create(
546-
json,
547-
JsonObject(
548-
mapOf(
549-
"email" to JsonPrimitive(email),
550-
"password" to JsonPrimitive(password),
551-
"returnSecureToken" to JsonPrimitive(true)
552-
)
553-
).toString()
554-
),
555-
setResult = { responseBody ->
556-
FirebaseUserImpl(app, jsonParser.parseToJsonElement(responseBody).jsonObject)
557-
}
558-
)
559-
=======
560467
fun signInWithEmailAndPassword(
561468
email: String,
562469
password: String,
@@ -579,7 +486,6 @@ class FirebaseAuth constructor(
579486
FirebaseUserImpl(app, jsonParser.parseToJsonElement(responseBody).jsonObject)
580487
},
581488
)
582-
>>>>>>> 25efe1c (ktlint formatting + update of user data after signInWithCustomToken + photoUrl and displayName implementation)
583489
return source.task
584490
}
585491

@@ -600,11 +506,7 @@ class FirebaseAuth constructor(
600506
?: "UNKNOWN_ERROR",
601507
"$action API returned an error, " +
602508
"with url [${request.method()}] ${request.url()} ${request.body()} -- " +
603-
<<<<<<< HEAD
604-
"response [${response.code()}] ${response.message()} $body"
605-
=======
606509
"response [${response.code()}] ${response.message()} $body",
607-
>>>>>>> 25efe1c (ktlint formatting + update of user data after signInWithCustomToken + photoUrl and displayName implementation)
608510
)
609511
}
610512

@@ -913,20 +815,12 @@ class FirebaseAuth constructor(
913815
idTokenListeners.remove(listener)
914816
}
915817

916-
<<<<<<< HEAD
917818
fun useEmulator(host: String, port: Int) {
918819
urlFactory = UrlFactory(app, "http://$host:$port/")
919820
}
920821

921822
fun sendPasswordResetEmail(email: String, settings: ActionCodeSettings?): Task<Unit> = TODO()
922823
fun signInWithCredential(authCredential: AuthCredential): Task<AuthResult> = TODO()
923-
=======
924-
fun sendPasswordResetEmail(
925-
email: String,
926-
settings: ActionCodeSettings?,
927-
): Task<Unit> = TODO()
928-
929-
>>>>>>> 25efe1c (ktlint formatting + update of user data after signInWithCustomToken + photoUrl and displayName implementation)
930824
fun checkActionCode(code: String): Task<ActionCodeResult> = TODO()
931825

932826
fun confirmPasswordReset(
@@ -957,14 +851,4 @@ class FirebaseAuth constructor(
957851
): Task<AuthResult> = TODO()
958852

959853
fun setLanguageCode(value: String): Nothing = TODO()
960-
<<<<<<< HEAD
961-
=======
962-
963-
fun useEmulator(
964-
host: String,
965-
port: Int,
966-
) {
967-
urlFactory = UrlFactory(app, "http://$host:$port/")
968-
}
969-
>>>>>>> 25efe1c (ktlint formatting + update of user data after signInWithCustomToken + photoUrl and displayName implementation)
970854
}

src/test/kotlin/AuthTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,6 @@ class AuthTest : FirebaseTest() {
107107
}
108108
}
109109

110-
assertEquals("INVALID_PASSWORD", exception.errorCode)
110+
assertEquals("INVALID_LOGIN_CREDENTIALS", exception.errorCode)
111111
}
112112
}

0 commit comments

Comments
 (0)