Skip to content

Auth code cleanup #376

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 37 commits into from
Nov 18, 2016
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6ecc551
cleanup
SUPERCILEX Oct 23, 2016
00a59cd
cleanup
SUPERCILEX Oct 23, 2016
bb352e9
Update .travis.yml
SUPERCILEX Oct 23, 2016
d8f1e1a
Merge remote-tracking branch 'firebase/version-1.0.0-dev' into cleanup
SUPERCILEX Oct 23, 2016
e733913
More dependency updates
SUPERCILEX Oct 24, 2016
9ab7dd4
Reorganize dependencies
SUPERCILEX Oct 24, 2016
b5fe9f1
Cleanup
SUPERCILEX Oct 24, 2016
7a05e46
Update firebase
SUPERCILEX Oct 24, 2016
51dc270
Update constants.gradle
SUPERCILEX Oct 25, 2016
90f2c56
Remove unnecessary app dependencies
SUPERCILEX Oct 25, 2016
1234066
Style consistency in xml files
SUPERCILEX Oct 25, 2016
575cb9b
Upgrade EditTexts to android.support.design.widget.TextInputEditText
SUPERCILEX Oct 25, 2016
34a7800
Final cleanup
SUPERCILEX Oct 25, 2016
5e7c955
Even more xml refactoring. Extracted FirebaseUI.EditText.EmailField
SUPERCILEX Oct 25, 2016
97bc852
app dependency updates
SUPERCILEX Oct 25, 2016
41c5ddd
Massively cleaned up gradle ext variables.
SUPERCILEX Oct 26, 2016
e666a15
Merge remote-tracking branch 'firebase/version-1.0.0-dev' into cleanup
SUPERCILEX Oct 27, 2016
6798d92
Address review comments and fix mistakes
SUPERCILEX Oct 27, 2016
afd6fc9
Turns out braces are unnecessary in gradle
SUPERCILEX Oct 28, 2016
1cdf4f2
Merge remote-tracking branch 'firebase/version-1.0.0-dev' into cleanup
SUPERCILEX Oct 28, 2016
2b2da92
Fix merge mistakes
SUPERCILEX Oct 28, 2016
9d9b7f5
Cleanup SmartLock.java
SUPERCILEX Oct 29, 2016
47b204e
Fix nits
SUPERCILEX Nov 1, 2016
6e35dcb
Merge remote-tracking branch 'firebase/version-1.0.0-dev' into cleanup
SUPERCILEX Nov 2, 2016
18e969f
Move AcquireEmailHelper.java so as to narrow down access to RC_SIGN_IN
SUPERCILEX Nov 3, 2016
a183c7f
Cleanup
SUPERCILEX Nov 3, 2016
26343b4
Merge remote-tracking branch 'firebase/master' into cleanup
SUPERCILEX Nov 5, 2016
2ac59d9
Cleanup
SUPERCILEX Nov 5, 2016
8925f51
Cleanup
SUPERCILEX Nov 5, 2016
9603d9a
Cleanup
SUPERCILEX Nov 5, 2016
2e9f399
Update README.md
SUPERCILEX Nov 5, 2016
f60c448
More xml cleanup
SUPERCILEX Nov 5, 2016
0406cd8
Merge remote-tracking branch 'origin/cleanup' into cleanup
SUPERCILEX Nov 5, 2016
0c85d63
Update AuthMethodPickerActivity.java
SUPERCILEX Nov 6, 2016
7b95605
Merge remote-tracking branch 'firebase/master' into cleanup
SUPERCILEX Nov 18, 2016
5610ad1
Fix merge mistakes
SUPERCILEX Nov 18, 2016
af34fab
Merge remote-tracking branch 'origin/cleanup' into cleanup
SUPERCILEX Nov 18, 2016
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
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: android
jdk: oraclejdk8
# See https://github.com/travis-ci/travis-ci/issues/5582
sudo: required
# See https://docs.travis-ci.com/user/languages/java/#Caching
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
Expand All @@ -18,8 +17,6 @@ android:
- android-25

# Extras
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
- addon-google_apis-google-24
script: ./gradlew clean :library:testAll :library:prepareArtifacts
5 changes: 0 additions & 5 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@

<color name="material_gray_300">#E0E0E0</color>

<color name="material_lime_50">#F9FBE7</color>
<color name="material_lime_a700">#AEEA00</color>

<color name="material_purple_50">#F3E5F5</color>
<color name="material_purple_a700">#AA00FF</color>

<color name="material_red_a200">#FF5252</color>

<color name="material_grey_200">#EEEEEE</color>
<color name="material_grey_400">#BDBDBD</color>
<color name="material_grey_500">#9E9E9E</color>
<color name="material_grey_700">#616161</color>
</resources>
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<string name="firebase_tos_label">Firebase TOS</string>
<string name="tos_header">Terms of Service URL:</string>
<string name="unknown_response">Unexpected onActivityResult response code</string>
<string name="ok_label">OK</string>
<string name="unknown_sign_in_response">Unknown response from AuthUI sign-in</string>
<string name="sign_in_cancelled">Sign in cancelled</string>
<string name="no_internet_connection">No internet connection</string>
Expand Down
26 changes: 13 additions & 13 deletions auth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ android {
}
}


dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.2.0'
testCompile 'org.robolectric:robolectric:3.1.2'
// See https://github.com/robolectric/robolectric/issues/1932#issuecomment-219796474
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'

compile 'com.facebook.android:facebook-android-sdk:4.14.1'
compile("com.twitter.sdk.android:twitter:2.0.0@aar") {
transitive = true;
}
compile "com.android.support:design:${project.ext.support_library_version}"

compile "com.google.firebase:firebase-auth:${project.ext.firebase_version}"
compile "com.google.android.gms:play-services-auth:${project.ext.firebase_version}"

compile 'com.facebook.android:facebook-android-sdk:4.16.1'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old: v4.14.1

compile("com.twitter.sdk.android:twitter:2.1.1@aar") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old: 2.0.0

transitive = true
}

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.2.6'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old: 2.2.0

testCompile 'org.robolectric:robolectric:3.1.2'
// See https://github.com/robolectric/robolectric/issues/1932#issuecomment-219796474
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
}

checkstyle {
Expand All @@ -64,8 +64,8 @@ javadoc.exclude([
'com/firebase/ui/auth/ui/ExtraConstants',
'com/firebase/ui/auth/ui/email/field_validators/**',
'com/firebase/ui/auth/util/**',
])
])

javadoc.include([
'com/google/firebase/auth/**'
])
])
4 changes: 1 addition & 3 deletions auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public static AuthUI getInstance() {
* Retrieves the {@link AuthUI} instance associated the the specified app.
*/
public static AuthUI getInstance(FirebaseApp app) {
AuthUI authUi = null;
AuthUI authUi;
synchronized (INSTANCES) {
authUi = INSTANCES.get(app);
if (authUi == null) {
Expand All @@ -407,8 +407,6 @@ public static AuthUI getInstance(FirebaseApp app) {
* customization is required.
*/
public static @StyleRes int getDefaultTheme() {
// TODO(iainmgin): figure out why this works as a static method but not as a static
// final variable.
return R.style.FirebaseUI;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public interface IdpProvider {

void startLogin(Activity activity);

public interface IdpCallback {
public void onSuccess(IdpResponse idpResponse);
public void onFailure(Bundle extra);
interface IdpCallback {
void onSuccess(IdpResponse idpResponse);
void onFailure(Bundle extra);
}
}
34 changes: 13 additions & 21 deletions auth/src/main/java/com/firebase/ui/auth/ui/AcquireEmailHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@

public class AcquireEmailHelper {
private static final String TAG = "AcquireEmailHelper";
public static final int RC_REGISTER_ACCOUNT = 14;
public static final int RC_WELCOME_BACK_IDP = 15;
private static final int RC_REGISTER_ACCOUNT = 14;
private static final int RC_WELCOME_BACK_IDP = 15;
public static final int RC_SIGN_IN = 16;
public static final List<Integer> REQUEST_CODES = Arrays.asList(
private static final List<Integer> REQUEST_CODES = Arrays.asList(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason for keeping this stuff public?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope this LGTM, not meant to be part of the public API/

RC_REGISTER_ACCOUNT,
RC_WELCOME_BACK_IDP,
RC_SIGN_IN
Expand Down Expand Up @@ -80,30 +80,22 @@ private void startEmailHandler(String email, List<String> providers) {
mActivityHelper.startActivityForResult(registerIntent, RC_REGISTER_ACCOUNT);
} else {
// account does exist
for (String provider : providers) {
if (provider.equalsIgnoreCase(EmailAuthProvider.PROVIDER_ID)) {
Intent signInIntent = SignInActivity.createIntent(
mActivityHelper.getApplicationContext(),
mActivityHelper.getFlowParams(),
email);
mActivityHelper.startActivityForResult(signInIntent, RC_SIGN_IN);
return;
}

Intent intent = WelcomeBackIdpPrompt.createIntent(
if (providers.get(0).equalsIgnoreCase(EmailAuthProvider.PROVIDER_ID)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the most important change in this PR: the for loop doesn't loop! Is my change appropriate or should we be doing something else here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be sure that if the email provider is in the providers collection that it will be at index 0? I agree the loop was not needed but not sure that get(0) will always be equivalent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<String> providers so isn't the first item in the for loop always going to be at index 0?

Intent signInIntent = SignInActivity.createIntent(
mActivityHelper.getApplicationContext(),
mActivityHelper.getFlowParams(),
provider,
null,
email);
mActivityHelper.startActivityForResult(intent, RC_WELCOME_BACK_IDP);
mActivityHelper.startActivityForResult(signInIntent, RC_SIGN_IN);
return;
}

Intent signInIntent = new Intent(
mActivityHelper.getApplicationContext(), SignInActivity.class);
signInIntent.putExtra(ExtraConstants.EXTRA_EMAIL, email);
mActivityHelper.startActivityForResult(signInIntent, RC_SIGN_IN);
Intent intent = WelcomeBackIdpPrompt.createIntent(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a behavior change from SignInActivity to WelcomeBackIDPPrompt.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the git diff just got really messed up. See the old vs the new:

image

mActivityHelper.getApplicationContext(),
mActivityHelper.getFlowParams(),
providers.get(0),
null,
email);
mActivityHelper.startActivityForResult(intent, RC_WELCOME_BACK_IDP);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,5 @@ public class ExtraConstants {
public static final String EXTRA_ERROR_MESSAGE = "extra_error_msg";
public static final String EXTRA_FLOW_PARAMS = "extra_flow_params";
public static final String EXTRA_IDP_RESPONSE = "extra_idp_response";
public static final String EXTRA_NAME = "extra_name";
public static final String EXTRA_PASSWORD = "extra_password";
public static final String EXTRA_PROFILE_PICTURE_URI = "extra_profile_picture_uri";
public static final String EXTRA_PROVIDER = "extra_provider";
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,21 @@ public class WelcomeBackIdpPrompt extends AppCompatBase

private static final String TAG = "WelcomeBackIDPPrompt";
private IdpProvider mIdpProvider;
private String mProviderId;
private IdpResponse mPrevIdpResponse;
private AuthCredential mPrevCredential;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mProviderId = getProviderIdFromIntent();
String providerId = getProviderIdFromIntent();
mPrevIdpResponse = getIntent().getParcelableExtra(ExtraConstants.EXTRA_IDP_RESPONSE);
setContentView(R.layout.welcome_back_idp_prompt_layout);

mIdpProvider = null;
for (IdpConfig idpConfig: mActivityHelper.getFlowParams().providerInfo) {
if (mProviderId.equals(idpConfig.getProviderId())) {
switch (mProviderId) {
if (providerId.equals(idpConfig.getProviderId())) {
switch (providerId) {
case GoogleAuthProvider.PROVIDER_ID:
mIdpProvider = new GoogleProvider(this, idpConfig, getEmailFromIntent());
break;
Expand All @@ -79,7 +78,7 @@ protected void onCreate(Bundle savedInstanceState) {
mIdpProvider = new TwitterProvider(this);
break;
default:
Log.w(TAG, "Unknown provider: " + mProviderId);
Log.w(TAG, "Unknown provider: " + providerId);
finish(RESULT_CANCELED, getIntent());
return;
}
Expand Down Expand Up @@ -205,7 +204,7 @@ public static Intent createIntent(
.putExtra(ExtraConstants.EXTRA_EMAIL, email);
}

private class FinishListener implements OnCompleteListener {
private class FinishListener implements OnCompleteListener<AuthResult> {
private final IdpResponse mIdpResponse;

FinishListener(IdpResponse idpResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ public class IdpSignInContainerActivity extends IDPBaseActivity implements IdpCa
private static final int RC_WELCOME_BACK_IDP = 4;

private IdpProvider mIdpProvider;
private String mProvider;
private String mEmail;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mProvider = getIntent().getStringExtra(ExtraConstants.EXTRA_PROVIDER);
mEmail = getIntent().getStringExtra(ExtraConstants.EXTRA_EMAIL);
String provider = getIntent().getStringExtra(ExtraConstants.EXTRA_PROVIDER);
String email = getIntent().getStringExtra(ExtraConstants.EXTRA_EMAIL);
IdpConfig providerConfig = null;
for (IdpConfig config : mActivityHelper.getFlowParams().providerInfo) {
if (config.getProviderId().equalsIgnoreCase(mProvider)) {
if (config.getProviderId().equalsIgnoreCase(provider)) {
providerConfig = config;
break;
}
Expand All @@ -63,11 +61,11 @@ protected void onCreate(Bundle savedInstanceState) {
finish(RESULT_CANCELED, new Intent());
return;
}
if (mProvider.equalsIgnoreCase(FacebookAuthProvider.PROVIDER_ID)) {
if (provider.equalsIgnoreCase(FacebookAuthProvider.PROVIDER_ID)) {
mIdpProvider = new FacebookProvider(this, providerConfig);
} else if (mProvider.equalsIgnoreCase(GoogleAuthProvider.PROVIDER_ID)) {
mIdpProvider = new GoogleProvider(this, providerConfig, mEmail);
} else if (mProvider.equalsIgnoreCase(TwitterAuthProvider.PROVIDER_ID)) {
} else if (provider.equalsIgnoreCase(GoogleAuthProvider.PROVIDER_ID)) {
mIdpProvider = new GoogleProvider(this, providerConfig, email);
} else if (provider.equalsIgnoreCase(TwitterAuthProvider.PROVIDER_ID)) {
mIdpProvider = new TwitterProvider(this);
}
mIdpProvider.setAuthenticationCallback(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.app.Activity;
import android.app.PendingIntent;
import android.support.annotation.NonNull;

import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.AuthUI.IdpConfig;
import com.google.android.gms.auth.api.Auth;
Expand All @@ -32,6 +33,7 @@
import com.google.android.gms.tasks.Continuation;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.TaskCompletionSource;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -76,8 +78,7 @@ public Task<CredentialRequestResult> request(final CredentialRequest request) {
@Override
protected void process(
final GoogleApiClient client,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed all the throws exception here. Did they serve a purpose?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess not? @amandle see anything?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why these are throwing Exception, @iainmcgin might know

final TaskCompletionSource<CredentialRequestResult> source)
throws Exception {
final TaskCompletionSource<CredentialRequestResult> source) {
Auth.CredentialsApi.request(client, request)
.setResultCallback(new TaskResultCaptor<>(source));
}
Expand All @@ -90,10 +91,9 @@ public Task<Status> save(final Credential credential) {
@Override
protected void process(
GoogleApiClient client,
TaskCompletionSource<Status> source)
throws Exception {
TaskCompletionSource<Status> source) {
Auth.CredentialsApi.save(client, credential)
.setResultCallback(new TaskResultCaptor<Status>(source));
.setResultCallback(new TaskResultCaptor<>(source));
}
});
}
Expand All @@ -104,8 +104,7 @@ public Task<PendingIntent> getHintPickerIntent(final HintRequest request) {
@Override
protected void process(
GoogleApiClient client,
TaskCompletionSource<PendingIntent> source)
throws Exception {
TaskCompletionSource<PendingIntent> source) {
source.setResult(Auth.CredentialsApi.getHintPickerIntent(client, request));
}
});
Expand All @@ -117,9 +116,9 @@ public Task<Status> delete(final Credential credential) {
@Override
protected void process(
GoogleApiClient client,
TaskCompletionSource<Status> source) throws Exception {
TaskCompletionSource<Status> source) {
Auth.CredentialsApi.delete(client, credential)
.setResultCallback(new TaskResultCaptor<Status>(source));
.setResultCallback(new TaskResultCaptor<>(source));
}
});
}
Expand All @@ -130,8 +129,7 @@ public Task<Status> disableAutoSignIn() {
@Override
protected void process(
final GoogleApiClient client,
final TaskCompletionSource<Status> source)
throws Exception {
final TaskCompletionSource<Status> source) {
Auth.CredentialsApi.disableAutoSignIn(client)
.setResultCallback(new ResultCallback<Status>() {
@Override
Expand Down Expand Up @@ -169,7 +167,7 @@ public final Task<OutT> then(@NonNull Task<InT> task) throws Exception {
return source.getTask();
}

protected abstract void process(InT in, TaskCompletionSource<OutT> result) throws Exception;
protected abstract void process(InT in, TaskCompletionSource<OutT> result);
}

private static final class TaskResultCaptor<R extends Result> implements ResultCallback<R> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package com.firebase.ui.auth.util;

import android.app.Fragment;
import android.app.PendingIntent;
import android.content.Context;
import android.os.Bundle;
Expand Down Expand Up @@ -67,10 +66,7 @@ public FirebaseAuthWrapperImpl(@NonNull FirebaseAuth firebaseAuth) {
@Override
@WorkerThread
public boolean isExistingAccount(@Nullable final String email) {
if (email == null) {
return false;
}
return hasProviders(await(mFirebaseAuth.fetchProvidersForEmail(email)));
return email != null && hasProviders(await(mFirebaseAuth.fetchProvidersForEmail(email)));
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion auth/src/main/res/layout/auth_method_picker_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

<ImageView
android:id="@+id/logo"
style="@style/FirebaseUI.AuthMethodPicker.Logo"/>
style="@style/FirebaseUI.AuthMethodPicker.Logo"
android:contentDescription="@string/accessibility_logo"/>

</LinearLayout>

Expand Down
18 changes: 0 additions & 18 deletions auth/src/main/res/layout/delete_credential.xml

This file was deleted.

Loading