Skip to content

Commit

Permalink
re-add startSaveCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
thatfiredev committed Aug 28, 2024
1 parent f87451d commit 5e22369
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 126 deletions.
6 changes: 6 additions & 0 deletions auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ dependencies {
implementation(Config.Libs.Androidx.customTabs)
implementation(Config.Libs.Androidx.constraint)

// TODO(thatfiredev): replace with Config.Libs
implementation("androidx.credentials:credentials:1.2.2")
implementation("androidx.credentials:credentials-play-services-auth:1.2.2")
implementation("com.google.android.libraries.identity.googleid:googleid:1.1.1")


annotationProcessor(Config.Libs.Androidx.lifecycleCompiler)

implementation(platform(Config.Libs.Firebase.bom))
Expand Down
7 changes: 7 additions & 0 deletions auth/src/main/java/com/firebase/ui/auth/ui/FragmentBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
public FlowParameters getFlowParams() {
return mActivity.getFlowParams();
}

public void startSaveCredentials(
FirebaseUser firebaseUser,
IdpResponse response,
@Nullable String password) {
mActivity.startSaveCredentials(firebaseUser, response, password);
}
}
49 changes: 49 additions & 0 deletions auth/src/main/java/com/firebase/ui/auth/ui/HelperActivityBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.CancellationSignal;
import android.text.TextUtils;

import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.ErrorCodes;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.data.model.FlowParameters;
import com.firebase.ui.auth.util.ExtraConstants;
import com.firebase.ui.auth.viewmodel.RequestCodes;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

import java.util.concurrent.Executors;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.appcompat.app.AppCompatActivity;
import androidx.credentials.CreateCredentialResponse;
import androidx.credentials.CreatePasswordRequest;
import androidx.credentials.CredentialManager;
import androidx.credentials.CredentialManagerCallback;
import androidx.credentials.exceptions.CreateCredentialException;

import static com.firebase.ui.auth.util.Preconditions.checkNotNull;

Expand Down Expand Up @@ -67,6 +78,44 @@ public void finish(int resultCode, @Nullable Intent intent) {
finish();
}

public void startSaveCredentials(
FirebaseUser firebaseUser,
IdpResponse response,
@Nullable String password) {
if (firebaseUser == null) {
setResult(RESULT_CANCELED);
finish();
}
String email = firebaseUser.getEmail();
String phone = firebaseUser.getPhoneNumber();

String username = TextUtils.isEmpty(email) ? phone : email;

CreatePasswordRequest request = new CreatePasswordRequest(username, password);
CredentialManager credMan = CredentialManager.create(this);
credMan.createCredentialAsync(
this,
request,
new CancellationSignal(),
Executors.newSingleThreadExecutor(),
new CredentialManagerCallback<CreateCredentialResponse, CreateCredentialException>() {
@Override
public void onResult(CreateCredentialResponse response) {
setResult(RESULT_OK);
finish();
}

@Override
public void onError(@NonNull CreateCredentialException e) {
// TODO: return this exception before finish()
e.printStackTrace();
setResult(RESULT_CANCELED);
finish();
}
}
);
}

/**
* Check if there is an active or soon-to-be-active network connection.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.firebase.ui.auth.ui.email;

import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -32,10 +34,18 @@
import com.google.firebase.auth.EmailAuthProvider;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseAuthWeakPasswordException;
import com.google.firebase.auth.FirebaseUser;

import java.util.concurrent.Executors;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.credentials.CreateCredentialResponse;
import androidx.credentials.CreatePasswordRequest;
import androidx.credentials.CredentialManager;
import androidx.credentials.CredentialManagerCallback;
import androidx.credentials.exceptions.CreateCredentialException;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProvider;

Expand Down Expand Up @@ -100,11 +110,10 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
this, R.string.fui_progress_dialog_signing_up) {
@Override
protected void onSuccess(@NonNull IdpResponse response) {
// TODO(hackathon): Save this user's credentials
// startSaveCredentials(
// mHandler.getCurrentUser(),
// response,
// mPasswordEditText.getText().toString());
startSaveCredentials(
mHandler.getCurrentUser(),
response,
mPasswordEditText.getText().toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
this, R.string.fui_progress_dialog_signing_in) {
@Override
protected void onSuccess(@NonNull IdpResponse response) {
// TODO(hackathon): Save this user's credentials
// startSaveCredentials(
// mHandler.getCurrentUser(), response, mHandler.getPendingPassword());
startSaveCredentials(
mHandler.getCurrentUser(), response, mHandler.getPendingPassword());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
this, R.string.fui_progress_dialog_signing_in) {
@Override
protected void onSuccess(@NonNull IdpResponse response) {
// TODO(hackathon): Save this user's credentials
// startSaveCredentials(mHandler.getCurrentUser(), response, null);
startSaveCredentials(mHandler.getCurrentUser(), response, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ protected void onFailure(@NonNull Exception e) {
mHandler.getOperation().observe(this, new ResourceObserver<IdpResponse>(this) {
@Override
protected void onSuccess(@NonNull IdpResponse response) {
// TODO(hackathon): Save this user's credentials
// startSaveCredentials(mHandler.getCurrentUser(), response, null);
startSaveCredentials(mHandler.getCurrentUser(), response, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
this, R.string.fui_progress_dialog_signing_in) {
@Override
protected void onSuccess(@NonNull IdpResponse response) {
// TODO(hackathon): Save this user's credentials
// startSaveCredentials(handler.getCurrentUser(), response, null);
startSaveCredentials(handler.getCurrentUser(), response, null);
}

@Override
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 5e22369

Please sign in to comment.