From 4321f9b492a472d3f0bea71ea35eeb9dd0d5c7e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20Ali=20Dikc=CC=A7=C4=B1nar?= Date: Fri, 17 May 2024 22:07:09 +0300 Subject: [PATCH 1/4] feat: invoke method channell added --- .../flutterappauth/FlutterAppauthPlugin.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java b/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java index a212b82..7d60a84 100644 --- a/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java +++ b/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -73,16 +74,20 @@ public class FlutterAppauthPlugin implements FlutterPlugin, MethodCallHandler, P private Context applicationContext; private Activity mainActivity; - private PendingOperation pendingOperation; + private static PendingOperation pendingOperation; private String clientSecret; private boolean allowInsecureConnections; private AuthorizationService defaultAuthorizationService; private AuthorizationService insecureAuthorizationService; - + private void setActivity(Activity flutterActivity) { this.mainActivity = flutterActivity; } + private final String methodChannelId = "crossingthestreams.io/flutter_appauth"; + + private MethodChannel channel; + private void onAttachedToEngine(Context context, BinaryMessenger binaryMessenger) { this.applicationContext = context; defaultAuthorizationService = new AuthorizationService(this.applicationContext); @@ -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, methodChannelId); channel.setMethodCallHandler(this); } @@ -133,7 +138,7 @@ private void disposeAuthorizationServices() { insecureAuthorizationService = null; } - private void checkAndSetPendingOperation(String method, Result result) { + private synchronized void checkAndSetPendingOperation(String method, Result result) { if (pendingOperation != null) { throw new IllegalStateException( "Concurrent operations detected: " + pendingOperation.method + ", " + method); @@ -460,6 +465,8 @@ private void finishWithTokenError(AuthorizationException ex) { private void finishWithSuccess(Object data) { if (pendingOperation != null) { pendingOperation.result.success(data); + channel.invokeMethod(pendingOperation.method, data); + pendingOperation = null; } } @@ -486,7 +493,7 @@ private String getCauseFromException(Exception ex) { @Override - public boolean onActivityResult(int requestCode, int resultCode, Intent intent) { + public synchronized boolean onActivityResult(int requestCode, int resultCode, Intent intent) { if (pendingOperation == null) { return false; } From dabaa7be310525e415a1c691fd700381f066cb81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20Ali=20Dikc=CC=A7=C4=B1nar?= Date: Sat, 18 May 2024 01:45:58 +0300 Subject: [PATCH 2/4] feat: pending operation call back --- .../flutterappauth/FlutterAppauthPlugin.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java b/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java index 7d60a84..64101f7 100644 --- a/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java +++ b/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java @@ -5,7 +5,6 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; -import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -47,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"; @@ -74,20 +74,20 @@ public class FlutterAppauthPlugin implements FlutterPlugin, MethodCallHandler, P private Context applicationContext; private Activity mainActivity; - private static PendingOperation pendingOperation; + private PendingOperation pendingOperation; private String clientSecret; private boolean allowInsecureConnections; private AuthorizationService defaultAuthorizationService; private AuthorizationService insecureAuthorizationService; + private String methodChannelName = "crossingthestreams.io/flutter_appauth"; + + private MethodChannel channel; + private void setActivity(Activity flutterActivity) { this.mainActivity = flutterActivity; } - private final String methodChannelId = "crossingthestreams.io/flutter_appauth"; - - private MethodChannel channel; - private void onAttachedToEngine(Context context, BinaryMessenger binaryMessenger) { this.applicationContext = context; defaultAuthorizationService = new AuthorizationService(this.applicationContext); @@ -95,7 +95,7 @@ private void onAttachedToEngine(Context context, BinaryMessenger binaryMessenger authConfigBuilder.setConnectionBuilder(InsecureConnectionBuilder.INSTANCE); authConfigBuilder.setSkipIssuerHttpsCheck(true); insecureAuthorizationService = new AuthorizationService(applicationContext, authConfigBuilder.build()); - channel = new MethodChannel(binaryMessenger, methodChannelId); + channel = new MethodChannel(binaryMessenger, methodChannelName); channel.setMethodCallHandler(this); } @@ -138,7 +138,7 @@ private void disposeAuthorizationServices() { insecureAuthorizationService = null; } - private synchronized void checkAndSetPendingOperation(String method, Result result) { + private void checkAndSetPendingOperation(String method, Result result) { if (pendingOperation != null) { throw new IllegalStateException( "Concurrent operations detected: " + pendingOperation.method + ", " + method); @@ -465,9 +465,9 @@ private void finishWithTokenError(AuthorizationException ex) { private void finishWithSuccess(Object data) { if (pendingOperation != null) { pendingOperation.result.success(data); - channel.invokeMethod(pendingOperation.method, data); - pendingOperation = null; + } else { + channel.invokeMethod(HAS_PENDING_OPERATION, null); } } @@ -475,6 +475,8 @@ private void finishWithError(String errorCode, String errorMessage, String error if (pendingOperation != null) { pendingOperation.result.error(errorCode, errorMessage, errorDetails); pendingOperation = null; + } else { + channel.invokeMethod(HAS_PENDING_OPERATION, null); } } @@ -493,10 +495,7 @@ private String getCauseFromException(Exception ex) { @Override - public synchronized boolean onActivityResult(int requestCode, int resultCode, Intent intent) { - if (pendingOperation == null) { - return false; - } + public boolean onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == RC_AUTH_EXCHANGE_CODE || requestCode == RC_AUTH) { if (intent == null) { finishWithError(NULL_INTENT_ERROR_CODE, NULL_INTENT_ERROR_FORMAT, null); From d88c998d9c385e31cfd2429390b2a76c6d97d8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20Ali=20Dikc=CC=A7=C4=B1nar?= Date: Sat, 18 May 2024 02:09:40 +0300 Subject: [PATCH 3/4] feat: HAS_PENDING_OPERATION return data --- .../flutterappauth/FlutterAppauthPlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java b/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java index 64101f7..af9f35e 100644 --- a/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java +++ b/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java @@ -467,7 +467,7 @@ private void finishWithSuccess(Object data) { pendingOperation.result.success(data); pendingOperation = null; } else { - channel.invokeMethod(HAS_PENDING_OPERATION, null); + channel.invokeMethod(HAS_PENDING_OPERATION, data); } } @@ -476,7 +476,7 @@ private void finishWithError(String errorCode, String errorMessage, String error pendingOperation.result.error(errorCode, errorMessage, errorDetails); pendingOperation = null; } else { - channel.invokeMethod(HAS_PENDING_OPERATION, null); + channel.invokeMethod(HAS_PENDING_OPERATION, errorCode); } } From e60279507e4d329ee59a5494afeb554c1744035b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20Ali=20Dikc=CC=A7=C4=B1nar?= Date: Sat, 18 May 2024 02:11:21 +0300 Subject: [PATCH 4/4] feat: final methodChannelName --- .../crossingthestreams/flutterappauth/FlutterAppauthPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java b/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java index af9f35e..4ea4e5e 100644 --- a/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java +++ b/flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java @@ -80,7 +80,7 @@ public class FlutterAppauthPlugin implements FlutterPlugin, MethodCallHandler, P private AuthorizationService defaultAuthorizationService; private AuthorizationService insecureAuthorizationService; - private String methodChannelName = "crossingthestreams.io/flutter_appauth"; + private final String methodChannelName = "crossingthestreams.io/flutter_appauth"; private MethodChannel channel;