From e5eb0c11261c15bcee51dd6c03b68bf80f1e1a0a Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:14:44 +1100 Subject: [PATCH 1/4] refactored code on managing AuthorizationService instances --- .../flutterappauth/FlutterAppauthPlugin.java | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 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 8b7b552..2f1ddc8 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 @@ -94,12 +94,7 @@ private void setActivity(Activity flutterActivity) { private void onAttachedToEngine(Context context, BinaryMessenger binaryMessenger) { this.applicationContext = context; - defaultAuthorizationService = new AuthorizationService(this.applicationContext); - AppAuthConfiguration.Builder authConfigBuilder = new AppAuthConfiguration.Builder(); - authConfigBuilder.setConnectionBuilder(InsecureConnectionBuilder.INSTANCE); - authConfigBuilder.setSkipIssuerHttpsCheck(true); - insecureAuthorizationService = - new AuthorizationService(applicationContext, authConfigBuilder.build()); + createAuthorizationServices(); final MethodChannel channel = new MethodChannel(binaryMessenger, "crossingthestreams.io/flutter_appauth"); channel.setMethodCallHandler(this); @@ -137,6 +132,14 @@ public void onDetachedFromActivity() { this.mainActivity = null; } + private void createAuthorizationServices() { + defaultAuthorizationService = new AuthorizationService(this.applicationContext); + AppAuthConfiguration.Builder authConfigBuilder = new AppAuthConfiguration.Builder(); + authConfigBuilder.setConnectionBuilder(InsecureConnectionBuilder.INSTANCE); + authConfigBuilder.setSkipIssuerHttpsCheck(true); + insecureAuthorizationService = + new AuthorizationService(applicationContext, authConfigBuilder.build()); + } private void disposeAuthorizationServices() { defaultAuthorizationService.dispose(); insecureAuthorizationService.dispose(); @@ -461,8 +464,7 @@ private void performAuthorization( authRequestBuilder.setAdditionalParameters(additionalParameters); } - AuthorizationService authorizationService = - allowInsecureConnections ? insecureAuthorizationService : defaultAuthorizationService; + AuthorizationService authorizationService = getAuthorizationService(); try { Intent authIntent = @@ -513,8 +515,7 @@ public void onTokenRequestCompleted(TokenResponse resp, AuthorizationException e }; TokenRequest tokenRequest = builder.build(); - AuthorizationService authorizationService = - allowInsecureConnections ? insecureAuthorizationService : defaultAuthorizationService; + AuthorizationService authorizationService = getAuthorizationService(); if (clientSecret == null) { authorizationService.performTokenRequest(tokenRequest, tokenResponseCallback); } else { @@ -588,12 +589,17 @@ private void performEndSessionRequest( } final EndSessionRequest endSessionRequest = endSessionRequestBuilder.build(); - AuthorizationService authorizationService = - allowInsecureConnections ? insecureAuthorizationService : defaultAuthorizationService; + AuthorizationService authorizationService = getAuthorizationService(); Intent endSessionIntent = authorizationService.getEndSessionRequestIntent(endSessionRequest); mainActivity.startActivityForResult(endSessionIntent, RC_END_SESSION); } + private AuthorizationService getAuthorizationService() { + AuthorizationService authorizationService = + allowInsecureConnections ? insecureAuthorizationService : defaultAuthorizationService; + return authorizationService; + } + private void finishWithTokenError(AuthorizationException ex) { finishWithError( TOKEN_ERROR_CODE, @@ -702,14 +708,7 @@ private void processAuthorizationData( boolean exchangeCode) { if (authException == null) { if (exchangeCode) { - AppAuthConfiguration.Builder authConfigBuilder = new AppAuthConfiguration.Builder(); - if (allowInsecureConnections) { - authConfigBuilder.setConnectionBuilder(InsecureConnectionBuilder.INSTANCE); - authConfigBuilder.setSkipIssuerHttpsCheck(true); - } - - AuthorizationService authService = - new AuthorizationService(applicationContext, authConfigBuilder.build()); + AuthorizationService authService = getAuthorizationService(); AuthorizationService.TokenResponseCallback tokenResponseCallback = new AuthorizationService.TokenResponseCallback() { @Override From d34fb3539b56481707af4d8d302a64e8bf938e8e Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:17:34 +1100 Subject: [PATCH 2/4] refactored code on getting appropriate ConnectionBuilder --- .../flutterappauth/FlutterAppauthPlugin.java | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 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 2f1ddc8..49780b7 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 @@ -21,6 +21,7 @@ import net.openid.appauth.ResponseTypeValues; import net.openid.appauth.TokenRequest; import net.openid.appauth.TokenResponse; +import net.openid.appauth.connectivity.ConnectionBuilder; import net.openid.appauth.connectivity.DefaultConnectionBuilder; import org.json.JSONException; @@ -345,20 +346,22 @@ public void onFetchConfigurationCompleted( AuthorizationServiceConfiguration.fetchFromUrl( Uri.parse(tokenRequestParameters.discoveryUrl), callback, - allowInsecureConnections - ? InsecureConnectionBuilder.INSTANCE - : DefaultConnectionBuilder.INSTANCE); + getConnectionBuilder()); } else { AuthorizationServiceConfiguration.fetchFromIssuer( Uri.parse(tokenRequestParameters.issuer), callback, - allowInsecureConnections - ? InsecureConnectionBuilder.INSTANCE - : DefaultConnectionBuilder.INSTANCE); + getConnectionBuilder()); } } } + private @NonNull ConnectionBuilder getConnectionBuilder() { + return allowInsecureConnections + ? InsecureConnectionBuilder.INSTANCE + : DefaultConnectionBuilder.INSTANCE; + } + private AuthorizationServiceConfiguration processServiceConfigurationParameters( Map serviceConfigurationArguments) { final String endSessionEndpoint = serviceConfigurationArguments.get("endSessionEndpoint"); @@ -394,16 +397,12 @@ public void onFetchConfigurationCompleted( AuthorizationServiceConfiguration.fetchFromUrl( Uri.parse(tokenRequestParameters.discoveryUrl), callback, - allowInsecureConnections - ? InsecureConnectionBuilder.INSTANCE - : DefaultConnectionBuilder.INSTANCE); + getConnectionBuilder()); } else { AuthorizationServiceConfiguration.fetchFromIssuer( Uri.parse(tokenRequestParameters.issuer), callback, - allowInsecureConnections - ? InsecureConnectionBuilder.INSTANCE - : DefaultConnectionBuilder.INSTANCE); + getConnectionBuilder()); } } } @@ -551,16 +550,12 @@ public void onFetchConfigurationCompleted( AuthorizationServiceConfiguration.fetchFromUrl( Uri.parse(endSessionRequestParameters.discoveryUrl), callback, - allowInsecureConnections - ? InsecureConnectionBuilder.INSTANCE - : DefaultConnectionBuilder.INSTANCE); + getConnectionBuilder()); } else { AuthorizationServiceConfiguration.fetchFromIssuer( Uri.parse(endSessionRequestParameters.issuer), callback, - allowInsecureConnections - ? InsecureConnectionBuilder.INSTANCE - : DefaultConnectionBuilder.INSTANCE); + getConnectionBuilder()); } } } From 6bd46e82dbdf2c3728b5f51c35dcb1061aa9d62c Mon Sep 17 00:00:00 2001 From: github-actions <> Date: Sun, 13 Oct 2024 01:18:36 +0000 Subject: [PATCH 3/4] Google Java Format --- .../flutterappauth/FlutterAppauthPlugin.java | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 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 49780b7..ed2acc9 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 @@ -139,8 +139,9 @@ private void createAuthorizationServices() { authConfigBuilder.setConnectionBuilder(InsecureConnectionBuilder.INSTANCE); authConfigBuilder.setSkipIssuerHttpsCheck(true); insecureAuthorizationService = - new AuthorizationService(applicationContext, authConfigBuilder.build()); + new AuthorizationService(applicationContext, authConfigBuilder.build()); } + private void disposeAuthorizationServices() { defaultAuthorizationService.dispose(); insecureAuthorizationService.dispose(); @@ -344,22 +345,18 @@ public void onFetchConfigurationCompleted( }; if (tokenRequestParameters.discoveryUrl != null) { AuthorizationServiceConfiguration.fetchFromUrl( - Uri.parse(tokenRequestParameters.discoveryUrl), - callback, - getConnectionBuilder()); + Uri.parse(tokenRequestParameters.discoveryUrl), callback, getConnectionBuilder()); } else { AuthorizationServiceConfiguration.fetchFromIssuer( - Uri.parse(tokenRequestParameters.issuer), - callback, - getConnectionBuilder()); + Uri.parse(tokenRequestParameters.issuer), callback, getConnectionBuilder()); } } } private @NonNull ConnectionBuilder getConnectionBuilder() { return allowInsecureConnections - ? InsecureConnectionBuilder.INSTANCE - : DefaultConnectionBuilder.INSTANCE; + ? InsecureConnectionBuilder.INSTANCE + : DefaultConnectionBuilder.INSTANCE; } private AuthorizationServiceConfiguration processServiceConfigurationParameters( @@ -395,14 +392,10 @@ public void onFetchConfigurationCompleted( }; if (tokenRequestParameters.discoveryUrl != null) { AuthorizationServiceConfiguration.fetchFromUrl( - Uri.parse(tokenRequestParameters.discoveryUrl), - callback, - getConnectionBuilder()); + Uri.parse(tokenRequestParameters.discoveryUrl), callback, getConnectionBuilder()); } else { AuthorizationServiceConfiguration.fetchFromIssuer( - Uri.parse(tokenRequestParameters.issuer), - callback, - getConnectionBuilder()); + Uri.parse(tokenRequestParameters.issuer), callback, getConnectionBuilder()); } } } @@ -548,14 +541,10 @@ public void onFetchConfigurationCompleted( if (endSessionRequestParameters.discoveryUrl != null) { AuthorizationServiceConfiguration.fetchFromUrl( - Uri.parse(endSessionRequestParameters.discoveryUrl), - callback, - getConnectionBuilder()); + Uri.parse(endSessionRequestParameters.discoveryUrl), callback, getConnectionBuilder()); } else { AuthorizationServiceConfiguration.fetchFromIssuer( - Uri.parse(endSessionRequestParameters.issuer), - callback, - getConnectionBuilder()); + Uri.parse(endSessionRequestParameters.issuer), callback, getConnectionBuilder()); } } } From f855fcf713145c127b115fa8c067cdd3902e4bee Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:22:33 +1100 Subject: [PATCH 4/4] release prep --- flutter_appauth/CHANGELOG.md | 4 ++++ flutter_appauth/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/flutter_appauth/CHANGELOG.md b/flutter_appauth/CHANGELOG.md index fe104f2..2e6f8f2 100644 --- a/flutter_appauth/CHANGELOG.md +++ b/flutter_appauth/CHANGELOG.md @@ -1,3 +1,7 @@ +## [8.0.0-dev.4] + +* [Android] no functional changes but some code around dealing with `allowInsecureConnections` has been done in response to issue [554](https://github.com/MaikuB/flutter_appauth/issues/554) + ## [8.0.0-dev.3] * Includes changes from the 7.0.1 release diff --git a/flutter_appauth/pubspec.yaml b/flutter_appauth/pubspec.yaml index e03505e..76008c9 100644 --- a/flutter_appauth/pubspec.yaml +++ b/flutter_appauth/pubspec.yaml @@ -2,7 +2,7 @@ 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: 8.0.0-dev.3 +version: 8.0.0-dev.4 homepage: https://github.com/MaikuB/flutter_appauth/tree/master/flutter_appauth environment: