-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
308 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
auth/src/main/java/com/firebase/ui/auth/data/remote/AnonymousSignInHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.firebase.ui.auth.data.remote; | ||
|
||
import android.app.Application; | ||
import android.content.Intent; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.annotation.RestrictTo; | ||
import android.support.annotation.VisibleForTesting; | ||
|
||
import com.firebase.ui.auth.AuthUI; | ||
import com.firebase.ui.auth.IdpResponse; | ||
import com.firebase.ui.auth.data.model.FlowParameters; | ||
import com.firebase.ui.auth.data.model.Resource; | ||
import com.firebase.ui.auth.data.model.User; | ||
import com.firebase.ui.auth.ui.HelperActivityBase; | ||
import com.firebase.ui.auth.viewmodel.ProviderSignInBase; | ||
import com.google.android.gms.tasks.OnFailureListener; | ||
import com.google.android.gms.tasks.OnSuccessListener; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.auth.AuthResult; | ||
import com.google.firebase.auth.FirebaseAuth; | ||
|
||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
public class AnonymousSignInHandler extends ProviderSignInBase<FlowParameters> { | ||
|
||
@VisibleForTesting | ||
public FirebaseAuth mAuth; | ||
|
||
public AnonymousSignInHandler(Application application) { | ||
super(application); | ||
} | ||
|
||
@Override | ||
protected void onCreate() { | ||
mAuth = getAuth(); | ||
} | ||
|
||
@Override | ||
public void startSignIn(@NonNull HelperActivityBase activity) { | ||
setResult(Resource.<IdpResponse>forLoading()); | ||
|
||
// Calling signInAnonymously() will always return the same anonymous user if already | ||
// available. This is enforced by the client SDK. | ||
mAuth.signInAnonymously() | ||
.addOnSuccessListener(new OnSuccessListener<AuthResult>() { | ||
@Override | ||
public void onSuccess(AuthResult result) { | ||
setResult(Resource.<IdpResponse>forSuccess(initResponse( | ||
result.getAdditionalUserInfo().isNewUser()))); | ||
} | ||
}) | ||
.addOnFailureListener(new OnFailureListener() { | ||
@Override | ||
public void onFailure(@NonNull Exception e) { | ||
setResult(Resource.<IdpResponse>forFailure(e)); | ||
} | ||
}); | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {} | ||
|
||
private IdpResponse initResponse(boolean isNewUser) { | ||
return new IdpResponse.Builder( | ||
new User.Builder(AuthUI.ANONYMOUS_PROVIDER, null) | ||
.build()) | ||
.setNewUser(isNewUser) | ||
.build(); | ||
} | ||
|
||
// TODO: We need to centralize the auth logic. ProviderSignInBase classes were originally | ||
// meant to only retrieve remote provider data. | ||
private FirebaseAuth getAuth() { | ||
FirebaseApp app = FirebaseApp.getInstance(getArguments().appName); | ||
return FirebaseAuth.getInstance(app); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
auth/src/main/res/drawable/fui_ic_anonymous_white_24dp.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<vector | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportHeight="24.0" | ||
android:viewportWidth="24.0" | ||
tools:ignore="InvalidVectorPath"> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:pathData="M12 5.9c1.16 0 2.1.94 2.1 2.1s-0.94 2.1-2.1 2.1S9.9 9.16 9.9 8s0.94-2.1 2.1-2.1m0 9c2.97 0 6.1 1.46 6.1 2.1v1.1H5.9V17c0-0.64 3.13-2.1 6.1-2.1M12 4C9.79 4 8 5.79 8 8s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4zm0 9c-2.67 0-8 1.34-8 4v3h16v-3c0-2.66-5.33-4-8-4z" /> | ||
</vector> |
19 changes: 19 additions & 0 deletions
19
auth/src/main/res/drawable/fui_idp_button_background_anonymous.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item> | ||
<shape android:shape="rectangle"> | ||
<corners android:radius="3dp" /> | ||
<solid android:color="@color/fui_buttonShadow" /> | ||
</shape> | ||
</item> | ||
<item | ||
android:bottom="@dimen/fui_button_inset_bottom" | ||
android:left="@dimen/fui_button_inset_left" | ||
android:right="@dimen/fui_button_inset_right" | ||
android:top="@dimen/fui_button_inset_top"> | ||
<shape android:shape="rectangle"> | ||
<corners android:radius="3dp" /> | ||
<solid android:color="@color/fui_bgAnonymous" /> | ||
</shape> | ||
</item> | ||
</layer-list> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/anonymous_button" | ||
style="@style/FirebaseUI.Button.AccountChooser.AnonymousButton" | ||
android:text="@string/fui_sign_in_anonymously" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.