Skip to content
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

Fix bug when canceling WebAuth flow #120

Merged
merged 1 commit into from
Oct 5, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@ public class AuthenticationActivity extends Activity {
static final String EXTRA_USE_BROWSER = "com.auth0.android.EXTRA_USE_BROWSER";
static final String EXTRA_USE_FULL_SCREEN = "com.auth0.android.EXTRA_USE_FULL_SCREEN";
static final String EXTRA_CONNECTION_NAME = "com.auth0.android.EXTRA_CONNECTION_NAME";
static final String EXTRA_AUTHORIZE_URI = "com.auth0.android.EXTRA_AUTHORIZE_URI";
private static final String EXTRA_INTENT_LAUNCHED = "com.auth0.android.EXTRA_INTENT_LAUNCHED";

private boolean intentLaunched;
private CustomTabsController customTabsController;

static void authenticateUsingBrowser(Context context, Uri authorizeUri) {
Intent intent = new Intent(context, AuthenticationActivity.class);
intent.setData(authorizeUri);
intent.putExtra(AuthenticationActivity.EXTRA_AUTHORIZE_URI, authorizeUri);
intent.putExtra(AuthenticationActivity.EXTRA_USE_BROWSER, true);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}

static void authenticateUsingWebView(Activity activity, Uri authorizeUri, int requestCode, String connection, boolean useFullScreen) {
Intent intent = new Intent(activity, AuthenticationActivity.class);
intent.setData(authorizeUri);
intent.putExtra(AuthenticationActivity.EXTRA_AUTHORIZE_URI, authorizeUri);
intent.putExtra(AuthenticationActivity.EXTRA_USE_BROWSER, false);
intent.putExtra(AuthenticationActivity.EXTRA_USE_FULL_SCREEN, useFullScreen);
intent.putExtra(AuthenticationActivity.EXTRA_CONNECTION_NAME, connection);
Expand Down Expand Up @@ -77,6 +78,7 @@ protected void onResume() {
if (getIntent().getData() != null) {
deliverSuccessfulAuthenticationResult(getIntent());
}
setResult(RESULT_CANCELED);
finish();
}

Expand All @@ -91,7 +93,7 @@ protected void onDestroy() {

private void launchAuthenticationIntent() {
Bundle extras = getIntent().getExtras();
final Uri authorizeUri = getIntent().getData();
Uri authorizeUri = extras.getParcelable(EXTRA_AUTHORIZE_URI);
if (!extras.getBoolean(EXTRA_USE_BROWSER, true)) {
Intent intent = new Intent(this, WebAuthActivity.class);
intent.setData(authorizeUri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasData;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasFlag;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.notNullValue;
Expand Down Expand Up @@ -144,9 +145,6 @@ public void shouldCancelAuthenticationUsingBrowser() throws Exception {
activityController.pause().stop();
//Browser is shown

Intent authenticationResultIntent = new Intent();
authenticationResultIntent.setData(null);
activityController.newIntent(authenticationResultIntent);
activityController.start().resume();

assertThat(activity.getDeliveredIntent(), is(nullValue()));
Expand Down Expand Up @@ -254,9 +252,7 @@ public void shouldCancelAuthenticationUsingWebView() throws Exception {
activityController.pause().stop();
//WebViewActivity is shown

Intent authenticationResultIntent = new Intent();
authenticationResultIntent.setData(resultUri);
activityShadow.receiveResult(webViewIntent.intent, Activity.RESULT_CANCELED, authenticationResultIntent);
activityShadow.receiveResult(webViewIntent.intent, Activity.RESULT_CANCELED, null);

assertThat(activity.getDeliveredIntent(), is(nullValue()));
assertThat(activity.isFinishing(), is(true));
Expand All @@ -274,9 +270,10 @@ public void shouldLaunchForBrowserAuthentication() throws Exception {
Assert.assertThat(intent, is(notNullValue()));
Assert.assertThat(intent, hasComponent(AuthenticationActivity.class.getName()));
Assert.assertThat(intent, hasFlag(Intent.FLAG_ACTIVITY_CLEAR_TOP));
Assert.assertThat(intent, hasData(uri));
Assert.assertThat(intent, not(hasData(uri)));

Bundle extras = intent.getExtras();
Assert.assertThat((Uri) extras.getParcelable(AuthenticationActivity.EXTRA_AUTHORIZE_URI), is(uri));
Assert.assertThat(extras.containsKey(AuthenticationActivity.EXTRA_CONNECTION_NAME), is(false));
Assert.assertThat(extras.containsKey(AuthenticationActivity.EXTRA_USE_FULL_SCREEN), is(false));
Assert.assertThat(extras.containsKey(AuthenticationActivity.EXTRA_USE_BROWSER), is(true));
Expand All @@ -293,9 +290,10 @@ public void shouldLaunchForWebViewAuthentication() throws Exception {
Assert.assertThat(intent, is(notNullValue()));
Assert.assertThat(intent, hasComponent(AuthenticationActivity.class.getName()));
Assert.assertThat(intent, hasFlag(Intent.FLAG_ACTIVITY_CLEAR_TOP));
Assert.assertThat(intent, hasData(uri));
Assert.assertThat(intent, not(hasData(uri)));

Bundle extras = intentCaptor.getValue().getExtras();
Assert.assertThat((Uri) extras.getParcelable(AuthenticationActivity.EXTRA_AUTHORIZE_URI), is(uri));
Assert.assertThat(extras.containsKey(AuthenticationActivity.EXTRA_CONNECTION_NAME), is(true));
Assert.assertThat(extras.getString(AuthenticationActivity.EXTRA_CONNECTION_NAME), is("facebook"));
Assert.assertThat(extras.containsKey(AuthenticationActivity.EXTRA_USE_FULL_SCREEN), is(true));
Expand Down
Loading