Skip to content

Commit

Permalink
Merge pull request #286 from auth0/fix-rebase-issues
Browse files Browse the repository at this point in the history
Fix issues found on of beta.1
  • Loading branch information
hzalaz committed Jun 6, 2016
2 parents ae5ad22 + 18c6b6b commit b5f14ae
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 128 deletions.
25 changes: 5 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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
}

Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
33 changes: 6 additions & 27 deletions app/src/main/java/com/auth0/android/lock/app/DemoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion lib/src/main/java/com/auth0/android/lock/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
5 changes: 2 additions & 3 deletions lib/src/main/java/com/auth0/android/lock/LockActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/src/main/java/com/auth0/android/lock/provider/PKCE.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Credentials>() {
apiClient.token(authorizationCode, redirectUri)
.setCodeVerifier(codeVerifier)
.start(new BaseCallback<Credentials>() {
@Override
public void onSuccess(Credentials payload) {
callback.onSuccess(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
13 changes: 6 additions & 7 deletions lib/src/main/java/com/auth0/android/lock/views/FormLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<RadioButton
Expand Down
Loading

0 comments on commit b5f14ae

Please sign in to comment.