Skip to content

Commit 2d3b24e

Browse files
authored
[google_sign_in] Add Android account name field as optional (#8573)
The underlying Android library for google_sign_in allows for explicitly specifying an account name, but google_sign_in doesn't have a passthrough field for this. Android clients who want to use this functionality through google_sign_in are unable. This PR would remedy this by adding a passthrough field to expose this functionality. Flutter issue: [163257](flutter/flutter#163257)
1 parent faa4ad4 commit 2d3b24e

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

packages/google_sign_in/google_sign_in/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## NEXT
1+
## 6.3.0
22

3+
* Adds a sign-in field to allow Android clients to explicitly specify an account name. This
4+
capability is only available within Android for the underlying libraries.
35
* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
46

57
## 6.2.2

packages/google_sign_in/google_sign_in/lib/google_sign_in.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class GoogleSignIn {
187187
this.clientId,
188188
this.serverClientId,
189189
this.forceCodeForRefreshToken = false,
190+
this.forceAccountName,
190191
}) {
191192
// Start initializing.
192193
if (kIsWeb) {
@@ -263,6 +264,9 @@ class GoogleSignIn {
263264
/// Force the authorization code to be valid for a refresh token every time. Only needed on Android.
264265
final bool forceCodeForRefreshToken;
265266

267+
/// Explicitly specifies the account name to be used in sign-in. Must only be set on Android.
268+
final String? forceAccountName;
269+
266270
final StreamController<GoogleSignInAccount?> _currentUserController =
267271
StreamController<GoogleSignInAccount?>.broadcast();
268272

@@ -317,6 +321,7 @@ class GoogleSignIn {
317321
clientId: clientId,
318322
serverClientId: serverClientId,
319323
forceCodeForRefreshToken: forceCodeForRefreshToken,
324+
forceAccountName: forceAccountName,
320325
));
321326

322327
unawaited(GoogleSignInPlatform.instance.userDataEvents

packages/google_sign_in/google_sign_in/pubspec.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ description: Flutter plugin for Google Sign-In, a secure authentication system
33
for signing in with a Google account.
44
repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
6-
version: 6.2.2
6+
version: 6.3.0
77

88
environment:
9-
sdk: ^3.4.0
10-
flutter: ">=3.22.0"
9+
sdk: ^3.6.0
10+
flutter: ">=3.27.0"
1111

1212
flutter:
1313
plugin:
@@ -24,10 +24,10 @@ flutter:
2424
dependencies:
2525
flutter:
2626
sdk: flutter
27-
google_sign_in_android: ^6.1.0
28-
google_sign_in_ios: ^5.7.0
29-
google_sign_in_platform_interface: ^2.4.0
30-
google_sign_in_web: ^0.12.0
27+
google_sign_in_android: ^6.2.0
28+
google_sign_in_ios: ^5.8.1
29+
google_sign_in_platform_interface: ^2.5.0
30+
google_sign_in_web: ^0.12.4+4
3131

3232
dev_dependencies:
3333
build_runner: ^2.1.10

packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ void main() {
113113
verify(mockPlatform.signIn());
114114
});
115115

116+
test('forceAccountName sent with init method call', () async {
117+
final GoogleSignIn googleSignIn =
118+
GoogleSignIn(forceAccountName: '[email protected]');
119+
120+
await googleSignIn.signIn();
121+
122+
_verifyInit(mockPlatform,
123+
forceAccountName: '[email protected]');
124+
verify(mockPlatform.signIn());
125+
});
126+
116127
test('signOut', () async {
117128
final GoogleSignIn googleSignIn = GoogleSignIn();
118129

@@ -447,6 +458,7 @@ void _verifyInit(
447458
String? clientId,
448459
String? serverClientId,
449460
bool forceCodeForRefreshToken = false,
461+
String? forceAccountName,
450462
}) {
451463
verify(mockSignIn.initWithParams(argThat(
452464
isA<SignInInitParameters>()
@@ -479,6 +491,11 @@ void _verifyInit(
479491
(SignInInitParameters p) => p.forceCodeForRefreshToken,
480492
'forceCodeForRefreshToken',
481493
forceCodeForRefreshToken,
494+
)
495+
.having(
496+
(SignInInitParameters p) => p.forceAccountName,
497+
'forceAccountName',
498+
forceAccountName,
482499
),
483500
)));
484501
}

0 commit comments

Comments
 (0)