Skip to content

Commit

Permalink
[ESD-27178] Fix browser not found issue not being surfaced (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
poovamraj authored Apr 4, 2023
1 parent bc8c82b commit b3ddb90
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
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
23 changes: 18 additions & 5 deletions android/src/main/java/com/auth0/react/AuthenticationActivity.java
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();
}
}

}

0 comments on commit b3ddb90

Please sign in to comment.