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

[ESD-27178] Fix browser not found issue not being surfaced #611

Merged
merged 2 commits into from
Apr 4, 2023
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
18 changes: 18 additions & 0 deletions android/src/main/java/com/auth0/react/A0Auth0Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class A0Auth0Module extends ReactContextBaseJavaModule implements Activit
private static final String SHA_256 = "SHA-256";
private static final String ERROR_CODE = "a0.invalid_state.credential_manager_exception";
private static final int LOCAL_AUTH_REQUEST_CODE = 150;
public static final int NO_BROWSER_FOUND_RESULT_CODE = 1404;
public static final int UNKNOWN_ERROR_RESULT_CODE = 1405;

private final ReactApplicationContext reactContext;
private Callback callback;
Expand Down Expand Up @@ -226,6 +228,22 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,
return;
}

if (resultCode == NO_BROWSER_FOUND_RESULT_CODE) {
final WritableMap error = Arguments.createMap();
error.putString("name", "a0.browser_not_available");
error.putString("message", "No Browser application is installed.");
callback.invoke(error);
return;
}

if (resultCode == UNKNOWN_ERROR_RESULT_CODE) {
final WritableMap error = Arguments.createMap();
error.putString("name", "a0.response.invalid");
error.putString("message", "unknown error");
callback.invoke(error);
return;
}

if (cb == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.auth0.react;

import static com.auth0.react.A0Auth0Module.NO_BROWSER_FOUND_RESULT_CODE;
import static com.auth0.react.A0Auth0Module.UNKNOWN_ERROR_RESULT_CODE;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
Expand Down Expand Up @@ -65,11 +69,20 @@ protected void onNewIntent(@Nullable Intent intent) {
}

private void launchAuthenticationIntent() {
Bundle extras = getIntent().getExtras();
Uri authorizeUri = extras.getParcelable(EXTRA_AUTHORIZE_URI);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, authorizeUri);
try {
Bundle extras = getIntent().getExtras();
Uri authorizeUri = extras.getParcelable(EXTRA_AUTHORIZE_URI);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, authorizeUri);
} catch (Exception e) {
if(e instanceof ActivityNotFoundException) {
setResult(NO_BROWSER_FOUND_RESULT_CODE);
} else {
setResult(UNKNOWN_ERROR_RESULT_CODE);
}
finish();
}
}

}