@@ -245,6 +245,38 @@ class FirebaseAuth constructor(val app: FirebaseApp) : InternalAuthProvider {
245
245
return source.task
246
246
}
247
247
248
+ fun createUserWithEmailAndPassword (email : String , password : String ): Task <AuthResult > {
249
+ val source = TaskCompletionSource <AuthResult >()
250
+ val body = RequestBody .create(
251
+ json,
252
+ JsonObject (mapOf (" email" to JsonPrimitive (email), " password" to JsonPrimitive (password), " returnSecureToken" to JsonPrimitive (true ))).toString()
253
+ )
254
+ val request = Request .Builder ()
255
+ .url(" https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=" + app.options.apiKey)
256
+ .post(body)
257
+ .build()
258
+ client.newCall(request).enqueue(object : Callback {
259
+
260
+ override fun onFailure (call : Call , e : IOException ) {
261
+ source.setException(FirebaseException (e.toString(), e))
262
+ }
263
+
264
+ @Throws(IOException ::class )
265
+ override fun onResponse (call : Call , response : Response ) {
266
+ if (! response.isSuccessful) {
267
+ source.setException(
268
+ createAuthInvalidUserException(" signupNewUser" , request, response)
269
+ )
270
+ } else {
271
+ val responseBody = response.body()?.use { it.string() } ? : " "
272
+ val user = FirebaseUserImpl (app, jsonParser.parseToJsonElement(responseBody).jsonObject)
273
+ refreshToken(user, source) { AuthResult { it } }
274
+ }
275
+ }
276
+ })
277
+ return source.task
278
+ }
279
+
248
280
fun signInWithEmailAndPassword (email : String , password : String ): Task <AuthResult > {
249
281
val source = TaskCompletionSource <AuthResult >()
250
282
val body = RequestBody .create(
@@ -425,7 +457,6 @@ class FirebaseAuth constructor(val app: FirebaseApp) : InternalAuthProvider {
425
457
}
426
458
427
459
fun sendPasswordResetEmail (email : String , settings : ActionCodeSettings ? ): Task <Unit > = TODO ()
428
- fun createUserWithEmailAndPassword (email : String , password : String ): Task <AuthResult > = TODO ()
429
460
fun signInWithCredential (authCredential : AuthCredential ): Task <AuthResult > = TODO ()
430
461
fun checkActionCode (code : String ): Task <ActionCodeResult > = TODO ()
431
462
fun confirmPasswordReset (code : String , newPassword : String ): Task <Unit > = TODO ()
0 commit comments