From b73d66ea1650fab911f10db677aa59957c45a91e Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Tue, 11 Jan 2022 17:01:41 -0600 Subject: [PATCH 01/20] [force-code-for-refresh-token-new] Add forceCodeForRefreshToken to allow android to receive a refresh token on every sign in --- .../googlesignin/GoogleSignInPlugin.java | 13 ++++++----- .../google_sign_in/lib/google_sign_in.dart | 5 +++++ .../google_sign_in/pubspec.yaml | 2 +- .../test/google_sign_in_test.dart | 22 +++++++++++++++++++ .../google_sign_in_platform_interface.dart | 1 + .../src/method_channel_google_sign_in.dart | 2 ++ .../pubspec.yaml | 2 +- .../method_channel_google_sign_in_test.dart | 4 +++- .../lib/google_sign_in_web.dart | 1 + .../google_sign_in_web/pubspec.yaml | 4 ++-- 10 files changed, 46 insertions(+), 10 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java b/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java index 3a63f785aa9f..8562339a17d8 100644 --- a/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java +++ b/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java @@ -137,7 +137,8 @@ public void onMethodCall(MethodCall call, Result result) { List requestedScopes = call.argument("scopes"); String hostedDomain = call.argument("hostedDomain"); String clientId = call.argument("clientId"); - delegate.init(result, signInOption, requestedScopes, hostedDomain, clientId); + boolean forceCodeForRefreshToken = call.argument("forceCodeForRefreshToken"); + delegate.init(result, signInOption, requestedScopes, hostedDomain, clientId, forceCodeForRefreshToken); break; case METHOD_SIGN_IN_SILENTLY: @@ -193,7 +194,8 @@ public void init( String signInOption, List requestedScopes, String hostedDomain, - String clientId); + String clientId, + boolean forceCodeForRefreshToken); /** * Returns the account information for the user who is signed in to this app. If no user is @@ -318,7 +320,8 @@ public void init( String signInOption, List requestedScopes, String hostedDomain, - String clientId) { + String clientId, + boolean forceCodeForRefreshToken) { try { GoogleSignInOptions.Builder optionsBuilder; @@ -345,10 +348,10 @@ public void init( .getIdentifier("default_web_client_id", "string", context.getPackageName()); if (!Strings.isNullOrEmpty(clientId)) { optionsBuilder.requestIdToken(clientId); - optionsBuilder.requestServerAuthCode(clientId); + optionsBuilder.requestServerAuthCode(clientId, forceCodeForRefreshToken); } else if (clientIdIdentifier != 0) { optionsBuilder.requestIdToken(context.getString(clientIdIdentifier)); - optionsBuilder.requestServerAuthCode(context.getString(clientIdIdentifier)); + optionsBuilder.requestServerAuthCode(context.getString(clientIdIdentifier), forceCodeForRefreshToken); } for (String scope : requestedScopes) { optionsBuilder.requestScopes(new Scope(scope)); diff --git a/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart b/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart index e104093c69bc..63ae56bbf8d4 100644 --- a/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart +++ b/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart @@ -180,6 +180,7 @@ class GoogleSignIn { this.scopes = const [], this.hostedDomain, this.clientId, + this.forceCodeForRefreshToken = false, }); /// Factory for creating default sign in user experience. @@ -228,6 +229,9 @@ class GoogleSignIn { /// Client ID being used to connect to google sign-in. Only supported on web. final String? clientId; + /// Force the authorization code to be valid for a refresh token every time. Only needed on Android. + final bool forceCodeForRefreshToken; + StreamController _currentUserController = StreamController.broadcast(); @@ -262,6 +266,7 @@ class GoogleSignIn { scopes: scopes, hostedDomain: hostedDomain, clientId: clientId, + forceCodeForRefreshToken: forceCodeForRefreshToken, )..catchError((dynamic _) { // Invalidate initialization if it errors out. _initialization = null; diff --git a/packages/google_sign_in/google_sign_in/pubspec.yaml b/packages/google_sign_in/google_sign_in/pubspec.yaml index fd47802f1bad..4ed33ce1c4c5 100644 --- a/packages/google_sign_in/google_sign_in/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in/pubspec.yaml @@ -23,7 +23,7 @@ flutter: dependencies: flutter: sdk: flutter - google_sign_in_platform_interface: ^2.1.0 + google_sign_in_platform_interface: ^2.2.0 google_sign_in_web: ^0.10.0 dev_dependencies: diff --git a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart index 0a019a2ffae5..d5486983dac3 100644 --- a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart +++ b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart @@ -96,6 +96,27 @@ void main() { 'scopes': [], 'hostedDomain': null, 'clientId': fakeClientId, + 'forceCodeForRefreshToken': false, + }), + isMethodCall('signIn', arguments: null), + ], + ); + }); + + test('forceCodeForRefreshToken sent with init method call', () async { + final fakeClientId = 'fakeClientId'; + googleSignIn = GoogleSignIn(clientId: fakeClientId, forceCodeForRefreshToken: true); + await googleSignIn.signIn(); + expect(googleSignIn.currentUser, isNotNull); + expect( + log, + [ + isMethodCall('init', arguments: { + 'signInOption': 'SignInOption.standard', + 'scopes': [], + 'hostedDomain': null, + 'clientId': fakeClientId, + 'forceCodeForRefreshToken': true, }), isMethodCall('signIn', arguments: null), ], @@ -430,5 +451,6 @@ Matcher _isSignInMethodCall({String signInOption = 'SignInOption.standard'}) { 'scopes': [], 'hostedDomain': null, 'clientId': null, + 'forceCodeForRefreshToken': false }); } diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart index 50f261bfa578..9488515d5be1 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart @@ -85,6 +85,7 @@ abstract class GoogleSignInPlatform { SignInOption signInOption = SignInOption.standard, String? hostedDomain, String? clientId, + bool forceCodeForRefreshToken = false, }) async { throw UnimplementedError('init() has not been implemented.'); } diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart index c569133a1b34..5b2245ae38c9 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart @@ -25,12 +25,14 @@ class MethodChannelGoogleSignIn extends GoogleSignInPlatform { SignInOption signInOption = SignInOption.standard, String? hostedDomain, String? clientId, + bool forceCodeForRefreshToken = false, }) { return channel.invokeMethod('init', { 'signInOption': signInOption.toString(), 'scopes': scopes, 'hostedDomain': hostedDomain, 'clientId': clientId, + 'forceCodeForRefreshToken': forceCodeForRefreshToken, }); } diff --git a/packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml b/packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml index fcf83bc34d5c..9c20bc2b9b5b 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/master/packages/google_sign_ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 2.1.1 +version: 2.2.0 environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart b/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart index fcb443f84293..d77671f04b92 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart @@ -102,12 +102,14 @@ void main() { hostedDomain: 'example.com', scopes: ['two', 'scopes'], signInOption: SignInOption.games, - clientId: 'fakeClientId'); + clientId: 'fakeClientId', + forceCodeForRefreshToken: true); }: isMethodCall('init', arguments: { 'hostedDomain': 'example.com', 'scopes': ['two', 'scopes'], 'signInOption': 'SignInOption.games', 'clientId': 'fakeClientId', + 'forceCodeForRefreshToken': true, }), () { googleSignIn.getTokens( diff --git a/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart b/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart index ff0d8e4cea89..b4fb2c38270a 100644 --- a/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart +++ b/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart @@ -71,6 +71,7 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { SignInOption signInOption = SignInOption.standard, String? hostedDomain, String? clientId, + bool forceCodeForRefreshToken = false, }) async { final String? appClientId = clientId ?? _autoDetectedClientId; assert( diff --git a/packages/google_sign_in/google_sign_in_web/pubspec.yaml b/packages/google_sign_in/google_sign_in_web/pubspec.yaml index ec61f30a77fb..7e6d20b8ab53 100644 --- a/packages/google_sign_in/google_sign_in_web/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_web/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android, iOS and Web. repository: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in_web issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 0.10.0+4 +version: 0.10.1+4 environment: sdk: ">=2.12.0 <3.0.0" @@ -22,7 +22,7 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - google_sign_in_platform_interface: ^2.0.0 + google_sign_in_platform_interface: ^2.2.0 js: ^0.6.3 pedantic: ^1.10.0 From 1c1e63953835472e7c2c1a798d0434118172b37d Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Tue, 11 Jan 2022 17:13:43 -0600 Subject: [PATCH 02/20] [force-code-for-refresh-token] Add AUTHORS --- packages/google_sign_in/google_sign_in/AUTHORS | 1 + .../google_sign_in/google_sign_in_platform_interface/AUTHORS | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/google_sign_in/google_sign_in/AUTHORS b/packages/google_sign_in/google_sign_in/AUTHORS index 493a0b4ef9c2..c7b210e8a700 100644 --- a/packages/google_sign_in/google_sign_in/AUTHORS +++ b/packages/google_sign_in/google_sign_in/AUTHORS @@ -64,3 +64,4 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> +Twin Sun, LLC \ No newline at end of file diff --git a/packages/google_sign_in/google_sign_in_platform_interface/AUTHORS b/packages/google_sign_in/google_sign_in_platform_interface/AUTHORS index 493a0b4ef9c2..c7b210e8a700 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/AUTHORS +++ b/packages/google_sign_in/google_sign_in_platform_interface/AUTHORS @@ -64,3 +64,4 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> +Twin Sun, LLC \ No newline at end of file From 8b0e62f62090740f9768fc31553663b691cef204 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Wed, 12 Jan 2022 10:40:12 -0600 Subject: [PATCH 03/20] [force-code-for-refresh-token] Update to non-breaking change for platform interface, add dependency overrides --- .../google_sign_in/CHANGELOG.md | 4 ++ .../google_sign_in/lib/google_sign_in.dart | 5 ++- .../google_sign_in/pubspec.yaml | 8 +++- .../CHANGELOG.md | 4 ++ .../google_sign_in_platform_interface.dart | 38 ++++++++++++++++++- .../src/method_channel_google_sign_in.dart | 14 +++++++ .../pubspec.yaml | 2 +- .../method_channel_google_sign_in_test.dart | 23 +++++++++-- .../google_sign_in_web/CHANGELOG.md | 4 ++ .../lib/google_sign_in_web.dart | 17 ++++++++- .../google_sign_in_web/pubspec.yaml | 4 +- 11 files changed, 112 insertions(+), 11 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/CHANGELOG.md b/packages/google_sign_in/google_sign_in/CHANGELOG.md index 3c2dfbe5a7be..1c6bb99f3291 100644 --- a/packages/google_sign_in/google_sign_in/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.2.3 + +* Add `forceCodeForRefreshToken` parameter to `GoogleSignIn`. + ## 5.2.2 * Updates Android compileSdkVersion to 31. diff --git a/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart b/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart index 63ae56bbf8d4..b1c7ef62cff6 100644 --- a/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart +++ b/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart @@ -175,6 +175,9 @@ class GoogleSignIn { /// The [hostedDomain] argument specifies a hosted domain restriction. By /// setting this, sign in will be restricted to accounts of the user in the /// specified domain. By default, the list of accounts will not be restricted. + /// + /// The [forceCodeForRefreshToken] is used on Android to ensure the authentication + /// code can be exchanged for a refresh token after the first request. GoogleSignIn({ this.signInOption = SignInOption.standard, this.scopes = const [], @@ -261,7 +264,7 @@ class GoogleSignIn { } Future _ensureInitialized() { - return _initialization ??= GoogleSignInPlatform.instance.init( + return _initialization ??= GoogleSignInPlatform.instance.initWithForceCodeForRefreshToken( signInOption: signInOption, scopes: scopes, hostedDomain: hostedDomain, diff --git a/packages/google_sign_in/google_sign_in/pubspec.yaml b/packages/google_sign_in/google_sign_in/pubspec.yaml index 4ed33ce1c4c5..7cb9ce606e0b 100644 --- a/packages/google_sign_in/google_sign_in/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android and iOS. repository: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 5.2.2 +version: 5.2.3 environment: sdk: ">=2.14.0 <3.0.0" @@ -23,7 +23,7 @@ flutter: dependencies: flutter: sdk: flutter - google_sign_in_platform_interface: ^2.2.0 + google_sign_in_platform_interface: ^2.1.2 google_sign_in_web: ^0.10.0 dev_dependencies: @@ -36,6 +36,10 @@ dev_dependencies: sdk: flutter pedantic: ^1.10.0 +dependency_overrides: + google_sign_in_platform_interface: + path: ../google_sign_in_platform_interface + # The example deliberately includes limited-use secrets. false_secrets: - /example/android/app/google-services.json diff --git a/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md b/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md index 928186029a48..5c90e22d40ac 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.1.2 + +* Add `initWithForceCodeForRefreshToken` method to add the `forceCodeForRefreshToken` method. + ## 2.1.1 * Removes dependency on `meta`. diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart index 9488515d5be1..9a314a0ffdf1 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart @@ -78,6 +78,9 @@ abstract class GoogleSignInPlatform { /// The [signInOption] determines the user experience. [SigninOption.games] is /// only supported on Android. /// + /// This method is deprecated in favor of [initWithForceFodeForRefreshToken] and + /// will be removed in a future update. + /// /// See: /// https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams Future init({ @@ -85,11 +88,44 @@ abstract class GoogleSignInPlatform { SignInOption signInOption = SignInOption.standard, String? hostedDomain, String? clientId, - bool forceCodeForRefreshToken = false, }) async { throw UnimplementedError('init() has not been implemented.'); } + /// Initializes the plugin. You must call this method before calling other + /// methods. + /// + /// The [hostedDomain] argument specifies a hosted domain restriction. By + /// setting this, sign in will be restricted to accounts of the user in the + /// specified domain. By default, the list of accounts will not be restricted. + /// + /// The list of [scopes] are OAuth scope codes to request when signing in. + /// These scope codes will determine the level of data access that is granted + /// to your application by the user. The full list of available scopes can be + /// found here: + /// + /// The [signInOption] determines the user experience. [SigninOption.games] is + /// only supported on Android. + /// + /// The [forceCodeForRefreshToken] is used on Android to ensure the authentication + /// code can be exchanged for a refresh token after the first request. + /// + /// See: + /// https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams + Future initWithForceCodeForRefreshToken({ + List scopes = const [], + SignInOption signInOption = SignInOption.standard, + String? hostedDomain, + String? clientId, + bool forceCodeForRefreshToken = false, + }) async { + await init( + scopes: scopes, + signInOption: signInOption, + hostedDomain: hostedDomain, + clientId: clientId); + } + /// Attempts to reuse pre-existing credentials to sign in again, without user interaction. Future signInSilently() async { throw UnimplementedError('signInSilently() has not been implemented.'); diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart index 5b2245ae38c9..3e77ae4b0c14 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart @@ -25,6 +25,20 @@ class MethodChannelGoogleSignIn extends GoogleSignInPlatform { SignInOption signInOption = SignInOption.standard, String? hostedDomain, String? clientId, + }) { + return initWithForceCodeForRefreshToken( + scopes: scopes, + signInOption: signInOption, + hostedDomain: hostedDomain, + clientId: clientId); + } + + @override + Future initWithForceCodeForRefreshToken({ + List scopes = const [], + SignInOption signInOption = SignInOption.standard, + String? hostedDomain, + String? clientId, bool forceCodeForRefreshToken = false, }) { return channel.invokeMethod('init', { diff --git a/packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml b/packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml index 9c20bc2b9b5b..0ea3f6acf9ec 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/master/packages/google_sign_ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 2.2.0 +version: 2.1.2 environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart b/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart index d77671f04b92..89c137905ff7 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart @@ -102,14 +102,13 @@ void main() { hostedDomain: 'example.com', scopes: ['two', 'scopes'], signInOption: SignInOption.games, - clientId: 'fakeClientId', - forceCodeForRefreshToken: true); + clientId: 'fakeClientId'); }: isMethodCall('init', arguments: { 'hostedDomain': 'example.com', 'scopes': ['two', 'scopes'], 'signInOption': 'SignInOption.games', 'clientId': 'fakeClientId', - 'forceCodeForRefreshToken': true, + 'forceCodeForRefreshToken': false, }), () { googleSignIn.getTokens( @@ -137,5 +136,23 @@ void main() { expect(log, tests.values); }); + + test('initWithForceCodeForRefreshToken passes through arguments to the channel', () async { + await googleSignIn.initWithForceCodeForRefreshToken( + hostedDomain: 'example.com', + scopes: ['two', 'scopes'], + signInOption: SignInOption.games, + clientId: 'fakeClientId', + forceCodeForRefreshToken: true); + expect(log, [ + isMethodCall('init', arguments: { + 'hostedDomain': 'example.com', + 'scopes': ['two', 'scopes'], + 'signInOption': 'SignInOption.games', + 'clientId': 'fakeClientId', + 'forceCodeForRefreshToken': true, + }), + ]); + }); }); } diff --git a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md index e65ce0fb23ba..194a78e3360d 100644 --- a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.10.0+5 + +* Add override for `GoogleSignInPlatformInterface.initWithForceCodeForRefreshToken`. + ## 0.10.0+4 * Removes dependency on `meta`. diff --git a/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart b/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart index b4fb2c38270a..f3b0ac373a1f 100644 --- a/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart +++ b/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart @@ -71,7 +71,6 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { SignInOption signInOption = SignInOption.standard, String? hostedDomain, String? clientId, - bool forceCodeForRefreshToken = false, }) async { final String? appClientId = clientId ?? _autoDetectedClientId; assert( @@ -120,6 +119,22 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { return _isAuthInitialized; } + @override + Future initWithForceCodeForRefreshToken({ + List scopes = const [], + SignInOption signInOption = SignInOption.standard, + String? hostedDomain, + String? clientId, + bool forceCodeForRefreshToken = false, + }) async { + await init( + scopes: scopes, + signInOption: signInOption, + hostedDomain: hostedDomain, + clientId: clientId, + ); + } + @override Future signInSilently() async { await initialized; diff --git a/packages/google_sign_in/google_sign_in_web/pubspec.yaml b/packages/google_sign_in/google_sign_in_web/pubspec.yaml index 7e6d20b8ab53..51aee34e9221 100644 --- a/packages/google_sign_in/google_sign_in_web/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_web/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android, iOS and Web. repository: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in_web issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 0.10.1+4 +version: 0.10.0+5 environment: sdk: ">=2.12.0 <3.0.0" @@ -22,7 +22,7 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - google_sign_in_platform_interface: ^2.2.0 + google_sign_in_platform_interface: ^2.1.2 js: ^0.6.3 pedantic: ^1.10.0 From 56949bd47b857d49ed3f37e72775e9ee9204f697 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Wed, 12 Jan 2022 10:43:46 -0600 Subject: [PATCH 04/20] [force-code-for-refresh-token] Clean up a couple things --- packages/google_sign_in/google_sign_in/AUTHORS | 2 +- .../google_sign_in/google_sign_in_platform_interface/AUTHORS | 2 +- .../google_sign_in_platform_interface/CHANGELOG.md | 2 +- packages/google_sign_in/google_sign_in_web/CHANGELOG.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/AUTHORS b/packages/google_sign_in/google_sign_in/AUTHORS index c7b210e8a700..35d24a5ae0b5 100644 --- a/packages/google_sign_in/google_sign_in/AUTHORS +++ b/packages/google_sign_in/google_sign_in/AUTHORS @@ -64,4 +64,4 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> -Twin Sun, LLC \ No newline at end of file +Twin Sun, LLC diff --git a/packages/google_sign_in/google_sign_in_platform_interface/AUTHORS b/packages/google_sign_in/google_sign_in_platform_interface/AUTHORS index c7b210e8a700..35d24a5ae0b5 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/AUTHORS +++ b/packages/google_sign_in/google_sign_in_platform_interface/AUTHORS @@ -64,4 +64,4 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> -Twin Sun, LLC \ No newline at end of file +Twin Sun, LLC diff --git a/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md b/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md index 5c90e22d40ac..6e806be0feb3 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.1.2 -* Add `initWithForceCodeForRefreshToken` method to add the `forceCodeForRefreshToken` method. +* Add `initWithForceCodeForRefreshToken` method to add the `forceCodeForRefreshToken` parameter. ## 2.1.1 diff --git a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md index 194a78e3360d..451e1b6dca9a 100644 --- a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.10.0+5 -* Add override for `GoogleSignInPlatformInterface.initWithForceCodeForRefreshToken`. +* Add override for `GoogleSignInPlatform.initWithForceCodeForRefreshToken`. ## 0.10.0+4 From 00c978884a46e79aeb1aa66defc767657c485fbe Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Wed, 12 Jan 2022 10:49:39 -0600 Subject: [PATCH 05/20] [force-code-for-refresh-token] Run flutter format --- .../google_sign_in/lib/google_sign_in.dart | 9 +++++---- .../google_sign_in/test/google_sign_in_test.dart | 3 ++- .../lib/google_sign_in_platform_interface.dart | 8 ++++---- .../lib/src/method_channel_google_sign_in.dart | 8 ++++---- .../test/method_channel_google_sign_in_test.dart | 14 ++++++++------ 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart b/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart index b1c7ef62cff6..ad0aad0ad2c7 100644 --- a/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart +++ b/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart @@ -264,16 +264,17 @@ class GoogleSignIn { } Future _ensureInitialized() { - return _initialization ??= GoogleSignInPlatform.instance.initWithForceCodeForRefreshToken( + return _initialization ??= + GoogleSignInPlatform.instance.initWithForceCodeForRefreshToken( signInOption: signInOption, scopes: scopes, hostedDomain: hostedDomain, clientId: clientId, forceCodeForRefreshToken: forceCodeForRefreshToken, )..catchError((dynamic _) { - // Invalidate initialization if it errors out. - _initialization = null; - }); + // Invalidate initialization if it errors out. + _initialization = null; + }); } /// The most recently scheduled method call. diff --git a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart index d5486983dac3..a70a5e8be053 100644 --- a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart +++ b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart @@ -105,7 +105,8 @@ void main() { test('forceCodeForRefreshToken sent with init method call', () async { final fakeClientId = 'fakeClientId'; - googleSignIn = GoogleSignIn(clientId: fakeClientId, forceCodeForRefreshToken: true); + googleSignIn = + GoogleSignIn(clientId: fakeClientId, forceCodeForRefreshToken: true); await googleSignIn.signIn(); expect(googleSignIn.currentUser, isNotNull); expect( diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart index 9a314a0ffdf1..ed501d48663e 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart @@ -120,10 +120,10 @@ abstract class GoogleSignInPlatform { bool forceCodeForRefreshToken = false, }) async { await init( - scopes: scopes, - signInOption: signInOption, - hostedDomain: hostedDomain, - clientId: clientId); + scopes: scopes, + signInOption: signInOption, + hostedDomain: hostedDomain, + clientId: clientId); } /// Attempts to reuse pre-existing credentials to sign in again, without user interaction. diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart index 3e77ae4b0c14..297aa8f070c5 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart @@ -27,10 +27,10 @@ class MethodChannelGoogleSignIn extends GoogleSignInPlatform { String? clientId, }) { return initWithForceCodeForRefreshToken( - scopes: scopes, - signInOption: signInOption, - hostedDomain: hostedDomain, - clientId: clientId); + scopes: scopes, + signInOption: signInOption, + hostedDomain: hostedDomain, + clientId: clientId); } @override diff --git a/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart b/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart index 89c137905ff7..264e3e9e3987 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart @@ -137,13 +137,15 @@ void main() { expect(log, tests.values); }); - test('initWithForceCodeForRefreshToken passes through arguments to the channel', () async { + test( + 'initWithForceCodeForRefreshToken passes through arguments to the channel', + () async { await googleSignIn.initWithForceCodeForRefreshToken( - hostedDomain: 'example.com', - scopes: ['two', 'scopes'], - signInOption: SignInOption.games, - clientId: 'fakeClientId', - forceCodeForRefreshToken: true); + hostedDomain: 'example.com', + scopes: ['two', 'scopes'], + signInOption: SignInOption.games, + clientId: 'fakeClientId', + forceCodeForRefreshToken: true); expect(log, [ isMethodCall('init', arguments: { 'hostedDomain': 'example.com', From f37e9c49365313f5c4029653a284edd9cc427e2d Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Wed, 12 Jan 2022 12:49:27 -0600 Subject: [PATCH 06/20] [force-code-for-refresh-token] Add dependency_overrides to example projects as well --- packages/google_sign_in/google_sign_in/example/pubspec.yaml | 4 ++++ .../google_sign_in/google_sign_in_web/example/pubspec.yaml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/packages/google_sign_in/google_sign_in/example/pubspec.yaml b/packages/google_sign_in/google_sign_in/example/pubspec.yaml index dfd942d3d438..3294880e3759 100644 --- a/packages/google_sign_in/google_sign_in/example/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in/example/pubspec.yaml @@ -28,3 +28,7 @@ dev_dependencies: flutter: uses-material-design: true + +dependency_overrides: + google_sign_in_platform_interface: + path: ../google_sign_in_platform_interface diff --git a/packages/google_sign_in/google_sign_in_web/example/pubspec.yaml b/packages/google_sign_in/google_sign_in_web/example/pubspec.yaml index e370ecc561d2..ab4eab23b540 100644 --- a/packages/google_sign_in/google_sign_in_web/example/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_web/example/pubspec.yaml @@ -20,3 +20,7 @@ dev_dependencies: sdk: flutter integration_test: sdk: flutter + +dependency_overrides: + google_sign_in_platform_interface: + path: ../google_sign_in_platform_interface \ No newline at end of file From 39982f1eccc28d243a30500acf76e48ed9f4b18c Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Wed, 12 Jan 2022 12:53:31 -0600 Subject: [PATCH 07/20] [force-code-for-refresh-token] Java format --- .../plugins/googlesignin/GoogleSignInPlugin.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java b/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java index 8562339a17d8..10da9fcd06b9 100644 --- a/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java +++ b/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java @@ -138,7 +138,13 @@ public void onMethodCall(MethodCall call, Result result) { String hostedDomain = call.argument("hostedDomain"); String clientId = call.argument("clientId"); boolean forceCodeForRefreshToken = call.argument("forceCodeForRefreshToken"); - delegate.init(result, signInOption, requestedScopes, hostedDomain, clientId, forceCodeForRefreshToken); + delegate.init( + result, + signInOption, + requestedScopes, + hostedDomain, + clientId, + forceCodeForRefreshToken); break; case METHOD_SIGN_IN_SILENTLY: @@ -351,7 +357,8 @@ public void init( optionsBuilder.requestServerAuthCode(clientId, forceCodeForRefreshToken); } else if (clientIdIdentifier != 0) { optionsBuilder.requestIdToken(context.getString(clientIdIdentifier)); - optionsBuilder.requestServerAuthCode(context.getString(clientIdIdentifier), forceCodeForRefreshToken); + optionsBuilder.requestServerAuthCode( + context.getString(clientIdIdentifier), forceCodeForRefreshToken); } for (String scope : requestedScopes) { optionsBuilder.requestScopes(new Scope(scope)); From 4ca91944a6783575383d4154d68152a211a1cf3d Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Wed, 12 Jan 2022 13:15:04 -0600 Subject: [PATCH 08/20] [force-code-for-refresh-token] Correct path in example apps --- packages/google_sign_in/google_sign_in/example/pubspec.yaml | 2 +- packages/google_sign_in/google_sign_in_web/example/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/example/pubspec.yaml b/packages/google_sign_in/google_sign_in/example/pubspec.yaml index 3294880e3759..35d2c7197fb8 100644 --- a/packages/google_sign_in/google_sign_in/example/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in/example/pubspec.yaml @@ -31,4 +31,4 @@ flutter: dependency_overrides: google_sign_in_platform_interface: - path: ../google_sign_in_platform_interface + path: ../../google_sign_in_platform_interface diff --git a/packages/google_sign_in/google_sign_in_web/example/pubspec.yaml b/packages/google_sign_in/google_sign_in_web/example/pubspec.yaml index ab4eab23b540..1fbdae1ace80 100644 --- a/packages/google_sign_in/google_sign_in_web/example/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_web/example/pubspec.yaml @@ -23,4 +23,4 @@ dev_dependencies: dependency_overrides: google_sign_in_platform_interface: - path: ../google_sign_in_platform_interface \ No newline at end of file + path: ../../google_sign_in_platform_interface \ No newline at end of file From 7a2b9e0397186049143f17cbc1209fc9508ab85b Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Fri, 14 Jan 2022 15:40:20 -0600 Subject: [PATCH 09/20] [force-code-for-refresh-token] Update CHANGELOG entries --- packages/google_sign_in/google_sign_in/CHANGELOG.md | 2 +- .../google_sign_in_platform_interface/CHANGELOG.md | 2 +- packages/google_sign_in/google_sign_in_web/CHANGELOG.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/CHANGELOG.md b/packages/google_sign_in/google_sign_in/CHANGELOG.md index 1c6bb99f3291..91f0a7e27bdc 100644 --- a/packages/google_sign_in/google_sign_in/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in/CHANGELOG.md @@ -1,6 +1,6 @@ ## 5.2.3 -* Add `forceCodeForRefreshToken` parameter to `GoogleSignIn`. +* Adds `forceCodeForRefreshToken` parameter to `GoogleSignIn`. ## 5.2.2 diff --git a/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md b/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md index 6e806be0feb3..58fe5079e521 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.1.2 -* Add `initWithForceCodeForRefreshToken` method to add the `forceCodeForRefreshToken` parameter. +* Adds `initWithForceCodeForRefreshToken` method to add the `forceCodeForRefreshToken` parameter. ## 2.1.1 diff --git a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md index 451e1b6dca9a..33dcbeed63ea 100644 --- a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.10.0+5 -* Add override for `GoogleSignInPlatform.initWithForceCodeForRefreshToken`. +* Adds override for `GoogleSignInPlatform.initWithForceCodeForRefreshToken`. ## 0.10.0+4 From 40d32f72309b7ee9092463f716021dfd5b9394da Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Mon, 31 Jan 2022 10:22:33 -0600 Subject: [PATCH 10/20] [force-code-for-refresh-token] Add dependency override for web --- packages/google_sign_in/google_sign_in_web/pubspec.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/google_sign_in/google_sign_in_web/pubspec.yaml b/packages/google_sign_in/google_sign_in_web/pubspec.yaml index 51aee34e9221..630c526622e5 100644 --- a/packages/google_sign_in/google_sign_in_web/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_web/pubspec.yaml @@ -29,3 +29,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + +dependency_overrides: + google_sign_in_platform_interface: + path: ../google_sign_in_platform_interface \ No newline at end of file From b70f335c5204b763aea345acadf29fb4243585ed Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Mon, 31 Jan 2022 10:24:09 -0600 Subject: [PATCH 11/20] [force-code-for-refresh-token] Refactor GoogleSignInPlugin.Delegate to allow mocking the clientIdIdentifier and GoogleSignInOptions.Builder; use those to add tests for forceCodeForRefreshToken in the init method --- .../googlesignin/GoogleSignInPlugin.java | 79 ++++++++++++++----- .../googlesignin/GoogleSignInTest.java | 56 +++++++++++++ 2 files changed, 114 insertions(+), 21 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java b/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java index 10da9fcd06b9..4d046d9b66be 100644 --- a/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java +++ b/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java @@ -42,6 +42,9 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import android.content.res.Resources; +import android.util.Log; + /** Google sign-in plugin for Flutter. */ public class GoogleSignInPlugin implements MethodCallHandler, FlutterPlugin, ActivityAware { private static final String CHANNEL_NAME = "plugins.flutter.io/google_sign_in"; @@ -80,6 +83,16 @@ public void setUpRegistrar(PluginRegistry.Registrar registrar) { delegate.setUpRegistrar(registrar); } + @VisibleForTesting + public void setOptionsBuilderFactory(OptionsBuilderFactory factory) { + delegate.setOptionsBuilderFactory(factory); + } + + @VisibleForTesting + public void setClientIdIdentifierOverride(int clientIdIdentifier) { + delegate.setClientIdIdentifierOverride(clientIdIdentifier); + } + private void dispose() { delegate = null; channel.setMethodCallHandler(null); @@ -246,6 +259,30 @@ public void init( public void requestScopes(final Result result, final List scopes); } + /** + * Factory class that generates the GoogleSignInOptions.Builder. This is exposed so that tests + * can inject a mock instance of the GoogleSignInOptions.Builder. + */ + public static class OptionsBuilderFactory { + public static final String DEFAULT_SIGN_IN = "SignInOption.standard"; + public static final String DEFAULT_GAMES_SIGN_IN = "SignInOption.games"; + + /** + * Returns an instance of GoogleSignInOptions.Builder with the passed signInOption. + */ + public GoogleSignInOptions.Builder get(String signInOption) { + switch (signInOption) { + case DEFAULT_GAMES_SIGN_IN: + return new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); + + case DEFAULT_SIGN_IN: + return new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail(); + default: + throw new IllegalStateException("Unknown signInOption"); + } + } + } + /** * Delegate class that does the work for the Google sign-in plugin. This is exposed as a dedicated * class for use in other plugins that wrap basic sign-in functionality. @@ -270,9 +307,6 @@ public static class Delegate implements IDelegate, PluginRegistry.ActivityResult private static final String ERROR_FAILURE_TO_RECOVER_AUTH = "failed_to_recover_auth"; private static final String ERROR_USER_RECOVERABLE_AUTH = "user_recoverable_auth"; - private static final String DEFAULT_SIGN_IN = "SignInOption.standard"; - private static final String DEFAULT_GAMES_SIGN_IN = "SignInOption.games"; - private final Context context; // Only set registrar for v1 embedder. private PluginRegistry.Registrar registrar; @@ -284,6 +318,8 @@ public static class Delegate implements IDelegate, PluginRegistry.ActivityResult private GoogleSignInClient signInClient; private List requestedScopes; private PendingOperation pendingOperation; + private OptionsBuilderFactory optionsBuilderFactory = new OptionsBuilderFactory(); + private int clientIdIdentifierOverride = -1; public Delegate(Context context, GoogleSignInWrapper googleSignInWrapper) { this.context = context; @@ -295,6 +331,14 @@ public void setUpRegistrar(PluginRegistry.Registrar registrar) { registrar.addActivityResultListener(this); } + public void setOptionsBuilderFactory(OptionsBuilderFactory factory) { + this.optionsBuilderFactory = factory; + } + + public void setClientIdIdentifierOverride(int clientIdIdentifier) { + this.clientIdIdentifierOverride = clientIdIdentifier; + } + public void setActivity(Activity activity) { this.activity = activity; } @@ -316,6 +360,15 @@ private void checkAndSetPendingOperation(String method, Result result, Object da pendingOperation = new PendingOperation(method, result, data); } + private int getClientIdIdentifier() { + if (clientIdIdentifierOverride != -1) { + return clientIdIdentifierOverride; + } + return context + .getResources() + .getIdentifier("default_web_client_id", "string", context.getPackageName()); + } + /** * Initializes this delegate so that it is ready to perform other operations. The Dart code * guarantees that this will be called and completed before any other methods are invoked. @@ -329,29 +382,13 @@ public void init( String clientId, boolean forceCodeForRefreshToken) { try { - GoogleSignInOptions.Builder optionsBuilder; - - switch (signInOption) { - case DEFAULT_GAMES_SIGN_IN: - optionsBuilder = - new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); - break; - case DEFAULT_SIGN_IN: - optionsBuilder = - new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail(); - break; - default: - throw new IllegalStateException("Unknown signInOption"); - } + GoogleSignInOptions.Builder optionsBuilder = optionsBuilderFactory.get(signInOption); // Only requests a clientId if google-services.json was present and parsed // by the google-services Gradle script. // TODO(jackson): Perhaps we should provide a mechanism to override this // behavior. - int clientIdIdentifier = - context - .getResources() - .getIdentifier("default_web_client_id", "string", context.getPackageName()); + int clientIdIdentifier = getClientIdIdentifier(); if (!Strings.isNullOrEmpty(clientId)) { optionsBuilder.requestIdToken(clientId); optionsBuilder.requestServerAuthCode(clientId, forceCodeForRefreshToken); diff --git a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java index 3b6ad960f548..aeb56a5c73a2 100644 --- a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java +++ b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java @@ -13,6 +13,7 @@ import android.content.Context; import android.content.Intent; import com.google.android.gms.auth.api.signin.GoogleSignInAccount; +import com.google.android.gms.auth.api.signin.GoogleSignInOptions; import com.google.android.gms.common.api.Scope; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodCall; @@ -36,6 +37,8 @@ public class GoogleSignInTest { @Spy MethodChannel.Result result; @Mock GoogleSignInWrapper mockGoogleSignIn; @Mock GoogleSignInAccount account; + @Mock GoogleSignInPlugin.OptionsBuilderFactory optionsBuilderFactory; + @Mock GoogleSignInOptions.Builder optionsBuilder; private GoogleSignInPlugin plugin; @Before @@ -44,9 +47,62 @@ public void setUp() { when(mockRegistrar.messenger()).thenReturn(mockMessenger); when(mockRegistrar.context()).thenReturn(mockContext); when(mockRegistrar.activity()).thenReturn(mockActivity); + when(optionsBuilderFactory.get(GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN)).thenReturn(optionsBuilder); + when(optionsBuilderFactory.get(GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_GAMES_SIGN_IN)).thenReturn(optionsBuilder); plugin = new GoogleSignInPlugin(); plugin.initInstance(mockRegistrar.messenger(), mockRegistrar.context(), mockGoogleSignIn); plugin.setUpRegistrar(mockRegistrar); + plugin.setOptionsBuilderFactory(optionsBuilderFactory); + plugin.setClientIdIdentifierOverride(0); + } + + @Test + public void init_PassesForceCodeForRefreshTokenWithClientIdParameter() { + HashMap arguments = new HashMap<>(); + arguments.put("signInOption", GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN); + arguments.put("requestedScopes", Collections.singletonList("requestedScope")); + arguments.put("hostedDomain", null); + arguments.put("clientId", "mockClientId"); + arguments.put("forceCodeForRefreshToken", false); + + MethodCall methodCall = new MethodCall("init", arguments); + + plugin.onMethodCall(methodCall, result); + + verify(optionsBuilder, times(1)).requestServerAuthCode("mockClientId", false); + + arguments.put("forceCodeForRefreshToken", true); + + methodCall = new MethodCall("init", arguments); + + plugin.onMethodCall(methodCall, result); + + verify(optionsBuilder, times(1)).requestServerAuthCode("mockClientId", true); + } + + @Test + public void init_PassesForceCodeForRefreshTokenWithClientIdFromResources() { + plugin.setClientIdIdentifierOverride(1); + when(mockContext.getString(1)).thenReturn("mockClientId"); + HashMap arguments = new HashMap<>(); + arguments.put("signInOption", GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN); + arguments.put("requestedScopes", Collections.singletonList("requestedScope")); + arguments.put("hostedDomain", null); + arguments.put("forceCodeForRefreshToken", false); + + MethodCall methodCall = new MethodCall("init", arguments); + + plugin.onMethodCall(methodCall, result); + + verify(optionsBuilder, times(1)).requestServerAuthCode("mockClientId", false); + + arguments.put("forceCodeForRefreshToken", true); + + methodCall = new MethodCall("init", arguments); + + plugin.onMethodCall(methodCall, result); + + verify(optionsBuilder, times(1)).requestServerAuthCode("mockClientId", true); } @Test From 4f950910b5481de91d4fb1a4078101e1bb843866 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Mon, 14 Feb 2022 15:09:34 -0600 Subject: [PATCH 12/20] [force-code-for-refresh-token] Split true/false flows into separate tests --- .../googlesignin/GoogleSignInTest.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java index aeb56a5c73a2..563849949a7c 100644 --- a/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java +++ b/packages/google_sign_in/google_sign_in/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java @@ -57,7 +57,7 @@ public void setUp() { } @Test - public void init_PassesForceCodeForRefreshTokenWithClientIdParameter() { + public void init_PassesForceCodeForRefreshTokenFalseWithClientIdParameter() { HashMap arguments = new HashMap<>(); arguments.put("signInOption", GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN); arguments.put("requestedScopes", Collections.singletonList("requestedScope")); @@ -70,10 +70,18 @@ public void init_PassesForceCodeForRefreshTokenWithClientIdParameter() { plugin.onMethodCall(methodCall, result); verify(optionsBuilder, times(1)).requestServerAuthCode("mockClientId", false); + } + @Test + public void init_PassesForceCodeForRefreshTokenTrueWithClientIdParameter() { + HashMap arguments = new HashMap<>(); + arguments.put("signInOption", GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN); + arguments.put("requestedScopes", Collections.singletonList("requestedScope")); + arguments.put("hostedDomain", null); + arguments.put("clientId", "mockClientId"); arguments.put("forceCodeForRefreshToken", true); - methodCall = new MethodCall("init", arguments); + MethodCall methodCall = new MethodCall("init", arguments); plugin.onMethodCall(methodCall, result); @@ -81,7 +89,7 @@ public void init_PassesForceCodeForRefreshTokenWithClientIdParameter() { } @Test - public void init_PassesForceCodeForRefreshTokenWithClientIdFromResources() { + public void init_PassesForceCodeForRefreshTokenFalseWithClientIdFromResources() { plugin.setClientIdIdentifierOverride(1); when(mockContext.getString(1)).thenReturn("mockClientId"); HashMap arguments = new HashMap<>(); @@ -95,10 +103,19 @@ public void init_PassesForceCodeForRefreshTokenWithClientIdFromResources() { plugin.onMethodCall(methodCall, result); verify(optionsBuilder, times(1)).requestServerAuthCode("mockClientId", false); + } + @Test + public void init_PassesForceCodeForRefreshTokenTrueWithClientIdFromResources() { + plugin.setClientIdIdentifierOverride(1); + when(mockContext.getString(1)).thenReturn("mockClientId"); + HashMap arguments = new HashMap<>(); + arguments.put("signInOption", GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN); + arguments.put("requestedScopes", Collections.singletonList("requestedScope")); + arguments.put("hostedDomain", null); arguments.put("forceCodeForRefreshToken", true); - methodCall = new MethodCall("init", arguments); + MethodCall methodCall = new MethodCall("init", arguments); plugin.onMethodCall(methodCall, result); From 6a979fbb11bc37b99f924bb3aa270906a23c5797 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Wed, 11 May 2022 17:00:49 -0500 Subject: [PATCH 13/20] [force-code-for-refresh-token] Fix up after merging the the platform interface updates --- .../google_sign_in/example/pubspec.yaml | 3 -- .../google_sign_in/lib/google_sign_in.dart | 23 ++++++------ .../google_sign_in/pubspec.yaml | 6 +--- .../test/google_sign_in_test.dart | 2 +- .../google_sign_in_android/AUTHORS | 1 + .../lib/google_sign_in_android.dart | 19 +++++++--- .../test/google_sign_in_android_test.dart | 6 ++-- .../google_sign_in/google_sign_in_ios/AUTHORS | 1 + .../lib/google_sign_in_ios.dart | 18 +++++++--- .../google_sign_in_ios/pubspec.yaml | 2 +- .../test/google_sign_in_ios_test.dart | 4 +-- .../google_sign_in_platform_interface.dart | 3 -- .../google_sign_in/google_sign_in_web/AUTHORS | 1 + .../google_sign_in_web/CHANGELOG.md | 2 +- .../google_sign_in_web/example/pubspec.yaml | 4 --- .../lib/google_sign_in_web.dart | 36 ++++++++----------- .../google_sign_in_web/pubspec.yaml | 6 +--- 17 files changed, 69 insertions(+), 68 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/example/pubspec.yaml b/packages/google_sign_in/google_sign_in/example/pubspec.yaml index 36fbe70724ac..a90f9d17dc3e 100644 --- a/packages/google_sign_in/google_sign_in/example/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in/example/pubspec.yaml @@ -28,6 +28,3 @@ dev_dependencies: flutter: uses-material-design: true -dependency_overrides: - google_sign_in_platform_interface: - path: ../../google_sign_in_platform_interface diff --git a/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart b/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart index c7a41e22eab5..fd517b7d163e 100644 --- a/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart +++ b/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart @@ -238,7 +238,6 @@ class GoogleSignIn { /// Force the authorization code to be valid for a refresh token every time. Only needed on Android. final bool forceCodeForRefreshToken; - StreamController _currentUserController = final StreamController _currentUserController = StreamController.broadcast(); @@ -268,17 +267,17 @@ class GoogleSignIn { } Future _ensureInitialized() { - return _initialization ??= - GoogleSignInPlatform.instance.initWithForceCodeForRefreshToken( - signInOption: signInOption, - scopes: scopes, - hostedDomain: hostedDomain, - clientId: clientId, - forceCodeForRefreshToken: forceCodeForRefreshToken, - )..catchError((dynamic _) { - // Invalidate initialization if it errors out. - _initialization = null; - }); + return _initialization ??= GoogleSignInPlatform.instance.initWithParams( + SignInInitParameters( + signInOption: signInOption, + scopes: scopes, + hostedDomain: hostedDomain, + clientId: clientId, + forceCodeForRefreshToken: forceCodeForRefreshToken)) + ..catchError((dynamic _) { + // Invalidate initialization if it errors out. + _initialization = null; + }); } /// The most recently scheduled method call. diff --git a/packages/google_sign_in/google_sign_in/pubspec.yaml b/packages/google_sign_in/google_sign_in/pubspec.yaml index 29ef0c4de5e2..956899004776 100644 --- a/packages/google_sign_in/google_sign_in/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android and iOS. repository: https://github.com/flutter/plugins/tree/main/packages/google_sign_in/google_sign_in issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 5.3.1 +version: 5.3.2 environment: @@ -37,10 +37,6 @@ dev_dependencies: integration_test: sdk: flutter -dependency_overrides: - google_sign_in_platform_interface: - path: ../google_sign_in_platform_interface - # The example deliberately includes limited-use secrets. false_secrets: - /example/android/app/google-services.json diff --git a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart index 720de6e79f1f..ffab63b460ee 100644 --- a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart +++ b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart @@ -104,7 +104,7 @@ void main() { }); test('forceCodeForRefreshToken sent with init method call', () async { - final fakeClientId = 'fakeClientId'; + const String fakeClientId = 'fakeClientId'; googleSignIn = GoogleSignIn(clientId: fakeClientId, forceCodeForRefreshToken: true); await googleSignIn.signIn(); diff --git a/packages/google_sign_in/google_sign_in_android/AUTHORS b/packages/google_sign_in/google_sign_in_android/AUTHORS index 493a0b4ef9c2..35d24a5ae0b5 100644 --- a/packages/google_sign_in/google_sign_in_android/AUTHORS +++ b/packages/google_sign_in/google_sign_in_android/AUTHORS @@ -64,3 +64,4 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> +Twin Sun, LLC diff --git a/packages/google_sign_in/google_sign_in_android/lib/google_sign_in_android.dart b/packages/google_sign_in/google_sign_in_android/lib/google_sign_in_android.dart index d96328de695a..731da3968b3f 100644 --- a/packages/google_sign_in/google_sign_in_android/lib/google_sign_in_android.dart +++ b/packages/google_sign_in/google_sign_in_android/lib/google_sign_in_android.dart @@ -30,11 +30,22 @@ class GoogleSignInAndroid extends GoogleSignInPlatform { String? hostedDomain, String? clientId, }) { + return initWithParams(SignInInitParameters( + signInOption: signInOption, + scopes: scopes, + hostedDomain: hostedDomain, + clientId: clientId, + )); + } + + @override + Future initWithParams(SignInInitParameters params) { return channel.invokeMethod('init', { - 'signInOption': signInOption.toString(), - 'scopes': scopes, - 'hostedDomain': hostedDomain, - 'clientId': clientId, + 'signInOption': params.signInOption.toString(), + 'scopes': params.scopes, + 'hostedDomain': params.hostedDomain, + 'clientId': params.clientId, + 'forceCodeForRefreshToken': params.forceCodeForRefreshToken, }); } diff --git a/packages/google_sign_in/google_sign_in_android/test/google_sign_in_android_test.dart b/packages/google_sign_in/google_sign_in_android/test/google_sign_in_android_test.dart index 7d39ae5f0232..df110f2daed4 100644 --- a/packages/google_sign_in/google_sign_in_android/test/google_sign_in_android_test.dart +++ b/packages/google_sign_in/google_sign_in_android/test/google_sign_in_android_test.dart @@ -101,16 +101,18 @@ void main() { test('Other functions pass through arguments to the channel', () async { final Map tests = { () { - googleSignIn.init( + googleSignIn.initWithParams(const SignInInitParameters( hostedDomain: 'example.com', scopes: ['two', 'scopes'], signInOption: SignInOption.games, - clientId: 'fakeClientId'); + clientId: 'fakeClientId', + forceCodeForRefreshToken: true)); }: isMethodCall('init', arguments: { 'hostedDomain': 'example.com', 'scopes': ['two', 'scopes'], 'signInOption': 'SignInOption.games', 'clientId': 'fakeClientId', + 'forceCodeForRefreshToken': true, }), () { googleSignIn.getTokens( diff --git a/packages/google_sign_in/google_sign_in_ios/AUTHORS b/packages/google_sign_in/google_sign_in_ios/AUTHORS index 493a0b4ef9c2..35d24a5ae0b5 100644 --- a/packages/google_sign_in/google_sign_in_ios/AUTHORS +++ b/packages/google_sign_in/google_sign_in_ios/AUTHORS @@ -64,3 +64,4 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> +Twin Sun, LLC diff --git a/packages/google_sign_in/google_sign_in_ios/lib/google_sign_in_ios.dart b/packages/google_sign_in/google_sign_in_ios/lib/google_sign_in_ios.dart index ce8865664507..07407eaf5236 100644 --- a/packages/google_sign_in/google_sign_in_ios/lib/google_sign_in_ios.dart +++ b/packages/google_sign_in/google_sign_in_ios/lib/google_sign_in_ios.dart @@ -30,15 +30,25 @@ class GoogleSignInIOS extends GoogleSignInPlatform { String? hostedDomain, String? clientId, }) { - if (signInOption == SignInOption.games) { + return initWithParams(SignInInitParameters( + signInOption: signInOption, + scopes: scopes, + hostedDomain: hostedDomain, + clientId: clientId, + )); + } + + @override + Future initWithParams(SignInInitParameters params) { + if (params.signInOption == SignInOption.games) { throw PlatformException( code: 'unsupported-options', message: 'Games sign in is not supported on iOS'); } return channel.invokeMethod('init', { - 'scopes': scopes, - 'hostedDomain': hostedDomain, - 'clientId': clientId, + 'scopes': params.scopes, + 'hostedDomain': params.hostedDomain, + 'clientId': params.clientId, }); } diff --git a/packages/google_sign_in/google_sign_in_ios/pubspec.yaml b/packages/google_sign_in/google_sign_in_ios/pubspec.yaml index b6f541b22ce1..c03251397e6a 100644 --- a/packages/google_sign_in/google_sign_in_ios/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_ios/pubspec.yaml @@ -19,7 +19,7 @@ flutter: dependencies: flutter: sdk: flutter - google_sign_in_platform_interface: ^2.1.0 + google_sign_in_platform_interface: ^2.1.3 dev_dependencies: flutter_driver: diff --git a/packages/google_sign_in/google_sign_in_ios/test/google_sign_in_ios_test.dart b/packages/google_sign_in/google_sign_in_ios/test/google_sign_in_ios_test.dart index 92637e938fd9..3013b8d41d2a 100644 --- a/packages/google_sign_in/google_sign_in_ios/test/google_sign_in_ios_test.dart +++ b/packages/google_sign_in/google_sign_in_ios/test/google_sign_in_ios_test.dart @@ -116,10 +116,10 @@ void main() { test('Other functions pass through arguments to the channel', () async { final Map tests = { () { - googleSignIn.init( + googleSignIn.initWithParams(const SignInInitParameters( hostedDomain: 'example.com', scopes: ['two', 'scopes'], - clientId: 'fakeClientId'); + clientId: 'fakeClientId')); }: isMethodCall('init', arguments: { 'hostedDomain': 'example.com', 'scopes': ['two', 'scopes'], diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart index 60fdbd97ffe5..69d8455b6bd2 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart @@ -77,9 +77,6 @@ abstract class GoogleSignInPlatform { /// The [signInOption] determines the user experience. [SigninOption.games] is /// only supported on Android. /// - /// This method is deprecated in favor of [initWithForceFodeForRefreshToken] and - /// will be removed in a future update. - /// /// See: /// https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams Future init({ diff --git a/packages/google_sign_in/google_sign_in_web/AUTHORS b/packages/google_sign_in/google_sign_in_web/AUTHORS index 493a0b4ef9c2..35d24a5ae0b5 100644 --- a/packages/google_sign_in/google_sign_in_web/AUTHORS +++ b/packages/google_sign_in/google_sign_in_web/AUTHORS @@ -64,3 +64,4 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> +Twin Sun, LLC diff --git a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md index 28e3b18f84fc..48db2cab915f 100644 --- a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.10.1+3 -* Adds override for `GoogleSignInPlatform.initWithForceCodeForRefreshToken`. +* Adds override for `GoogleSignInPlatform.initWithParams`. ## 0.10.1+2 diff --git a/packages/google_sign_in/google_sign_in_web/example/pubspec.yaml b/packages/google_sign_in/google_sign_in_web/example/pubspec.yaml index 39c976cbcc9d..1bdb2f09c465 100644 --- a/packages/google_sign_in/google_sign_in_web/example/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_web/example/pubspec.yaml @@ -20,7 +20,3 @@ dev_dependencies: integration_test: sdk: flutter js: ^0.6.3 - -dependency_overrides: - google_sign_in_platform_interface: - path: ../../google_sign_in_platform_interface diff --git a/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart b/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart index 6e797bda4818..60245a3b5683 100644 --- a/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart +++ b/packages/google_sign_in/google_sign_in_web/lib/google_sign_in_web.dart @@ -71,8 +71,18 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { SignInOption signInOption = SignInOption.standard, String? hostedDomain, String? clientId, - }) async { - final String? appClientId = clientId ?? _autoDetectedClientId; + }) { + return initWithParams(SignInInitParameters( + signInOption: signInOption, + scopes: scopes, + hostedDomain: hostedDomain, + clientId: clientId, + )); + } + + @override + Future initWithParams(SignInInitParameters params) async { + final String? appClientId = params.clientId ?? _autoDetectedClientId; assert( appClientId != null, 'ClientID not set. Either set it on a ' @@ -80,7 +90,7 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { ' or pass clientId when calling init()'); assert( - !scopes.any((String scope) => scope.contains(' ')), + !params.scopes.any((String scope) => scope.contains(' ')), "OAuth 2.0 Scopes for Google APIs can't contain spaces. " 'Check https://developers.google.com/identity/protocols/googlescopes ' 'for a list of valid OAuth 2.0 scopes.'); @@ -88,9 +98,9 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { await _isGapiInitialized; final auth2.GoogleAuth auth = auth2.init(auth2.ClientConfig( - hosted_domain: hostedDomain, + hosted_domain: params.hostedDomain, // The js lib wants a space-separated list of values - scope: scopes.join(' '), + scope: params.scopes.join(' '), client_id: appClientId!, plugin_name: 'dart-google_sign_in_web', )); @@ -120,22 +130,6 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { return _isAuthInitialized; } - @override - Future initWithForceCodeForRefreshToken({ - List scopes = const [], - SignInOption signInOption = SignInOption.standard, - String? hostedDomain, - String? clientId, - bool forceCodeForRefreshToken = false, - }) async { - await init( - scopes: scopes, - signInOption: signInOption, - hostedDomain: hostedDomain, - clientId: clientId, - ); - } - @override Future signInSilently() async { await initialized; diff --git a/packages/google_sign_in/google_sign_in_web/pubspec.yaml b/packages/google_sign_in/google_sign_in_web/pubspec.yaml index 05636709fb6f..db81ef335730 100644 --- a/packages/google_sign_in/google_sign_in_web/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_web/pubspec.yaml @@ -22,13 +22,9 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - google_sign_in_platform_interface: ^2.1.2 + google_sign_in_platform_interface: ^2.1.3 js: ^0.6.3 dev_dependencies: flutter_test: sdk: flutter - -dependency_overrides: - google_sign_in_platform_interface: - path: ../google_sign_in_platform_interface \ No newline at end of file From f9de8322af4f993232c5ae75c3177b1681a46467 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Wed, 11 May 2022 17:06:02 -0500 Subject: [PATCH 14/20] [force-code-for-refresh-token] Correct interface versions and changelogs --- packages/google_sign_in/google_sign_in/CHANGELOG.md | 2 +- packages/google_sign_in/google_sign_in_android/CHANGELOG.md | 4 ++++ packages/google_sign_in/google_sign_in_android/pubspec.yaml | 4 ++-- packages/google_sign_in/google_sign_in_ios/CHANGELOG.md | 4 ++++ packages/google_sign_in/google_sign_in_ios/pubspec.yaml | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/CHANGELOG.md b/packages/google_sign_in/google_sign_in/CHANGELOG.md index 6295a185a99c..4900c31f7f99 100644 --- a/packages/google_sign_in/google_sign_in/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in/CHANGELOG.md @@ -1,6 +1,6 @@ ## 5.3.2 -* Adds `forceCodeForRefreshToken` parameter to `GoogleSignIn`. +* Adds override for `GoogleSignInPlatform.initWithParams`. ## 5.3.1 diff --git a/packages/google_sign_in/google_sign_in_android/CHANGELOG.md b/packages/google_sign_in/google_sign_in_android/CHANGELOG.md index 90069d05f442..d1b5bebe9ac2 100644 --- a/packages/google_sign_in/google_sign_in_android/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.2.8 + +* Adds override for `GoogleSignIn.initWithParams` to handle new `forceCodeForRefreshToken` parameter. + ## 5.2.7 * Fixes library_private_types_in_public_api, sort_child_properties_last and use_key_in_widget_constructors diff --git a/packages/google_sign_in/google_sign_in_android/pubspec.yaml b/packages/google_sign_in/google_sign_in_android/pubspec.yaml index d9b272320694..d553484f6967 100644 --- a/packages/google_sign_in/google_sign_in_android/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_android/pubspec.yaml @@ -2,7 +2,7 @@ name: google_sign_in_android description: Android implementation of the google_sign_in plugin. repository: https://github.com/flutter/plugins/tree/main/packages/google_sign_in/google_sign_in_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 5.2.7 +version: 5.2.8 environment: sdk: ">=2.14.0 <3.0.0" @@ -20,7 +20,7 @@ flutter: dependencies: flutter: sdk: flutter - google_sign_in_platform_interface: ^2.1.0 + google_sign_in_platform_interface: ^2.1.3 dev_dependencies: flutter_driver: diff --git a/packages/google_sign_in/google_sign_in_ios/CHANGELOG.md b/packages/google_sign_in/google_sign_in_ios/CHANGELOG.md index 90069d05f442..a8af1a0ab06b 100644 --- a/packages/google_sign_in/google_sign_in_ios/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_ios/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.2.8 + +* Adds override for `GoogleSignInPlatform.initWithParams`. + ## 5.2.7 * Fixes library_private_types_in_public_api, sort_child_properties_last and use_key_in_widget_constructors diff --git a/packages/google_sign_in/google_sign_in_ios/pubspec.yaml b/packages/google_sign_in/google_sign_in_ios/pubspec.yaml index c03251397e6a..cc3d79f3aa6d 100644 --- a/packages/google_sign_in/google_sign_in_ios/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_ios/pubspec.yaml @@ -2,7 +2,7 @@ name: google_sign_in_ios description: Android implementation of the google_sign_in plugin. repository: https://github.com/flutter/plugins/tree/main/packages/google_sign_in/google_sign_in_ios issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 5.2.7 +version: 5.2.8 environment: sdk: ">=2.14.0 <3.0.0" From 9a186778283a507f41f22c9a0d4b369fd1f66cf8 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Wed, 11 May 2022 19:36:47 -0500 Subject: [PATCH 15/20] [force-code-for-refresh-token] Fix formatting issues --- .../googlesignin/GoogleSignInPlugin.java | 29 +++++++++---------- .../googlesignin/GoogleSignInTest.java | 6 ++-- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java b/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java index e49a55b08a60..d9df30ac93d5 100644 --- a/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java +++ b/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java @@ -42,8 +42,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import android.content.res.Resources; -import android.util.Log; /** Google sign-in plugin for Flutter. */ public class GoogleSignInPlugin implements MethodCallHandler, FlutterPlugin, ActivityAware { @@ -260,26 +258,25 @@ public void init( } /** - * Factory class that generates the GoogleSignInOptions.Builder. This is exposed so that tests - * can inject a mock instance of the GoogleSignInOptions.Builder. + * Factory class that generates the GoogleSignInOptions.Builder. This is exposed so that tests can + * inject a mock instance of the GoogleSignInOptions.Builder. */ public static class OptionsBuilderFactory { public static final String DEFAULT_SIGN_IN = "SignInOption.standard"; public static final String DEFAULT_GAMES_SIGN_IN = "SignInOption.games"; - /** - * Returns an instance of GoogleSignInOptions.Builder with the passed signInOption. - */ + /** Returns an instance of GoogleSignInOptions.Builder with the passed signInOption. */ public GoogleSignInOptions.Builder get(String signInOption) { switch (signInOption) { - case DEFAULT_GAMES_SIGN_IN: - return new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); + case DEFAULT_GAMES_SIGN_IN: + return new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); - case DEFAULT_SIGN_IN: - return new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail(); - default: - throw new IllegalStateException("Unknown signInOption"); - } + case DEFAULT_SIGN_IN: + return new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) + .requestEmail(); + default: + throw new IllegalStateException("Unknown signInOption"); + } } } @@ -365,8 +362,8 @@ private int getClientIdIdentifier() { return clientIdIdentifierOverride; } return context - .getResources() - .getIdentifier("default_web_client_id", "string", context.getPackageName()); + .getResources() + .getIdentifier("default_web_client_id", "string", context.getPackageName()); } /** diff --git a/packages/google_sign_in/google_sign_in_android/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java b/packages/google_sign_in/google_sign_in_android/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java index 563849949a7c..3f15cb9afb30 100644 --- a/packages/google_sign_in/google_sign_in_android/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java +++ b/packages/google_sign_in/google_sign_in_android/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java @@ -47,8 +47,10 @@ public void setUp() { when(mockRegistrar.messenger()).thenReturn(mockMessenger); when(mockRegistrar.context()).thenReturn(mockContext); when(mockRegistrar.activity()).thenReturn(mockActivity); - when(optionsBuilderFactory.get(GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN)).thenReturn(optionsBuilder); - when(optionsBuilderFactory.get(GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_GAMES_SIGN_IN)).thenReturn(optionsBuilder); + when(optionsBuilderFactory.get(GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN)) + .thenReturn(optionsBuilder); + when(optionsBuilderFactory.get(GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_GAMES_SIGN_IN)) + .thenReturn(optionsBuilder); plugin = new GoogleSignInPlugin(); plugin.initInstance(mockRegistrar.messenger(), mockRegistrar.context(), mockGoogleSignIn); plugin.setUpRegistrar(mockRegistrar); From aec0d6ecd37201a80827e1781914b275b0058941 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Wed, 11 May 2022 19:42:52 -0500 Subject: [PATCH 16/20] [force-code-for-refresh-token] One more formatting change --- .../java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java b/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java index d9df30ac93d5..9acdedc703b6 100644 --- a/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java +++ b/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java @@ -42,7 +42,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; - /** Google sign-in plugin for Flutter. */ public class GoogleSignInPlugin implements MethodCallHandler, FlutterPlugin, ActivityAware { private static final String CHANNEL_NAME = "plugins.flutter.io/google_sign_in_android"; From 7a859c7c685cfc9eebb820b98374a2123fe1dc6b Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Thu, 21 Jul 2022 16:18:48 -0500 Subject: [PATCH 17/20] [force-code-for-refresh-token] Clean up after merge --- .../google_sign_in/example/pubspec.yaml | 1 - .../test/google_sign_in_test.dart | 23 +++++-------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/example/pubspec.yaml b/packages/google_sign_in/google_sign_in/example/pubspec.yaml index f9b17cd3eb68..822f83895cfb 100644 --- a/packages/google_sign_in/google_sign_in/example/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in/example/pubspec.yaml @@ -27,4 +27,3 @@ dev_dependencies: flutter: uses-material-design: true - diff --git a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart index f0ce833f7296..b8a596b02065 100644 --- a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart +++ b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart @@ -81,24 +81,13 @@ void main() { }); test('forceCodeForRefreshToken sent with init method call', () async { - const String fakeClientId = 'fakeClientId'; - googleSignIn = - GoogleSignIn(clientId: fakeClientId, forceCodeForRefreshToken: true); + final GoogleSignIn googleSignIn = + GoogleSignIn(forceCodeForRefreshToken: true); + await googleSignIn.signIn(); - expect(googleSignIn.currentUser, isNotNull); - expect( - log, - [ - isMethodCall('init', arguments: { - 'signInOption': 'SignInOption.standard', - 'scopes': [], - 'hostedDomain': null, - 'clientId': fakeClientId, - 'forceCodeForRefreshToken': true, - }), - isMethodCall('signIn', arguments: null), - ], - ); + + _verifyInit(mockPlatform, forceCodeForRefreshToken: true); + verify(mockPlatform.signIn()); }); test('signOut', () async { From 63d78e7eaeafe50e143914eaf7044b5351ae2753 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Thu, 21 Jul 2022 16:20:24 -0500 Subject: [PATCH 18/20] [force-code-for-refresh-token] Add to main flutter-plugins AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 31402c79d54a..3112c3b3fd05 100644 --- a/AUTHORS +++ b/AUTHORS @@ -68,3 +68,4 @@ Daniel Roek TheOneWithTheBraid Rulong Chen(陈汝龙) Hwanseok Kang +Twin Sun, LLC From 5ffd3753d9fed637b0c16e89a37e9e7990620d93 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Thu, 21 Jul 2022 16:30:53 -0500 Subject: [PATCH 19/20] [force-code-for-refresh-token] [force-code-for-refresh-token-platform-implementations] Revert unnecessary changes to google_sign_in_web --- packages/google_sign_in/google_sign_in_web/AUTHORS | 1 - packages/google_sign_in/google_sign_in_web/CHANGELOG.md | 4 ---- packages/google_sign_in/google_sign_in_web/pubspec.yaml | 2 +- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/google_sign_in/google_sign_in_web/AUTHORS b/packages/google_sign_in/google_sign_in_web/AUTHORS index 35d24a5ae0b5..493a0b4ef9c2 100644 --- a/packages/google_sign_in/google_sign_in_web/AUTHORS +++ b/packages/google_sign_in/google_sign_in_web/AUTHORS @@ -64,4 +64,3 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> -Twin Sun, LLC diff --git a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md index cea12070a14e..12e6d9630f9c 100644 --- a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md @@ -1,7 +1,3 @@ -## 0.10.3 - -* Adds override for `GoogleSignInPlatform.initWithParams`. - ## 0.10.2 * Migrates to new platform-interface `initWithParams` method. diff --git a/packages/google_sign_in/google_sign_in_web/pubspec.yaml b/packages/google_sign_in/google_sign_in_web/pubspec.yaml index e2d70bfb0083..1dedd6de6666 100644 --- a/packages/google_sign_in/google_sign_in_web/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_web/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android, iOS and Web. repository: https://github.com/flutter/plugins/tree/main/packages/google_sign_in/google_sign_in_web issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 0.10.3 +version: 0.10.2 environment: sdk: ">=2.12.0 <3.0.0" From 2d79cc6f6853706d525c2cea000447cf0017e0c9 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Thu, 1 Sep 2022 20:58:00 -0500 Subject: [PATCH 20/20] [force-code-for-refresh-token] Revert android/ios changes to the published versions; update google_sign_in changes / changelog / pubspec depenencies --- .../google_sign_in/pubspec.yaml | 6 +- .../googlesignin/GoogleSignInPlugin.java | 70 +++++------------- .../googlesignin/GoogleSignInTest.java | 74 ------------------- .../test/google_sign_in_android_test.dart | 5 +- .../test/google_sign_in_ios_test.dart | 4 +- 5 files changed, 24 insertions(+), 135 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/pubspec.yaml b/packages/google_sign_in/google_sign_in/pubspec.yaml index 50339902fe75..c32dee78468b 100644 --- a/packages/google_sign_in/google_sign_in/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android and iOS. repository: https://github.com/flutter/plugins/tree/main/packages/google_sign_in/google_sign_in issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 5.4.1 +version: 5.4.2 environment: @@ -23,8 +23,8 @@ flutter: dependencies: flutter: sdk: flutter - google_sign_in_android: ^6.0.0 - google_sign_in_ios: ^5.4.0 + google_sign_in_android: ^6.1.0 + google_sign_in_ios: ^5.5.0 google_sign_in_platform_interface: ^2.2.0 google_sign_in_web: ^0.10.0 diff --git a/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java b/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java index 7de700c774e9..e84d196a6a0d 100644 --- a/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java +++ b/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java @@ -82,16 +82,6 @@ public void setUpRegistrar(PluginRegistry.Registrar registrar) { delegate.setUpRegistrar(registrar); } - @VisibleForTesting - public void setOptionsBuilderFactory(OptionsBuilderFactory factory) { - delegate.setOptionsBuilderFactory(factory); - } - - @VisibleForTesting - public void setClientIdIdentifierOverride(int clientIdIdentifier) { - delegate.setClientIdIdentifierOverride(clientIdIdentifier); - } - private void dispose() { delegate = null; channel.setMethodCallHandler(null); @@ -261,29 +251,6 @@ public void init( public void requestScopes(final Result result, final List scopes); } - /** - * Factory class that generates the GoogleSignInOptions.Builder. This is exposed so that tests can - * inject a mock instance of the GoogleSignInOptions.Builder. - */ - public static class OptionsBuilderFactory { - public static final String DEFAULT_SIGN_IN = "SignInOption.standard"; - public static final String DEFAULT_GAMES_SIGN_IN = "SignInOption.games"; - - /** Returns an instance of GoogleSignInOptions.Builder with the passed signInOption. */ - public GoogleSignInOptions.Builder get(String signInOption) { - switch (signInOption) { - case DEFAULT_GAMES_SIGN_IN: - return new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); - - case DEFAULT_SIGN_IN: - return new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) - .requestEmail(); - default: - throw new IllegalStateException("Unknown signInOption"); - } - } - } - /** * Delegate class that does the work for the Google sign-in plugin. This is exposed as a dedicated * class for use in other plugins that wrap basic sign-in functionality. @@ -308,6 +275,9 @@ public static class Delegate implements IDelegate, PluginRegistry.ActivityResult private static final String ERROR_FAILURE_TO_RECOVER_AUTH = "failed_to_recover_auth"; private static final String ERROR_USER_RECOVERABLE_AUTH = "user_recoverable_auth"; + private static final String DEFAULT_SIGN_IN = "SignInOption.standard"; + private static final String DEFAULT_GAMES_SIGN_IN = "SignInOption.games"; + private final Context context; // Only set registrar for v1 embedder. @SuppressWarnings("deprecation") @@ -320,8 +290,6 @@ public static class Delegate implements IDelegate, PluginRegistry.ActivityResult private GoogleSignInClient signInClient; private List requestedScopes; private PendingOperation pendingOperation; - private OptionsBuilderFactory optionsBuilderFactory = new OptionsBuilderFactory(); - private int clientIdIdentifierOverride = -1; public Delegate(Context context, GoogleSignInWrapper googleSignInWrapper) { this.context = context; @@ -334,14 +302,6 @@ public void setUpRegistrar(PluginRegistry.Registrar registrar) { registrar.addActivityResultListener(this); } - public void setOptionsBuilderFactory(OptionsBuilderFactory factory) { - this.optionsBuilderFactory = factory; - } - - public void setClientIdIdentifierOverride(int clientIdIdentifier) { - this.clientIdIdentifierOverride = clientIdIdentifier; - } - public void setActivity(Activity activity) { this.activity = activity; } @@ -363,15 +323,6 @@ private void checkAndSetPendingOperation(String method, Result result, Object da pendingOperation = new PendingOperation(method, result, data); } - private int getClientIdIdentifier() { - if (clientIdIdentifierOverride != -1) { - return clientIdIdentifierOverride; - } - return context - .getResources() - .getIdentifier("default_web_client_id", "string", context.getPackageName()); - } - /** * Initializes this delegate so that it is ready to perform other operations. The Dart code * guarantees that this will be called and completed before any other methods are invoked. @@ -386,7 +337,20 @@ public void init( String serverClientId, boolean forceCodeForRefreshToken) { try { - GoogleSignInOptions.Builder optionsBuilder = optionsBuilderFactory.get(signInOption); + GoogleSignInOptions.Builder optionsBuilder; + + switch (signInOption) { + case DEFAULT_GAMES_SIGN_IN: + optionsBuilder = + new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN); + break; + case DEFAULT_SIGN_IN: + optionsBuilder = + new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail(); + break; + default: + throw new IllegalStateException("Unknown signInOption"); + } // The clientId parameter is not supported on Android. // Android apps are identified by their package name and the SHA-1 of their signing key. diff --git a/packages/google_sign_in/google_sign_in_android/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java b/packages/google_sign_in/google_sign_in_android/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java index f933bb1ea2da..9692417390a5 100644 --- a/packages/google_sign_in/google_sign_in_android/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java +++ b/packages/google_sign_in/google_sign_in_android/android/src/test/java/io/flutter/plugins/googlesignin/GoogleSignInTest.java @@ -42,8 +42,6 @@ public class GoogleSignInTest { @Spy MethodChannel.Result result; @Mock GoogleSignInWrapper mockGoogleSignIn; @Mock GoogleSignInAccount account; - @Mock GoogleSignInPlugin.OptionsBuilderFactory optionsBuilderFactory; - @Mock GoogleSignInOptions.Builder optionsBuilder; @Mock GoogleSignInClient mockClient; private GoogleSignInPlugin plugin; @@ -53,82 +51,10 @@ public void setUp() { when(mockRegistrar.messenger()).thenReturn(mockMessenger); when(mockRegistrar.context()).thenReturn(mockContext); when(mockRegistrar.activity()).thenReturn(mockActivity); - when(optionsBuilderFactory.get(GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN)) - .thenReturn(optionsBuilder); - when(optionsBuilderFactory.get(GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_GAMES_SIGN_IN)) - .thenReturn(optionsBuilder); when(mockContext.getResources()).thenReturn(mockResources); plugin = new GoogleSignInPlugin(); plugin.initInstance(mockRegistrar.messenger(), mockRegistrar.context(), mockGoogleSignIn); plugin.setUpRegistrar(mockRegistrar); - plugin.setOptionsBuilderFactory(optionsBuilderFactory); - plugin.setClientIdIdentifierOverride(0); - } - - @Test - public void init_PassesForceCodeForRefreshTokenFalseWithClientIdParameter() { - HashMap arguments = new HashMap<>(); - arguments.put("signInOption", GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN); - arguments.put("requestedScopes", Collections.singletonList("requestedScope")); - arguments.put("hostedDomain", null); - arguments.put("clientId", "mockClientId"); - arguments.put("forceCodeForRefreshToken", false); - - MethodCall methodCall = new MethodCall("init", arguments); - - plugin.onMethodCall(methodCall, result); - - verify(optionsBuilder, times(1)).requestServerAuthCode("mockClientId", false); - } - - @Test - public void init_PassesForceCodeForRefreshTokenTrueWithClientIdParameter() { - HashMap arguments = new HashMap<>(); - arguments.put("signInOption", GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN); - arguments.put("requestedScopes", Collections.singletonList("requestedScope")); - arguments.put("hostedDomain", null); - arguments.put("clientId", "mockClientId"); - arguments.put("forceCodeForRefreshToken", true); - - MethodCall methodCall = new MethodCall("init", arguments); - - plugin.onMethodCall(methodCall, result); - - verify(optionsBuilder, times(1)).requestServerAuthCode("mockClientId", true); - } - - @Test - public void init_PassesForceCodeForRefreshTokenFalseWithClientIdFromResources() { - plugin.setClientIdIdentifierOverride(1); - when(mockContext.getString(1)).thenReturn("mockClientId"); - HashMap arguments = new HashMap<>(); - arguments.put("signInOption", GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN); - arguments.put("requestedScopes", Collections.singletonList("requestedScope")); - arguments.put("hostedDomain", null); - arguments.put("forceCodeForRefreshToken", false); - - MethodCall methodCall = new MethodCall("init", arguments); - - plugin.onMethodCall(methodCall, result); - - verify(optionsBuilder, times(1)).requestServerAuthCode("mockClientId", false); - } - - @Test - public void init_PassesForceCodeForRefreshTokenTrueWithClientIdFromResources() { - plugin.setClientIdIdentifierOverride(1); - when(mockContext.getString(1)).thenReturn("mockClientId"); - HashMap arguments = new HashMap<>(); - arguments.put("signInOption", GoogleSignInPlugin.OptionsBuilderFactory.DEFAULT_SIGN_IN); - arguments.put("requestedScopes", Collections.singletonList("requestedScope")); - arguments.put("hostedDomain", null); - arguments.put("forceCodeForRefreshToken", true); - - MethodCall methodCall = new MethodCall("init", arguments); - - plugin.onMethodCall(methodCall, result); - - verify(optionsBuilder, times(1)).requestServerAuthCode("mockClientId", true); } @Test diff --git a/packages/google_sign_in/google_sign_in_android/test/google_sign_in_android_test.dart b/packages/google_sign_in/google_sign_in_android/test/google_sign_in_android_test.dart index 62727c6fa7dd..948ced3f65bc 100644 --- a/packages/google_sign_in/google_sign_in_android/test/google_sign_in_android_test.dart +++ b/packages/google_sign_in/google_sign_in_android/test/google_sign_in_android_test.dart @@ -101,12 +101,11 @@ void main() { test('Other functions pass through arguments to the channel', () async { final Map tests = { () { - googleSignIn.initWithParams(const SignInInitParameters( + googleSignIn.init( hostedDomain: 'example.com', scopes: ['two', 'scopes'], signInOption: SignInOption.games, - clientId: 'fakeClientId', - forceCodeForRefreshToken: true)); + clientId: 'fakeClientId'); }: isMethodCall('init', arguments: { 'hostedDomain': 'example.com', 'scopes': ['two', 'scopes'], diff --git a/packages/google_sign_in/google_sign_in_ios/test/google_sign_in_ios_test.dart b/packages/google_sign_in/google_sign_in_ios/test/google_sign_in_ios_test.dart index 66f62e1c96b3..ace65092f61d 100644 --- a/packages/google_sign_in/google_sign_in_ios/test/google_sign_in_ios_test.dart +++ b/packages/google_sign_in/google_sign_in_ios/test/google_sign_in_ios_test.dart @@ -116,10 +116,10 @@ void main() { test('Other functions pass through arguments to the channel', () async { final Map tests = { () { - googleSignIn.initWithParams(const SignInInitParameters( + googleSignIn.init( hostedDomain: 'example.com', scopes: ['two', 'scopes'], - clientId: 'fakeClientId')); + clientId: 'fakeClientId'); }: isMethodCall('init', arguments: { 'hostedDomain': 'example.com', 'scopes': ['two', 'scopes'],