diff --git a/README.md b/README.md index c123606f3..a01076240 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ If you're going to use our `OAuth2WebProvider` with Browser instead of WebView, If you forget this mode, and the code is running on devices with Android version above KITKAT, an error will raise in the console and the Activity won't launch. This is to sort the way Android handles calling an existing Activity with a result. Previous versions of Android are also affected by this issue, but won't get the warning and can crash if it's not properly handled. -Also note that you can't use Browser and launch the `LockActivity` calling `startActivityForResult` at the same time. +Also note that for the time being, `LockActivity` can't be launched calling`startActivityForResult`. ### Lock instance @@ -103,7 +103,7 @@ You'll also need a `LockCallback` implementation. We suggest you to extend the ` ```java private LockCallback callback = new AuthenticationCallback() { @Override - public void onAuthentication(Authentication authentication) { + public void onAuthentication(Credentials credentials) { //Authenticated } @@ -126,7 +126,6 @@ This is how your activity should look like. ```java public class MainActivity extends Activity { - public static final int AUTH_REQUEST = 333; private Lock lock; @Override @@ -144,27 +143,13 @@ public class MainActivity extends Activity { super.onDestroy(); } - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == AUTH_REQUEST) { - lock.onActivityResult(this, resultCode, data); - return; - } - - super.onActivityResult(requestCode, resultCode, data); - } - private void performLogin(boolean useBrowser) { - if (useBrowser) { - startActivity(lock.newIntent(this)); - } else { - startActivityForResult(lock.newIntent(this), AUTH_REQUEST); - } + startActivity(lock.newIntent(this)); } private LockCallback callback = new AuthenticationCallback() { @Override - public void onAuthentication(Authentication authentication) { + public void onAuthentication(Credentials credentials) { //Authenticated } @@ -181,7 +166,7 @@ public class MainActivity extends Activity { } ``` ->Remember to notify the `LockActivity` on every `OnCreate`, `OnDestroy` and `OnActivityResult` call on your Activity, as it helps to keep the Lock state. +>Remember to notify the `LockActivity` on every `OnCreate` and `OnDestroy` call on your Activity, as it helps to keep the Lock state. That's it! **Lock** will handle the rest for you. diff --git a/app/build.gradle b/app/build.gradle index 0688cbd3d..c33d7485c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,11 +27,11 @@ android { } release { minifyEnabled true - proguardFile '../proguard/proguard-jackson-2.pro' proguardFile '../proguard/proguard-lock-2.pro' proguardFile '../proguard/proguard-okhttp-2.pro' proguardFile '../proguard/proguard-okio.pro' proguardFile '../proguard/proguard-otto.pro' + proguardFile '../proguard/proguard-gson.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release } diff --git a/app/src/main/java/com/auth0/android/lock/app/DemoActivity.java b/app/src/main/java/com/auth0/android/lock/app/DemoActivity.java index 8bdc24b65..1e6f75dfe 100644 --- a/app/src/main/java/com/auth0/android/lock/app/DemoActivity.java +++ b/app/src/main/java/com/auth0/android/lock/app/DemoActivity.java @@ -24,7 +24,6 @@ package com.auth0.android.lock.app; -import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; @@ -35,23 +34,17 @@ import com.auth0.Auth0; import com.auth0.android.lock.AuthenticationCallback; -import com.auth0.android.lock.CustomField; -import com.auth0.android.lock.CustomField.FieldType; import com.auth0.android.lock.Lock; import com.auth0.android.lock.LockCallback; import com.auth0.android.lock.PasswordlessLock; -import com.auth0.android.lock.enums.InitialScreen; import com.auth0.android.lock.utils.LockException; import com.auth0.authentication.ParameterBuilder; -import com.auth0.authentication.result.Authentication; +import com.auth0.authentication.result.Credentials; -import java.util.ArrayList; -import java.util.List; import java.util.Map; public class DemoActivity extends AppCompatActivity implements View.OnClickListener { private static final String SCOPE_OPENID_OFFLINE_ACCESS = "openid offline_access"; - private static final int AUTH_REQUEST = 333; private Lock lock; private PasswordlessLock passwordlessLock; @@ -84,17 +77,6 @@ public void onDestroy() { } } - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - //should we ask for null lock? - if (lock != null && requestCode == AUTH_REQUEST) { - lock.onActivityResult(this, resultCode, data); - return; - } - - super.onActivityResult(requestCode, resultCode, data); - } - @Override public void onClick(View v) { switch (v.getId()) { @@ -121,7 +103,7 @@ public void onClick(View v) { private void passwordlessLogin(boolean useCode) { Auth0 auth0 = new Auth0(getString(R.string.auth0_client_id), getString(R.string.auth0_domain)); - final PasswordlessLock.Builder builder = PasswordlessLock.newBuilder(auth0, callback); + final PasswordlessLock.Builder builder = PasswordlessLock.newBuilder(auth0, callback).closable(true); if (useCode) { builder.useCode(); } else { @@ -155,14 +137,11 @@ private void normalLogin(boolean useBrowser) { .closable(true) .build(); + //this should be called only once lock.onCreate(this); // launch, the results will be received in the callback - if (useBrowser) { - startActivity(lock.newIntent(this)); - } else { - startActivityForResult(lock.newIntent(this), AUTH_REQUEST); - } + startActivity(lock.newIntent(this)); } /** @@ -176,8 +155,8 @@ private void showResult(String message) { private LockCallback callback = new AuthenticationCallback() { @Override - public void onAuthentication(Authentication authentication) { - showResult("OK > " + authentication.getProfile().getName() + " > " + authentication.getCredentials().getIdToken()); + public void onAuthentication(Credentials credentials) { + showResult("OK > " + credentials.getIdToken()); } @Override diff --git a/lib/build.gradle b/lib/build.gradle index 6c6e03dd2..27b0b242a 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -35,7 +35,7 @@ dependencies { compile 'com.android.support:support-v4:23.3.0' compile 'com.android.support:design:23.3.0' compile 'com.google.code.gson:gson:2.6.2' - compile 'com.auth0:auth0:0.3.0' + compile 'com.auth0:auth0:0.4.0' compile 'com.squareup:otto:1.3.8' testCompile 'junit:junit:4.12' testCompile 'org.hamcrest:hamcrest-library:1.3' diff --git a/lib/src/main/java/com/auth0/android/lock/AuthenticationCallback.java b/lib/src/main/java/com/auth0/android/lock/AuthenticationCallback.java index 0be0a4199..07759e0b7 100644 --- a/lib/src/main/java/com/auth0/android/lock/AuthenticationCallback.java +++ b/lib/src/main/java/com/auth0/android/lock/AuthenticationCallback.java @@ -28,9 +28,7 @@ import android.util.Log; import com.auth0.android.lock.utils.LockException; -import com.auth0.authentication.result.Authentication; import com.auth0.authentication.result.Credentials; -import com.auth0.authentication.result.UserProfile; /** @@ -44,9 +42,9 @@ public abstract class AuthenticationCallback implements LockCallback { /** * Called when the authentication flow finished successfully. * - * @param authentication with the tokens. + * @param credentials with the tokens. */ - public abstract void onAuthentication(Authentication authentication); + public abstract void onAuthentication(Credentials credentials); /** * Called when the user goes back and closes the activity, without using an Authentication flow. @@ -79,13 +77,10 @@ private void parseAuthentication(Intent data) { String tokenType = data.getStringExtra(Constants.TOKEN_TYPE_EXTRA); String refreshToken = data.getStringExtra(Constants.REFRESH_TOKEN_EXTRA); Credentials credentials = new Credentials(idToken, accessToken, tokenType, refreshToken); - UserProfile profile = (UserProfile) data.getSerializableExtra(Constants.PROFILE_EXTRA); - - Authentication authentication = new Authentication(profile, credentials); if (idToken != null && accessToken != null) { Log.d(TAG, "User authenticated!"); - onAuthentication(authentication); + onAuthentication(credentials); } else { Log.e(TAG, "Error parsing authentication data: id_token or access_token are missing."); LockException up = new LockException(R.string.com_auth0_lock_social_error_authentication); diff --git a/lib/src/main/java/com/auth0/android/lock/Constants.java b/lib/src/main/java/com/auth0/android/lock/Constants.java index 1abe2466c..c1629319b 100644 --- a/lib/src/main/java/com/auth0/android/lock/Constants.java +++ b/lib/src/main/java/com/auth0/android/lock/Constants.java @@ -37,7 +37,6 @@ abstract class Constants { static final String ACCESS_TOKEN_EXTRA = "com.auth0.android.lock.extra.AccessToken"; static final String TOKEN_TYPE_EXTRA = "com.auth0.android.lock.extra.TokenType"; static final String REFRESH_TOKEN_EXTRA = "com.auth0.android.lock.extra.RefreshToken"; - static final String PROFILE_EXTRA = "com.auth0.android.lock.extra.Profile"; static final String EMAIL_EXTRA = "com.auth0.android.lock.extra.Email"; static final String USERNAME_EXTRA = "com.auth0.android.lock.extra.Username"; } diff --git a/lib/src/main/java/com/auth0/android/lock/LockActivity.java b/lib/src/main/java/com/auth0/android/lock/LockActivity.java index f852bdccf..bc00a4dbd 100644 --- a/lib/src/main/java/com/auth0/android/lock/LockActivity.java +++ b/lib/src/main/java/com/auth0/android/lock/LockActivity.java @@ -210,8 +210,8 @@ private boolean isLaunchConfigValid() { } boolean launchedForResult = getCallingActivity() != null; - if (options.useBrowser() && launchedForResult) { - Log.e(TAG, "You're not allowed to useBrowser and startActivityForResult at the same time."); + if (launchedForResult){ + Log.e(TAG, "You're not allowed to start Lock with startActivityForResult."); return false; } boolean launchedAsSingleTask = (getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0; @@ -243,7 +243,6 @@ private void deliverAuthenticationResult(Authentication result) { intent.putExtra(Constants.ACCESS_TOKEN_EXTRA, result.getCredentials().getAccessToken()); intent.putExtra(Constants.REFRESH_TOKEN_EXTRA, result.getCredentials().getRefreshToken()); intent.putExtra(Constants.TOKEN_TYPE_EXTRA, result.getCredentials().getType()); - intent.putExtra(Constants.PROFILE_EXTRA, result.getProfile()); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); finish(); diff --git a/lib/src/main/java/com/auth0/android/lock/PasswordlessLockActivity.java b/lib/src/main/java/com/auth0/android/lock/PasswordlessLockActivity.java index fcdfb2881..383a136c6 100644 --- a/lib/src/main/java/com/auth0/android/lock/PasswordlessLockActivity.java +++ b/lib/src/main/java/com/auth0/android/lock/PasswordlessLockActivity.java @@ -222,8 +222,8 @@ private boolean isLaunchConfigValid() { } boolean launchedForResult = getCallingActivity() != null; - if (options.useBrowser() && launchedForResult) { - Log.e(TAG, "You're not allowed to useBrowser and startActivityForResult at the same time."); + if (launchedForResult){ + Log.e(TAG, "You're not allowed to start Lock with startActivityForResult."); return false; } if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { @@ -261,7 +261,6 @@ private void deliverAuthenticationResult(Authentication result) { intent.putExtra(Constants.ACCESS_TOKEN_EXTRA, result.getCredentials().getAccessToken()); intent.putExtra(Constants.REFRESH_TOKEN_EXTRA, result.getCredentials().getRefreshToken()); intent.putExtra(Constants.TOKEN_TYPE_EXTRA, result.getCredentials().getType()); - intent.putExtra(Constants.PROFILE_EXTRA, result.getProfile()); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); finish(); diff --git a/lib/src/main/java/com/auth0/android/lock/errors/SignUpAuthenticationErrorBuilder.java b/lib/src/main/java/com/auth0/android/lock/errors/SignUpAuthenticationErrorBuilder.java index ec5052a49..8705ef97a 100644 --- a/lib/src/main/java/com/auth0/android/lock/errors/SignUpAuthenticationErrorBuilder.java +++ b/lib/src/main/java/com/auth0/android/lock/errors/SignUpAuthenticationErrorBuilder.java @@ -61,7 +61,7 @@ public AuthenticationError buildFrom(Throwable throwable) { if (UNAUTHORIZED_ERROR.equalsIgnoreCase(errorCode) && errorDescription != null) { return new AuthenticationError(errorDescription, ErrorType.UNAUTHORIZED, throwable); } else if (USER_EXISTS_ERROR.equalsIgnoreCase(errorCode) || USERNAME_EXISTS_ERROR.equalsIgnoreCase(errorCode)) { - return new AuthenticationError(userExistsResource, ErrorType.INVALID_CREDENTIALS, throwable); + return new AuthenticationError(userExistsResource, ErrorType.USER_EXISTS, throwable); } else if (errorDescription != null) { return new AuthenticationError(errorDescription, ErrorType.UNKNOWN, throwable); } diff --git a/lib/src/main/java/com/auth0/android/lock/provider/PKCE.java b/lib/src/main/java/com/auth0/android/lock/provider/PKCE.java index 5010ac82a..09e31539c 100644 --- a/lib/src/main/java/com/auth0/android/lock/provider/PKCE.java +++ b/lib/src/main/java/com/auth0/android/lock/provider/PKCE.java @@ -92,7 +92,9 @@ private String generateCodeChallenge() { * @param callback to notify the result of this call to. */ public void getToken(String authorizationCode, @NonNull final AuthCallback callback) { - apiClient.token(authorizationCode, codeVerifier, redirectUri).start(new BaseCallback() { + apiClient.token(authorizationCode, redirectUri) + .setCodeVerifier(codeVerifier) + .start(new BaseCallback() { @Override public void onSuccess(Credentials payload) { callback.onSuccess(payload); diff --git a/lib/src/main/java/com/auth0/android/lock/views/ClassicLockView.java b/lib/src/main/java/com/auth0/android/lock/views/ClassicLockView.java index 688940b6b..c330fc92b 100644 --- a/lib/src/main/java/com/auth0/android/lock/views/ClassicLockView.java +++ b/lib/src/main/java/com/auth0/android/lock/views/ClassicLockView.java @@ -122,7 +122,9 @@ private void showContentLayout() { actionButton.setVisibility(GONE); } - if (configuration.allowForgotPassword() && configuration.getInitialScreen() == InitialScreen.FORGOT_PASSWORD) { + if (configuration.getInitialScreen() == InitialScreen.SIGN_UP) { + showBottomBanner(true); + } else if (configuration.allowForgotPassword() && configuration.getInitialScreen() == InitialScreen.FORGOT_PASSWORD) { showChangePasswordForm(true); } } diff --git a/lib/src/main/java/com/auth0/android/lock/views/FormLayout.java b/lib/src/main/java/com/auth0/android/lock/views/FormLayout.java index 9face1c49..ecd926bbf 100644 --- a/lib/src/main/java/com/auth0/android/lock/views/FormLayout.java +++ b/lib/src/main/java/com/auth0/android/lock/views/FormLayout.java @@ -115,13 +115,12 @@ private void displayInitialScreen() { return; } int initialScreen = lockWidget.getConfiguration().getInitialScreen(); - switch (initialScreen) { - case InitialScreen.FORGOT_PASSWORD: - case InitialScreen.LOG_IN: - changeFormMode(ModeSelectionView.Mode.LOG_IN); - case InitialScreen.SIGN_UP: - changeFormMode(ModeSelectionView.Mode.SIGN_UP); - break; + int mode = initialScreen == InitialScreen.SIGN_UP ? ModeSelectionView.Mode.SIGN_UP : ModeSelectionView.Mode.LOG_IN; + + if (modeSelectionView != null) { + modeSelectionView.setSelectedMode(mode); + } else { + changeFormMode(mode); } } diff --git a/lib/src/main/java/com/auth0/android/lock/views/ModeSelectionView.java b/lib/src/main/java/com/auth0/android/lock/views/ModeSelectionView.java index a11818cea..c19ec18b8 100644 --- a/lib/src/main/java/com/auth0/android/lock/views/ModeSelectionView.java +++ b/lib/src/main/java/com/auth0/android/lock/views/ModeSelectionView.java @@ -41,6 +41,7 @@ public class ModeSelectionView extends RelativeLayout implements RadioGroup.OnCheckedChangeListener { private final ModeSelectedListener callback; + private RadioGroup modeGroup; @IntDef({LOG_IN, SIGN_UP}) @Retention(RetentionPolicy.SOURCE) @@ -57,10 +58,14 @@ public ModeSelectionView(Context context, @NonNull ModeSelectedListener listener private void init() { inflate(getContext(), R.layout.com_auth0_lock_mode_selection_layout, this); - RadioGroup modeGroup = (RadioGroup) findViewById(R.id.com_auth0_lock_form_radio_mode_group); + modeGroup = (RadioGroup) findViewById(R.id.com_auth0_lock_form_radio_mode_group); modeGroup.setOnCheckedChangeListener(this); } + public void setSelectedMode(@Mode int mode) { + modeGroup.check(mode == LOG_IN ? R.id.com_auth0_lock_mode_log_in : R.id.com_auth0_lock_mode_sign_up); + } + @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.com_auth0_lock_mode_log_in) { diff --git a/lib/src/main/res/layout/com_auth0_lock_mode_selection_layout.xml b/lib/src/main/res/layout/com_auth0_lock_mode_selection_layout.xml index f295a3bbb..4b312dade 100644 --- a/lib/src/main/res/layout/com_auth0_lock_mode_selection_layout.xml +++ b/lib/src/main/res/layout/com_auth0_lock_mode_selection_layout.xml @@ -37,7 +37,6 @@ style="@style/Lock.Theme.Text.ModeSwitcher" android:layout_marginLeft="2dp" android:background="@drawable/com_auth0_lock_radio_button_left_background" - android:checked="true" android:text="@string/com_auth0_lock_action_log_in" /> extends BaseMatcher { - private final Matcher authenticationMatcher; + private final Matcher authenticationMatcher; private final Matcher canceledMatcher; private final Matcher errorMatcher; - public AuthenticationCallbackMatcher(Matcher authenticationMatcher, Matcher canceledMatcher, Matcher errorMatcher) { + public AuthenticationCallbackMatcher(Matcher authenticationMatcher, Matcher canceledMatcher, Matcher errorMatcher) { this.authenticationMatcher = authenticationMatcher; this.canceledMatcher = canceledMatcher; this.errorMatcher = errorMatcher; @@ -75,19 +72,19 @@ public void describeTo(Description description) { } public static Matcher isCanceled() { - return new AuthenticationCallbackMatcher<>(is(nullValue(Authentication.class)), equalTo(true), is(nullValue(Throwable.class))); + return new AuthenticationCallbackMatcher<>(is(nullValue(Credentials.class)), equalTo(true), is(nullValue(Throwable.class))); } public static Matcher hasAuthentication() { - return new AuthenticationCallbackMatcher<>(is(notNullValue(Authentication.class)), equalTo(false), is(nullValue(Throwable.class))); + return new AuthenticationCallbackMatcher<>(is(notNullValue(Credentials.class)), equalTo(false), is(nullValue(Throwable.class))); } public static Matcher hasError() { - return new AuthenticationCallbackMatcher<>(is(nullValue(Authentication.class)), equalTo(false), is(notNullValue(Throwable.class))); + return new AuthenticationCallbackMatcher<>(is(nullValue(Credentials.class)), equalTo(false), is(notNullValue(Throwable.class))); } public static Matcher hasNoError() { - return new AuthenticationCallbackMatcher<>(anyOf(nullValue(Authentication.class), notNullValue(Authentication.class)), any(Boolean.class), is(nullValue(Throwable.class))); + return new AuthenticationCallbackMatcher<>(anyOf(nullValue(Credentials.class), notNullValue(Credentials.class)), any(Boolean.class), is(nullValue(Throwable.class))); } } diff --git a/lib/src/test/java/com/auth0/android/lock/utils/MockLockCallback.java b/lib/src/test/java/com/auth0/android/lock/utils/MockLockCallback.java index efef78f9d..7e6bf6a55 100644 --- a/lib/src/test/java/com/auth0/android/lock/utils/MockLockCallback.java +++ b/lib/src/test/java/com/auth0/android/lock/utils/MockLockCallback.java @@ -25,22 +25,22 @@ package com.auth0.android.lock.utils; import com.auth0.android.lock.AuthenticationCallback; -import com.auth0.authentication.result.Authentication; +import com.auth0.authentication.result.Credentials; import java.util.concurrent.Callable; public class MockLockCallback extends AuthenticationCallback { - private Authentication authentication; + private Credentials credentials; private boolean canceled; private LockException error; - public Callable authentication() { - return new Callable() { + public Callable authentication() { + return new Callable() { @Override @LockEvent - public Authentication call() throws Exception { - return authentication; + public Credentials call() throws Exception { + return credentials; } }; } @@ -65,8 +65,8 @@ public LockException call() throws Exception { } @Override - public void onAuthentication(Authentication authentication) { - this.authentication = authentication; + public void onAuthentication(Credentials credentials) { + this.credentials = credentials; } @Override @@ -79,7 +79,7 @@ public void onError(LockException error) { this.error = error; } - public Authentication getAuthentication() { - return this.authentication; + public Credentials getCredentials() { + return this.credentials; } } diff --git a/proguard/proguard-gson.pro b/proguard/proguard-gson.pro new file mode 100644 index 000000000..b5e9f7e34 --- /dev/null +++ b/proguard/proguard-gson.pro @@ -0,0 +1,4 @@ +# Gson + +-keepattributes Signature +-keepattributes *Annotation* \ No newline at end of file diff --git a/proguard/proguard-jackson-2.pro b/proguard/proguard-jackson-2.pro deleted file mode 100644 index 1e09ed92a..000000000 --- a/proguard/proguard-jackson-2.pro +++ /dev/null @@ -1,11 +0,0 @@ -#Jackson 2.x - --keepattributes *Annotation*, EnclosingMethod --keep class com.fasterxml.jackson.databind.ObjectMapper { - public ; - protected ; -} --keep class com.fasterxml.jackson.databind.ObjectWriter { - public ** writeValueAsString(**); -} --dontwarn org.w3c.dom.bootstrap.DOMImplementationRegistry \ No newline at end of file diff --git a/proguard/proguard-lock-2.pro b/proguard/proguard-lock-2.pro index ba7dd5b69..dac068047 100644 --- a/proguard/proguard-lock-2.pro +++ b/proguard/proguard-lock-2.pro @@ -12,6 +12,10 @@ public static final ** CREATOR; } +-keepclassmembers class ** { + com.auth0.android.lock.views.ViewUtils$Corners *; +} + ## Data Models / POJOs -keep class com.auth0.android.lock.utils.Strategies { *; } -keep class com.auth0.android.lock.utils.Strategy { *; }