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

[flutter_appauth] Feature: Android pendingOperation callback #496

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
*/
public class FlutterAppauthPlugin implements FlutterPlugin, MethodCallHandler, PluginRegistry.ActivityResultListener, ActivityAware {
private static final String AUTHORIZE_AND_EXCHANGE_CODE_METHOD = "authorizeAndExchangeCode";
private static final String HAS_PENDING_OPERATION = "hasPendingOperation";
private static final String AUTHORIZE_METHOD = "authorize";
private static final String TOKEN_METHOD = "token";
private static final String END_SESSION_METHOD = "endSession";
Expand Down Expand Up @@ -78,6 +79,10 @@ public class FlutterAppauthPlugin implements FlutterPlugin, MethodCallHandler, P
private boolean allowInsecureConnections;
private AuthorizationService defaultAuthorizationService;
private AuthorizationService insecureAuthorizationService;

private final String methodChannelName = "crossingthestreams.io/flutter_appauth";

private MethodChannel channel;

private void setActivity(Activity flutterActivity) {
this.mainActivity = flutterActivity;
Expand All @@ -90,7 +95,7 @@ private void onAttachedToEngine(Context context, BinaryMessenger binaryMessenger
authConfigBuilder.setConnectionBuilder(InsecureConnectionBuilder.INSTANCE);
authConfigBuilder.setSkipIssuerHttpsCheck(true);
insecureAuthorizationService = new AuthorizationService(applicationContext, authConfigBuilder.build());
final MethodChannel channel = new MethodChannel(binaryMessenger, "crossingthestreams.io/flutter_appauth");
channel = new MethodChannel(binaryMessenger, methodChannelName);
channel.setMethodCallHandler(this);
}

Expand Down Expand Up @@ -461,13 +466,17 @@ private void finishWithSuccess(Object data) {
if (pendingOperation != null) {
pendingOperation.result.success(data);
pendingOperation = null;
} else {
channel.invokeMethod(HAS_PENDING_OPERATION, data);
}
}

private void finishWithError(String errorCode, String errorMessage, String errorDetails) {
if (pendingOperation != null) {
pendingOperation.result.error(errorCode, errorMessage, errorDetails);
pendingOperation = null;
} else {
channel.invokeMethod(HAS_PENDING_OPERATION, errorCode);
}
}

Expand All @@ -487,9 +496,6 @@ private String getCauseFromException(Exception ex) {

@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent intent) {
if (pendingOperation == null) {
return false;
}
if (requestCode == RC_AUTH_EXCHANGE_CODE || requestCode == RC_AUTH) {
if (intent == null) {
finishWithError(NULL_INTENT_ERROR_CODE, NULL_INTENT_ERROR_FORMAT, null);
Expand Down