Skip to content

Commit 34dcd59

Browse files
fixed crash on login/logout if main activity has been destroyed/unbound (#630)
Co-authored-by: Sam <[email protected]>
1 parent 3a21fdc commit 34dcd59

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class FlutterAppauthPlugin
6060
private static final String TOKEN_ERROR_CODE = "token_failed";
6161
private static final String END_SESSION_ERROR_CODE = "end_session_failed";
6262
private static final String NULL_INTENT_ERROR_CODE = "null_intent";
63+
private static final String NULL_ACTIVITY_ERROR_CODE = "null_activity";
6364
private static final String INVALID_CLAIMS_ERROR_CODE = "invalid_claims";
6465
private static final String NO_BROWSER_AVAILABLE_ERROR_CODE = "no_browser_available";
6566

@@ -74,6 +75,9 @@ public class FlutterAppauthPlugin
7475

7576
private static final String NULL_INTENT_ERROR_FORMAT =
7677
"Failed to authorize: Null intent received";
78+
79+
private static final String NULL_ACTIVITY_ERROR_FORMAT =
80+
"Failed to authorize: Null activity received";
7781
private static final String NO_BROWSER_AVAILABLE_ERROR_FORMAT =
7882
"Failed to authorize: No suitable browser is available";
7983

@@ -466,6 +470,8 @@ private void performAuthorization(
466470
authIntent, exchangeCode ? RC_AUTH_EXCHANGE_CODE : RC_AUTH);
467471
} catch (ActivityNotFoundException ex) {
468472
finishWithError(NO_BROWSER_AVAILABLE_ERROR_CODE, NO_BROWSER_AVAILABLE_ERROR_FORMAT, ex);
473+
} catch (NullPointerException ex) {
474+
finishWithError(NULL_ACTIVITY_ERROR_CODE, NULL_ACTIVITY_ERROR_FORMAT, ex);
469475
}
470476
}
471477

@@ -576,7 +582,12 @@ private void performEndSessionRequest(
576582
final EndSessionRequest endSessionRequest = endSessionRequestBuilder.build();
577583
AuthorizationService authorizationService = getAuthorizationService();
578584
Intent endSessionIntent = authorizationService.getEndSessionRequestIntent(endSessionRequest);
579-
mainActivity.startActivityForResult(endSessionIntent, RC_END_SESSION);
585+
586+
try {
587+
mainActivity.startActivityForResult(endSessionIntent, RC_END_SESSION);
588+
} catch (NullPointerException ex) {
589+
finishWithError(NULL_ACTIVITY_ERROR_CODE, NULL_ACTIVITY_ERROR_FORMAT, ex);
590+
}
580591
}
581592

582593
private AuthorizationService getAuthorizationService() {

0 commit comments

Comments
 (0)