diff --git a/packages/google_sign_in/google_sign_in/CHANGELOG.md b/packages/google_sign_in/google_sign_in/CHANGELOG.md index eee5a932cf69..17f98cbaa1db 100644 --- a/packages/google_sign_in/google_sign_in/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in/CHANGELOG.md @@ -1,5 +1,7 @@ -## NEXT +## 6.3.0 +* Adds a sign-in field to allow Android clients to explicitly specify an account name. This + capability is only available within Android for the underlying libraries. * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. ## 6.2.2 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 5335068734a8..8c77891dea33 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,8 @@ dev_dependencies: flutter: uses-material-design: true + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins +dependency_overrides: + {google_sign_in_android: {path: ../../../../packages/google_sign_in/google_sign_in_android}, google_sign_in_ios: {path: ../../../../packages/google_sign_in/google_sign_in_ios}, google_sign_in_platform_interface: {path: ../../../../packages/google_sign_in/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 ed11f0f512e9..93565ad052b5 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 @@ -187,6 +187,7 @@ class GoogleSignIn { this.clientId, this.serverClientId, this.forceCodeForRefreshToken = false, + this.forceAccountName, }) { // Start initializing. if (kIsWeb) { @@ -263,6 +264,9 @@ class GoogleSignIn { /// Force the authorization code to be valid for a refresh token every time. Only needed on Android. final bool forceCodeForRefreshToken; + /// Explicitly specifies the account name to be used in sign-in. Must only be set on Android. + final String? forceAccountName; + final StreamController _currentUserController = StreamController.broadcast(); @@ -317,6 +321,7 @@ class GoogleSignIn { clientId: clientId, serverClientId: serverClientId, forceCodeForRefreshToken: forceCodeForRefreshToken, + forceAccountName: forceAccountName, )); unawaited(GoogleSignInPlatform.instance.userDataEvents diff --git a/packages/google_sign_in/google_sign_in/pubspec.yaml b/packages/google_sign_in/google_sign_in/pubspec.yaml index ee1a1e0b61d6..bc08d0fa3ca4 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. repository: https://github.com/flutter/packages/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: 6.2.2 +version: 6.3.0 environment: sdk: ^3.4.0 @@ -49,3 +49,8 @@ false_secrets: - /example/ios/RunnerTests/GoogleService-Info.plist - /example/ios/RunnerTests/GoogleSignInTests.m - /example/macos/Runner/Info.plist + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins +dependency_overrides: + {google_sign_in_android: {path: ../../../packages/google_sign_in/google_sign_in_android}, google_sign_in_ios: {path: ../../../packages/google_sign_in/google_sign_in_ios}, google_sign_in_platform_interface: {path: ../../../packages/google_sign_in/google_sign_in_platform_interface}} 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 9ca4124157f3..0853691f6ba0 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 @@ -113,6 +113,17 @@ void main() { verify(mockPlatform.signIn()); }); + test('forceAccountName sent with init method call', () async { + final GoogleSignIn googleSignIn = + GoogleSignIn(forceAccountName: 'fakeEmailAddress@example.com'); + + await googleSignIn.signIn(); + + _verifyInit(mockPlatform, + forceAccountName: 'fakeEmailAddress@example.com'); + verify(mockPlatform.signIn()); + }); + test('signOut', () async { final GoogleSignIn googleSignIn = GoogleSignIn(); @@ -447,6 +458,7 @@ void _verifyInit( String? clientId, String? serverClientId, bool forceCodeForRefreshToken = false, + String? forceAccountName, }) { verify(mockSignIn.initWithParams(argThat( isA() @@ -479,6 +491,11 @@ void _verifyInit( (SignInInitParameters p) => p.forceCodeForRefreshToken, 'forceCodeForRefreshToken', forceCodeForRefreshToken, + ) + .having( + (SignInInitParameters p) => p.forceAccountName, + 'forceAccountName', + forceAccountName, ), ))); } 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 5d2419a2c834..a051118da936 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 @@ +## 6.2.0 + +* Adds a sign-in field to allow clients to explicitly specify an account name. + ## 6.1.35 * Removes the dependency on the Guava library. 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 127c7c281f8c..462942127036 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 @@ -255,6 +255,11 @@ public void init(@NonNull Messages.InitParams params) { optionsBuilder.setHostedDomain(params.getHostedDomain()); } + String forceAccountName = params.getForceAccountName(); + if (!isNullOrEmpty(forceAccountName)) { + optionsBuilder.setAccountName(forceAccountName); + } + signInClient = googleSignInWrapper.getClient(context, optionsBuilder.build()); } catch (Exception e) { throw new FlutterError(ERROR_REASON_EXCEPTION, e.getMessage(), null); diff --git a/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/Messages.java b/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/Messages.java index e93f2bc66895..06462943b1b5 100644 --- a/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/Messages.java +++ b/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/Messages.java @@ -156,6 +156,16 @@ public void setForceCodeForRefreshToken(@NonNull Boolean setterArg) { this.forceCodeForRefreshToken = setterArg; } + private @Nullable String forceAccountName; + + public @Nullable String getForceAccountName() { + return forceAccountName; + } + + public void setForceAccountName(@Nullable String setterArg) { + this.forceAccountName = setterArg; + } + /** Constructor is non-public to enforce null safety; use Builder. */ InitParams() {} @@ -173,13 +183,20 @@ public boolean equals(Object o) { && Objects.equals(hostedDomain, that.hostedDomain) && Objects.equals(clientId, that.clientId) && Objects.equals(serverClientId, that.serverClientId) - && forceCodeForRefreshToken.equals(that.forceCodeForRefreshToken); + && forceCodeForRefreshToken.equals(that.forceCodeForRefreshToken) + && Objects.equals(forceAccountName, that.forceAccountName); } @Override public int hashCode() { return Objects.hash( - scopes, signInType, hostedDomain, clientId, serverClientId, forceCodeForRefreshToken); + scopes, + signInType, + hostedDomain, + clientId, + serverClientId, + forceCodeForRefreshToken, + forceAccountName); } public static final class Builder { @@ -232,6 +249,14 @@ public static final class Builder { return this; } + private @Nullable String forceAccountName; + + @CanIgnoreReturnValue + public @NonNull Builder setForceAccountName(@Nullable String setterArg) { + this.forceAccountName = setterArg; + return this; + } + public @NonNull InitParams build() { InitParams pigeonReturn = new InitParams(); pigeonReturn.setScopes(scopes); @@ -240,19 +265,21 @@ public static final class Builder { pigeonReturn.setClientId(clientId); pigeonReturn.setServerClientId(serverClientId); pigeonReturn.setForceCodeForRefreshToken(forceCodeForRefreshToken); + pigeonReturn.setForceAccountName(forceAccountName); return pigeonReturn; } } @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList<>(6); + ArrayList toListResult = new ArrayList<>(7); toListResult.add(scopes); toListResult.add(signInType); toListResult.add(hostedDomain); toListResult.add(clientId); toListResult.add(serverClientId); toListResult.add(forceCodeForRefreshToken); + toListResult.add(forceAccountName); return toListResult; } @@ -270,6 +297,8 @@ ArrayList toList() { pigeonResult.setServerClientId((String) serverClientId); Object forceCodeForRefreshToken = pigeonVar_list.get(5); pigeonResult.setForceCodeForRefreshToken((Boolean) forceCodeForRefreshToken); + Object forceAccountName = pigeonVar_list.get(6); + pigeonResult.setForceAccountName((String) forceAccountName); return pigeonResult; } } @@ -512,6 +541,7 @@ public interface Result { /** Failure case callback method for handling errors. */ void error(@NonNull Throwable error); } + /** Asynchronous error handling return type for nullable API method returns. */ public interface NullableResult { /** Success case callback method for handling returns. */ @@ -520,6 +550,7 @@ public interface NullableResult { /** Failure case callback method for handling errors. */ void error(@NonNull Throwable error); } + /** Asynchronous error handling return type for void API method returns. */ public interface VoidResult { /** Success case callback method for handling returns. */ @@ -528,26 +559,35 @@ public interface VoidResult { /** Failure case callback method for handling errors. */ void error(@NonNull Throwable error); } + /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface GoogleSignInApi { /** Initializes a sign in request with the given parameters. */ void init(@NonNull InitParams params); + /** Starts a silent sign in. */ void signInSilently(@NonNull Result result); + /** Starts a sign in with user interaction. */ void signIn(@NonNull Result result); + /** Requests the access token for the current sign in. */ void getAccessToken( @NonNull String email, @NonNull Boolean shouldRecoverAuth, @NonNull Result result); + /** Signs out the current user. */ void signOut(@NonNull VoidResult result); + /** Revokes scope grants to the application. */ void disconnect(@NonNull VoidResult result); + /** Returns whether the user is currently signed in. */ @NonNull Boolean isSignedIn(); + /** Clears the authentication caching for the given token, requiring a new sign in. */ void clearAuthCache(@NonNull String token); + /** Requests access to the given scopes. */ void requestScopes(@NonNull List scopes, @NonNull Result result); @@ -555,6 +595,7 @@ void getAccessToken( static @NonNull MessageCodec getCodec() { return PigeonCodec.INSTANCE; } + /** * Sets up an instance of `GoogleSignInApi` to handle messages through the `binaryMessenger`. */ 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 03853740b4ec..32ade75d0cb6 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 @@ -10,6 +10,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import android.accounts.Account; import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -32,6 +33,8 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; +import org.mockito.MockedConstruction; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.Spy; @@ -284,6 +287,25 @@ public void init_PassesForceCodeForRefreshTokenTrueWithServerClientIdFromResourc initAndAssertForceCodeForRefreshToken(params, true); } + @Test + public void init_PassesForceAccountName() { + String fakeAccountName = "fakeEmailAddress@example.com"; + + try (MockedConstruction mocked = + Mockito.mockConstruction( + Account.class, + (mock, context) -> { + when(mock.toString()).thenReturn(fakeAccountName); + })) { + InitParams params = buildInitParams("fakeClientId", "fakeServerClientId2", fakeAccountName); + + initAndAssertForceAccountName(params, fakeAccountName); + + List constructed = mocked.constructed(); + Assert.assertEquals(1, constructed.size()); + } + } + public void initAndAssertServerClientId(InitParams params, String serverClientId) { ArgumentCaptor optionsCaptor = ArgumentCaptor.forClass(GoogleSignInOptions.class); @@ -304,9 +326,23 @@ public void initAndAssertForceCodeForRefreshToken( forceCodeForRefreshToken, optionsCaptor.getValue().isForceCodeForRefreshToken()); } + public void initAndAssertForceAccountName(InitParams params, String forceAccountName) { + ArgumentCaptor optionsCaptor = + ArgumentCaptor.forClass(GoogleSignInOptions.class); + when(mockGoogleSignIn.getClient(any(Context.class), optionsCaptor.capture())) + .thenReturn(mockClient); + plugin.init(params); + Assert.assertEquals(forceAccountName, optionsCaptor.getValue().getAccount().toString()); + } + private static InitParams buildInitParams(String clientId, String serverClientId) { return buildInitParams( - Messages.SignInType.STANDARD, Collections.emptyList(), clientId, serverClientId, false); + Messages.SignInType.STANDARD, + Collections.emptyList(), + clientId, + serverClientId, + false, + null); } private static InitParams buildInitParams( @@ -316,7 +352,19 @@ private static InitParams buildInitParams( Collections.emptyList(), clientId, serverClientId, - forceCodeForRefreshToken); + forceCodeForRefreshToken, + null); + } + + private static InitParams buildInitParams( + String clientId, String serverClientId, String forceAccountName) { + return buildInitParams( + Messages.SignInType.STANDARD, + Collections.emptyList(), + clientId, + serverClientId, + false, + forceAccountName); } private static InitParams buildInitParams( @@ -324,7 +372,8 @@ private static InitParams buildInitParams( List scopes, String clientId, String serverClientId, - boolean forceCodeForRefreshToken) { + boolean forceCodeForRefreshToken, + String forceAccountName) { InitParams.Builder builder = new InitParams.Builder(); builder.setSignInType(signInType); builder.setScopes(scopes); @@ -335,6 +384,9 @@ private static InitParams buildInitParams( builder.setServerClientId(serverClientId); } builder.setForceCodeForRefreshToken(forceCodeForRefreshToken); + if (forceAccountName != null) { + builder.setForceAccountName(forceAccountName); + } return builder.build(); } } diff --git a/packages/google_sign_in/google_sign_in_android/example/pubspec.yaml b/packages/google_sign_in/google_sign_in_android/example/pubspec.yaml index 0adb6d9f80fc..8b69836ff955 100644 --- a/packages/google_sign_in/google_sign_in_android/example/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_android/example/pubspec.yaml @@ -28,3 +28,8 @@ dev_dependencies: flutter: uses-material-design: true + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins +dependency_overrides: + {google_sign_in_platform_interface: {path: ../../../../packages/google_sign_in/google_sign_in_platform_interface}} 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 fda32600fa9a..a064fba20de3 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 @@ -29,12 +29,14 @@ class GoogleSignInAndroid extends GoogleSignInPlatform { SignInOption signInOption = SignInOption.standard, String? hostedDomain, String? clientId, + String? forceAccountName, }) { return initWithParams(SignInInitParameters( signInOption: signInOption, scopes: scopes, hostedDomain: hostedDomain, clientId: clientId, + forceAccountName: forceAccountName, )); } @@ -47,6 +49,7 @@ class GoogleSignInAndroid extends GoogleSignInPlatform { clientId: params.clientId, serverClientId: params.serverClientId, forceCodeForRefreshToken: params.forceCodeForRefreshToken, + forceAccountName: params.forceAccountName, )); } diff --git a/packages/google_sign_in/google_sign_in_android/lib/src/messages.g.dart b/packages/google_sign_in/google_sign_in_android/lib/src/messages.g.dart index 1fb49d87a2ec..610741deb7b5 100644 --- a/packages/google_sign_in/google_sign_in_android/lib/src/messages.g.dart +++ b/packages/google_sign_in/google_sign_in_android/lib/src/messages.g.dart @@ -38,6 +38,7 @@ class InitParams { this.clientId, this.serverClientId, this.forceCodeForRefreshToken = false, + this.forceAccountName, }); List scopes; @@ -52,6 +53,8 @@ class InitParams { bool forceCodeForRefreshToken; + String? forceAccountName; + Object encode() { return [ scopes, @@ -60,6 +63,7 @@ class InitParams { clientId, serverClientId, forceCodeForRefreshToken, + forceAccountName, ]; } @@ -72,6 +76,7 @@ class InitParams { clientId: result[3] as String?, serverClientId: result[4] as String?, forceCodeForRefreshToken: result[5]! as bool, + forceAccountName: result[6] as String?, ); } } diff --git a/packages/google_sign_in/google_sign_in_android/pigeons/messages.dart b/packages/google_sign_in/google_sign_in_android/pigeons/messages.dart index e241e2115552..cdb92ea3337e 100644 --- a/packages/google_sign_in/google_sign_in_android/pigeons/messages.dart +++ b/packages/google_sign_in/google_sign_in_android/pigeons/messages.dart @@ -33,6 +33,7 @@ class InitParams { this.clientId, this.serverClientId, this.forceCodeForRefreshToken = false, + this.forceAccountName, }); final List scopes; @@ -41,6 +42,7 @@ class InitParams { final String? clientId; final String? serverClientId; final bool forceCodeForRefreshToken; + final String? forceAccountName; } /// Pigeon version of GoogleSignInUserData. 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 24e1f19973c7..3d7ff26c263f 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/packages/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: 6.1.35 +version: 6.2.0 environment: sdk: ^3.5.0 @@ -39,3 +39,8 @@ topics: false_secrets: - /example/android/app/google-services.json - /example/lib/main.dart + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins +dependency_overrides: + {google_sign_in_platform_interface: {path: ../../../packages/google_sign_in/google_sign_in_platform_interface}} 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 e53b9a8f546b..20cfb6a746e0 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 @@ -143,6 +143,7 @@ void main() { clientId: 'fakeClientId', serverClientId: 'fakeServerClientId', forceCodeForRefreshToken: true, + forceAccountName: 'fakeEmailAddress@example.com', ); await googleSignIn.initWithParams(initParams); @@ -156,6 +157,7 @@ void main() { expect(passedParams.serverClientId, initParams.serverClientId); expect(passedParams.forceCodeForRefreshToken, initParams.forceCodeForRefreshToken); + expect(passedParams.forceAccountName, initParams.forceAccountName); }); test('clearAuthCache passes arguments', () async { 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 15e309aa5749..ad6b725f944f 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.8.0+1 + +* Asserts that new `forceAccountName` parameter is null (not used in iOS). + ## 5.8.0 * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. diff --git a/packages/google_sign_in/google_sign_in_ios/example/pubspec.yaml b/packages/google_sign_in/google_sign_in_ios/example/pubspec.yaml index 03c1172bde92..98071cf930c5 100644 --- a/packages/google_sign_in/google_sign_in_ios/example/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_ios/example/pubspec.yaml @@ -27,3 +27,8 @@ dev_dependencies: flutter: uses-material-design: true + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins +dependency_overrides: + {google_sign_in_platform_interface: {path: ../../../../packages/google_sign_in/google_sign_in_platform_interface}} 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 1ddaadfd759f..652ead516a00 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 @@ -46,6 +46,9 @@ class GoogleSignInIOS extends GoogleSignInPlatform { code: 'unsupported-options', message: 'Games sign in is not supported on iOS'); } + if (params.forceAccountName != null) { + throw ArgumentError('Force account name is not supported on iOS'); + } return _api.init(InitParams( scopes: params.scopes, hostedDomain: params.hostedDomain, 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 9c24833e5956..317688edc82e 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: iOS implementation of the google_sign_in plugin. repository: https://github.com/flutter/packages/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.8.0 +version: 5.8.0+1 environment: sdk: ^3.4.0 @@ -46,3 +46,8 @@ false_secrets: - /example/ios/Runner/Info.plist - /example/lib/main.dart - /example/macos/Runner/Info.plist + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins +dependency_overrides: + {google_sign_in_platform_interface: {path: ../../../packages/google_sign_in/google_sign_in_platform_interface}} 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 d76bc978fc72..bd9d473a320c 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 @@ -52,6 +52,21 @@ void main() { (PlatformException e) => e.code, 'code', 'unsupported-options'))); }); + test('init throws for forceAccountName', () async { + expect( + () => googleSignIn.initWithParams( + const SignInInitParameters( + hostedDomain: 'example.com', + clientId: 'fakeClientId', + forceAccountName: 'fakeEmailAddress@example.com', + ), + ), + throwsA(isInstanceOf().having( + (ArgumentError e) => e.message, + 'message', + 'Force account name is not supported on iOS'))); + }); + test('signInSilently transforms platform data to GoogleSignInUserData', () async { when(api.signInSilently()).thenAnswer((_) async => UserData( 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 fda470243542..987f6f2e1975 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,5 +1,6 @@ -## NEXT +## 2.5.0 +* Add a sign-in field to allow Android clients to explicitly specify an account name. This capability is only available within Android for the underlying libraries. * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. ## 2.4.5 diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart index 5c74450b4806..d9de482518ed 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart @@ -36,6 +36,7 @@ class SignInInitParameters { this.clientId, this.serverClientId, this.forceCodeForRefreshToken = false, + this.forceAccountName, }); /// The list of OAuth scope codes to request when signing in. @@ -78,6 +79,11 @@ class SignInInitParameters { /// /// This is only used on Android. final bool forceCodeForRefreshToken; + + /// Can be used to explicitly set an account name on the underlying platform sign-in API. + /// + /// This should only be set on Android; other platforms may assert. + final String? forceAccountName; } /// Holds information about the signed in user. 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 2581773c69df..d0156993eb38 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/packages/tree/main/packages/google_sign_i 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.4.5 +version: 2.5.0 environment: sdk: ^3.4.0 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 52e161969d1f..0dd0d245abf8 100644 --- a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 0.12.4+4 +* Asserts that new `forceAccountName` parameter is null (not used in web). * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. ## 0.12.4+3 diff --git a/packages/google_sign_in/google_sign_in_web/example/integration_test/google_sign_in_web_test.dart b/packages/google_sign_in/google_sign_in_web/example/integration_test/google_sign_in_web_test.dart index 1b5f11d2f9d2..88b69f26fb5d 100644 --- a/packages/google_sign_in/google_sign_in_web/example/integration_test/google_sign_in_web_test.dart +++ b/packages/google_sign_in/google_sign_in_web/example/integration_test/google_sign_in_web_test.dart @@ -107,6 +107,17 @@ void main() { }, throwsAssertionError); }); + testWidgets('asserts forceAccountName must be null', (_) async { + expect(() async { + await plugin.initWithParams( + const SignInInitParameters( + clientId: 'some-non-null-client-id', + forceAccountName: 'fakeEmailAddress@example.com', + ), + ); + }, throwsAssertionError); + }); + testWidgets('must be called for most of the API to work', (_) async { expect(() async { await plugin.signInSilently(); 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 81b6dd8bad3f..7875805adfc4 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 @@ -26,3 +26,8 @@ dev_dependencies: flutter: uses-material-design: true + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins +dependency_overrides: + {google_sign_in_platform_interface: {path: ../../../../packages/google_sign_in/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 a7ce3f43c6a0..e6d3abc9e585 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 @@ -155,6 +155,9 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { 'Check https://developers.google.com/identity/protocols/googlescopes ' 'for a list of valid OAuth 2.0 scopes.'); + assert(params.forceAccountName == null, + 'forceAccountName is not supported on Web.'); + _initCalled = Completer(); await _jsSdkLoadedFuture; 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 ef52f4f3e41c..de9f9ff8cf48 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/packages/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.12.4+3 +version: 0.12.4+4 environment: sdk: ^3.4.0 @@ -34,3 +34,8 @@ dev_dependencies: topics: - authentication - google-sign-in + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins +dependency_overrides: + {google_sign_in_platform_interface: {path: ../../../packages/google_sign_in/google_sign_in_platform_interface}}