@@ -228,6 +228,39 @@ class FirebaseAuth constructor(val app: FirebaseApp) : InternalAuthProvider {
228
228
return source.task
229
229
}
230
230
231
+ fun signInWithEmailAndPassword (email : String , password : String ): Task <AuthResult > {
232
+ val source = TaskCompletionSource <AuthResult >()
233
+ val body = RequestBody .create(
234
+ json,
235
+ JsonObject (mapOf (" email" to JsonPrimitive (email), " password" to JsonPrimitive (password), " returnSecureToken" to JsonPrimitive (true ))).toString()
236
+ )
237
+ val request = Request .Builder ()
238
+ .url(" https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=" + app.options.apiKey)
239
+ .post(body)
240
+ .build()
241
+ client.newCall(request).enqueue(object : Callback {
242
+
243
+ override fun onFailure (request : Request , e : IOException ) {
244
+ source.setException(FirebaseException (e.toString(), e))
245
+ }
246
+
247
+ @Throws(IOException ::class )
248
+ override fun onResponse (response : Response ) {
249
+ if (! response.isSuccessful) {
250
+ source.setException(FirebaseAuthInvalidUserException (
251
+ response.message(),
252
+ formatErrorMessage(" verifyPassword" , request, response)
253
+ ))
254
+ } else {
255
+ val body = response.body().use { it.string() }
256
+ val user = FirebaseUserImpl (app, jsonParser.parseToJsonElement(body).jsonObject)
257
+ refreshToken(user, source) { AuthResult { it } }
258
+ }
259
+ }
260
+ })
261
+ return source.task
262
+ }
263
+
231
264
internal fun formatErrorMessage (title : String , request : Request , response : Response ): String {
232
265
return " $title API returned an error, " +
233
266
" with url [${request.method()} ] ${request.urlString()} ${request.body()} -- " +
@@ -363,7 +396,6 @@ class FirebaseAuth constructor(val app: FirebaseApp) : InternalAuthProvider {
363
396
idTokenListeners.remove(listener)
364
397
}
365
398
366
- fun signInWithEmailAndPassword (email : String , password : String ): Task <AuthResult > = TODO ()
367
399
fun sendPasswordResetEmail (email : String , settings : ActionCodeSettings ? ): Task <Unit > = TODO ()
368
400
fun createUserWithEmailAndPassword (email : String , password : String ): Task <AuthResult > = TODO ()
369
401
fun signInWithCredential (authCredential : AuthCredential ): Task <AuthResult > = TODO ()
0 commit comments