Skip to content

Commit dcf641d

Browse files
committed
add send password reset api
1 parent aee4034 commit dcf641d

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

firebase-auth-rest/core/src/main/java/com/anotherdev/firebase/auth/FirebaseAuth.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import androidx.annotation.Nullable;
55

66
import com.anotherdev.firebase.auth.provider.IdpAuthCredential;
7+
import com.anotherdev.firebase.auth.rest.api.model.SendPasswordResetEmailRequest;
8+
import com.anotherdev.firebase.auth.rest.api.model.SendPasswordResetEmailResponse;
79
import com.google.firebase.FirebaseApp;
810

911
import io.reactivex.rxjava3.annotations.CheckReturnValue;
1012
import io.reactivex.rxjava3.core.Observable;
1113
import io.reactivex.rxjava3.core.Single;
14+
import retrofit2.http.Body;
1215

1316
public interface FirebaseAuth {
1417

@@ -53,5 +56,9 @@ public interface FirebaseAuth {
5356
@CheckReturnValue
5457
Single<SignInResponse> linkWithCredential(@NonNull FirebaseUser user, @NonNull IdpAuthCredential credential);
5558

59+
@NonNull
60+
@CheckReturnValue
61+
Single<SendPasswordResetEmailResponse> sendPasswordResetEmail(@Body SendPasswordResetEmailRequest request);
62+
5663
void signOut();
5764
}

firebase-auth-rest/core/src/main/java/com/anotherdev/firebase/auth/rest/RestAuthProvider.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import com.anotherdev.firebase.auth.rest.api.RestAuthApi;
1515
import com.anotherdev.firebase.auth.rest.api.model.ExchangeTokenRequest;
1616
import com.anotherdev.firebase.auth.rest.api.model.ImmutableSignInWithIdpRequest;
17+
import com.anotherdev.firebase.auth.rest.api.model.SendPasswordResetEmailRequest;
18+
import com.anotherdev.firebase.auth.rest.api.model.SendPasswordResetEmailResponse;
1719
import com.anotherdev.firebase.auth.rest.api.model.SignInAnonymouslyRequest;
1820
import com.anotherdev.firebase.auth.rest.api.model.SignInWithCustomTokenRequest;
1921
import com.anotherdev.firebase.auth.rest.api.model.SignInWithEmailPasswordRequest;
@@ -155,6 +157,12 @@ private Single<SignInResponse> performSignInWithCredential(ImmutableSignInWithId
155157
.map(this::saveCurrentUser);
156158
}
157159

160+
@NonNull
161+
@Override
162+
public Single<SendPasswordResetEmailResponse> sendPasswordResetEmail(SendPasswordResetEmailRequest request) {
163+
return RestAuthApi.auth().sendPasswordResetEmail(request);
164+
}
165+
158166
@Override
159167
public void signOut() {
160168
userStore.delete();

firebase-auth-rest/core/src/main/java/com/anotherdev/firebase/auth/rest/api/IdentityToolkitApi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.anotherdev.firebase.auth.UserProfileChangeResponse;
66
import com.anotherdev.firebase.auth.rest.api.model.IdTokenRequest;
77
import com.anotherdev.firebase.auth.rest.api.model.SendPasswordResetEmailRequest;
8+
import com.anotherdev.firebase.auth.rest.api.model.SendPasswordResetEmailResponse;
89
import com.anotherdev.firebase.auth.rest.api.model.SignInRequest;
910
import com.anotherdev.firebase.auth.rest.api.model.SignInWithCustomTokenRequest;
1011
import com.anotherdev.firebase.auth.rest.api.model.SignInWithEmailPasswordRequest;
@@ -37,9 +38,8 @@ public interface IdentityToolkitApi {
3738
@POST("v1/accounts:signInWithCustomToken")
3839
Single<SignInResponse> signInWithCustomToken(@Body SignInWithCustomTokenRequest request);
3940

40-
// FIXME refactor to proper return type
4141
@POST("v1/accounts:sendOobCode")
42-
Single<JsonObject> sendPasswordResetEmail(@Body SendPasswordResetEmailRequest request);
42+
Single<SendPasswordResetEmailResponse> sendPasswordResetEmail(@Body SendPasswordResetEmailRequest request);
4343

4444
@POST("v1/accounts:lookup")
4545
Single<JsonObject> getAccounts(@Body IdTokenRequest request);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
package com.anotherdev.firebase.auth.rest.api.model;
22

3+
import com.google.gson.annotations.SerializedName;
4+
5+
import org.immutables.gson.Gson;
6+
import org.immutables.value.Value;
7+
8+
@Value.Immutable
9+
@Value.Style(strictBuilder = true)
10+
@Gson.TypeAdapters
311
public interface SendPasswordResetEmailRequest {
12+
13+
@SerializedName("email")
14+
String getEmail();
15+
16+
@Value.Default
17+
@SerializedName("requestType")
18+
default String getRequestType() {
19+
return "PASSWORD_RESET";
20+
}
21+
22+
23+
static ImmutableSendPasswordResetEmailRequest.Builder builder() {
24+
return ImmutableSendPasswordResetEmailRequest.builder();
25+
}
426
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.anotherdev.firebase.auth.rest.api.model;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
import org.immutables.gson.Gson;
6+
import org.immutables.value.Value;
7+
8+
@Value.Immutable
9+
@Value.Style(strictBuilder = true)
10+
@Gson.TypeAdapters
11+
public interface SendPasswordResetEmailResponse {
12+
13+
@SerializedName("email")
14+
String getEmail();
15+
16+
17+
static ImmutableSendPasswordResetEmailResponse.Builder builder() {
18+
return ImmutableSendPasswordResetEmailResponse.builder();
19+
}
20+
}

0 commit comments

Comments
 (0)