Skip to content

Commit

Permalink
[flutter_appauth] Check if intent is null in onActivityResult (MaikuB…
Browse files Browse the repository at this point in the history
…#146)

* Check if intent is null in onActivityResult

This seems to crash apps when intent is null.

* Update FlutterAppauthPlugin.java

* Update FlutterAppauthPlugin.java

* tweaks to PR and bump plugin version

Co-authored-by: Michael Bui <[email protected]>
  • Loading branch information
li0nza and MaikuB authored Oct 11, 2020
1 parent a08796a commit defe695
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions flutter_appauth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.2+6

* [Android] community has reported that there seem to be instances where the plugin encounters a null intent on some devices upon processing a authorisation request. This resulted in a crash before but will now throw a `PlatformException`. Thanks to the PR from [Leon Havenga](https://github.com/li0nza)

## 0.9.2+5

* Updated the Android setup section in the readme to include information for apps targeting Android 11 (API 30) or newer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ public class FlutterAppauthPlugin implements FlutterPlugin, MethodCallHandler, P
private static final String AUTHORIZE_AND_EXCHANGE_CODE_ERROR_CODE = "authorize_and_exchange_code_failed";
private static final String AUTHORIZE_ERROR_CODE = "authorize_failed";
private static final String TOKEN_ERROR_CODE = "token_failed";
private static final String NULL_INTENT_ERROR_CODE = "null_intent";

private static final String DISCOVERY_ERROR_MESSAGE_FORMAT = "Error retrieving discovery document: [error: %s, description: %s]";
private static final String TOKEN_ERROR_MESSAGE_FORMAT = "Failed to get token: [error: %s, description: %s]";
private static final String AUTHORIZE_ERROR_MESSAGE_FORMAT = "Failed to authorize: [error: %s, description: %s]";
private static final String NULL_INTENT_ERROR_FORMAT = "Failed to authorize: Null intent received";

private final int RC_AUTH_EXCHANGE_CODE = 65030;
private final int RC_AUTH = 65031;
Expand Down Expand Up @@ -385,9 +387,13 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent intent)
return false;
}
if (requestCode == RC_AUTH_EXCHANGE_CODE || requestCode == RC_AUTH) {
final AuthorizationResponse authResponse = AuthorizationResponse.fromIntent(intent);
AuthorizationException ex = AuthorizationException.fromIntent(intent);
processAuthorizationData(authResponse, ex, requestCode == RC_AUTH_EXCHANGE_CODE);
if (intent == null) {
finishWithError(NULL_INTENT_ERROR_CODE, NULL_INTENT_ERROR_FORMAT);
} else {
final AuthorizationResponse authResponse = AuthorizationResponse.fromIntent(intent);
AuthorizationException ex = AuthorizationException.fromIntent(intent);
processAuthorizationData(authResponse, ex, requestCode == RC_AUTH_EXCHANGE_CODE);
}
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion flutter_appauth/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_appauth
description: This plugin provides an abstraction around the Android and iOS AppAuth SDKs so it can be used to communicate with OAuth 2.0 and OpenID Connect providers
version: 0.9.2+5
version: 0.9.2+6
homepage: https://github.com/MaikuB/flutter_appauth/tree/master/flutter_appauth

environment:
Expand Down

0 comments on commit defe695

Please sign in to comment.