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

Handle incomplete promise in web authentication #798

Merged
merged 4 commits into from
Nov 10, 2023
Merged
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
10 changes: 9 additions & 1 deletion android/src/main/java/com/auth0/react/A0Auth0Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class A0Auth0Module extends ReactContextBaseJavaModule implements Activit
private final ReactApplicationContext reactContext;
private Auth0 auth0;
private SecureCredentialsManager secureCredentialsManager;
private Promise webAuthPromise;

public A0Auth0Module(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
Expand Down Expand Up @@ -141,6 +143,7 @@ public String getName() {

@ReactMethod
public void webAuth(String scheme, String redirectUri, String state, String nonce, String audience, String scope, String connection, int maxAge, String organization, String invitationUrl, int leeway, boolean ephemeralSession, ReadableMap additionalParameters, Promise promise) {
this.webAuthPromise = promise;
Map<String,String> cleanedParameters = new HashMap<>();
for (Map.Entry<String, Object> entry : additionalParameters.toHashMap().entrySet()) {
if (entry.getValue() != null) {
Expand Down Expand Up @@ -182,11 +185,13 @@ public void webAuth(String scheme, String redirectUri, String state, String nonc
public void onSuccess(Credentials result) {
ReadableMap map = CredentialsParser.toMap(result);
promise.resolve(map);
webAuthPromise = null;
}

@Override
public void onFailure(@NonNull AuthenticationException error) {
handleError(error, promise);
webAuthPromise = null;
}
});
}
Expand Down Expand Up @@ -241,6 +246,9 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,

@Override
public void onNewIntent(Intent intent) {
// NO OP
if(webAuthPromise != null) {
webAuthPromise.reject("a0.session.browser_terminated", "The browser window was closed by a new instance of the application");
webAuthPromise = null;
}
}
}