Skip to content

Improving sign out, fix rotation crash, doc update #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,27 @@ redefine a string to change it, for example:
<string name="progress_dialog_signing_up">Creating your shiny new account...</string>
</resources>
```

### OAuth Scope Customization

#### Facebook

By default, FirebaseUI requests the `email` and `public_profile` permissions when initiating
Facebook Login. If you would like to override these scopes, add a string array resource
to your application like this:

```
<!--
See:
https://developers.facebook.com/docs/facebook-login/android
https://developers.facebook.com/docs/facebook-login/permissions
-->
<array name="facebook_permissions">
<item>public_profile</item>
<item>email</item>
<!-- ... -->
</array>
```

Note that if you do not include at least the `email` and `public_profile` scopes, FirebaseUI
will not work properly.
42 changes: 37 additions & 5 deletions auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;

import com.facebook.FacebookSdk;
import com.facebook.login.LoginManager;
import com.firebase.ui.auth.provider.IDPProviderParcel;
import com.firebase.ui.auth.ui.FlowParameters;
import com.firebase.ui.auth.ui.ChooseAccountActivity;
import com.firebase.ui.auth.ui.FlowParameters;
import com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity;
import com.firebase.ui.auth.util.CredentialsApiHelper;
import com.firebase.ui.auth.util.GoogleApiClientTaskHelper;
import com.firebase.ui.auth.util.Preconditions;
import com.firebase.ui.auth.util.ProviderHelper;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.tasks.Continuation;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.FirebaseApp;
import com.google.firebase.auth.FirebaseAuth;

Expand Down Expand Up @@ -257,15 +264,40 @@ private AuthUI(FirebaseApp app) {
* ({@code !result.isSuccess()}).
*/
public Task<Void> signOut(@NonNull Activity activity) {
// Get helper for Google Sign In and Credentials API
GoogleApiClientTaskHelper taskHelper = GoogleApiClientTaskHelper.getInstance(activity);
taskHelper.getBuilder()
.addApi(Auth.CREDENTIALS_API)
.addApi(Auth.GOOGLE_SIGN_IN_API, GoogleSignInOptions.DEFAULT_SIGN_IN);

// Get Credentials Helper
CredentialsApiHelper credentialsHelper = CredentialsApiHelper.getInstance(taskHelper);

// Firebase Sign out
mAuth.signOut();
return CredentialsApiHelper.getInstance(activity)
.disableAutoSignIn()
.continueWith(new Continuation<Status, Void>() {

// Disable credentials auto sign-in
Task<Status> disableCredentialsTask = credentialsHelper.disableAutoSignIn();

// Google sign out
Task<Void> googleSignOutTask = taskHelper.getConnectedGoogleApiClient()
.continueWith(new Continuation<GoogleApiClient, Void>() {
@Override
public Void then(@NonNull Task<Status> task) throws Exception {
public Void then(@NonNull Task<GoogleApiClient> task) throws Exception {
if (task.isSuccessful()) {
Auth.GoogleSignInApi.signOut(task.getResult());
}
return null;
}
});

// Facebook sign out
if (FacebookSdk.isInitialized()) {
LoginManager.getInstance().logOut();
}

// Wait for all tasks to complete
return Tasks.whenAll(disableCredentialsTask, googleSignOutTask);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions auth/src/main/java/com/firebase/ui/auth/ui/AppCompatBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ protected void onCreate(Bundle savedInstance) {
mActivityHelper.configureTheme();
}

@Override
protected void onDestroy() {
super.onDestroy();
mActivityHelper.dismissDialog();
}

public void finish(int resultCode, Intent intent) {
mActivityHelper.finish(resultCode, intent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,16 @@ public void onResult(@NonNull Status status) {
}

public static CredentialsApiHelper getInstance(Activity activity) {
return new CredentialsApiHelper(GoogleApiClientTaskHelper.getInstance(activity));
// Get a task helper with the Credentials Api
GoogleApiClientTaskHelper taskHelper = GoogleApiClientTaskHelper.getInstance(activity);
taskHelper.getBuilder()
.addApi(Auth.CREDENTIALS_API);

return getInstance(taskHelper);
}

public static CredentialsApiHelper getInstance(GoogleApiClientTaskHelper taskHelper) {
return new CredentialsApiHelper(taskHelper);
}

private static abstract class ExceptionForwardingContinuation<InT, OutT>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.tasks.Task;
Expand Down Expand Up @@ -48,11 +47,17 @@ public class GoogleApiClientTaskHelper {
@NonNull
private final AtomicReference<TaskCompletionSource<GoogleApiClient>> mConnectTaskRef;

@NonNull
private final GoogleApiClient.Builder mBuilder;

private GoogleApiClientTaskHelper(@NonNull Activity activity) {
if (activity == null) {
throw new IllegalArgumentException("activity must not be null");
}

mActivity = activity;
mBuilder = new GoogleApiClient.Builder(mActivity);

mClientRef = new AtomicReference<>();
mConnectTaskRef = new AtomicReference<>();

Expand All @@ -68,7 +73,7 @@ public Task<GoogleApiClient> getConnectedGoogleApiClient() {
}

final AtomicReference<GoogleApiClient> gacReference = new AtomicReference<>();
GoogleApiClient client = new GoogleApiClient.Builder(mActivity)
GoogleApiClient client = mBuilder
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle bundle) {
Expand All @@ -86,7 +91,6 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
+ connectionResult.getErrorMessage()));
}
})
.addApi(Auth.CREDENTIALS_API)
.build();

gacReference.set(client);
Expand All @@ -95,6 +99,11 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
return source.getTask();
}

@NonNull
public GoogleApiClient.Builder getBuilder() {
return mBuilder;
}

/**
* Retrieve the instance for the specified activity, reusing an instance if it exists,
* otherwise creates a new one.
Expand Down