Skip to content

Commit ae09747

Browse files
authored
Avoid crash on Android when no browsers are found (#599)
Handles authorize and refresh when config is retrieved from OpenID well-known endpoint
1 parent bacd037 commit ae09747

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

android/src/main/java/com/rnappauth/RNAppAuthModule.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,21 @@ public void onFetchConfigurationCompleted(
270270

271271
setServiceConfiguration(issuer, fetchedConfiguration);
272272

273-
authorizeWithConfiguration(
274-
fetchedConfiguration,
275-
appAuthConfiguration,
276-
clientId,
277-
scopes,
278-
redirectUrl,
279-
usePKCE,
280-
additionalParametersMap
281-
);
273+
try {
274+
authorizeWithConfiguration(
275+
fetchedConfiguration,
276+
appAuthConfiguration,
277+
clientId,
278+
scopes,
279+
redirectUrl,
280+
usePKCE,
281+
additionalParametersMap
282+
);
283+
} catch (ActivityNotFoundException e) {
284+
promise.reject("browser_not_found", e.getMessage());
285+
} catch (Exception e) {
286+
promise.reject("authentication_failed", e.getMessage());
287+
}
282288
}
283289
},
284290
builder
@@ -354,18 +360,24 @@ public void onFetchConfigurationCompleted(
354360

355361
setServiceConfiguration(issuer, fetchedConfiguration);
356362

357-
refreshWithConfiguration(
358-
fetchedConfiguration,
359-
appAuthConfiguration,
360-
refreshToken,
361-
clientId,
362-
scopes,
363-
redirectUrl,
364-
additionalParametersMap,
365-
clientAuthMethod,
366-
clientSecret,
367-
promise
368-
);
363+
try {
364+
refreshWithConfiguration(
365+
fetchedConfiguration,
366+
appAuthConfiguration,
367+
refreshToken,
368+
clientId,
369+
scopes,
370+
redirectUrl,
371+
additionalParametersMap,
372+
clientAuthMethod,
373+
clientSecret,
374+
promise
375+
);
376+
} catch (ActivityNotFoundException e) {
377+
promise.reject("browser_not_found", e.getMessage());
378+
} catch (Exception e) {
379+
promise.reject("token_refresh_failed", e.getMessage());
380+
}
369381
}
370382
},
371383
builder);

0 commit comments

Comments
 (0)