Skip to content

Commit

Permalink
Merge branch 'android_account_name' of ../flutter into android_accoun…
Browse files Browse the repository at this point in the history
…t_name
  • Loading branch information
neilself committed Feb 5, 2025
2 parents 97b6074 + bdfe492 commit bedfeeb
Show file tree
Hide file tree
Showing 30 changed files with 280 additions and 154 deletions.
3 changes: 2 additions & 1 deletion packages/google_sign_in/google_sign_in/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 6.3.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.

## 6.2.2
Expand Down
5 changes: 5 additions & 0 deletions packages/google_sign_in/google_sign_in/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class GoogleSignIn {
this.clientId,
this.serverClientId,
this.forceCodeForRefreshToken = false,
this.forceAccountName,
}) {
// Start initializing.
if (kIsWeb) {
Expand Down Expand Up @@ -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. Only used on Android.
final String? forceAccountName;

final StreamController<GoogleSignInAccount?> _currentUserController =
StreamController<GoogleSignInAccount?>.broadcast();

Expand Down Expand Up @@ -317,6 +321,7 @@ class GoogleSignIn {
clientId: clientId,
serverClientId: serverClientId,
forceCodeForRefreshToken: forceCodeForRefreshToken,
forceAccountName: forceAccountName,
));

unawaited(GoogleSignInPlatform.instance.userDataEvents
Expand Down
7 changes: 6 additions & 1 deletion packages/google_sign_in/google_sign_in/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ void main() {
verify(mockPlatform.signIn());
});

test('forceAccountName sent with init method call', () async {
final GoogleSignIn googleSignIn =
GoogleSignIn(forceAccountName: '[email protected]');

await googleSignIn.signIn();

_verifyInit(mockPlatform,
forceAccountName: '[email protected]');
verify(mockPlatform.signIn());
});

test('signOut', () async {
final GoogleSignIn googleSignIn = GoogleSignIn();

Expand Down Expand Up @@ -447,6 +458,7 @@ void _verifyInit(
String? clientId,
String? serverClientId,
bool forceCodeForRefreshToken = false,
String? forceAccountName,
}) {
verify(mockSignIn.initWithParams(argThat(
isA<SignInInitParameters>()
Expand Down Expand Up @@ -479,6 +491,11 @@ void _verifyInit(
(SignInInitParameters p) => p.forceCodeForRefreshToken,
'forceCodeForRefreshToken',
forceCodeForRefreshToken,
)
.having(
(SignInInitParameters p) => p.forceAccountName,
'forceAccountName',
forceAccountName,
),
)));
}
4 changes: 4 additions & 0 deletions packages/google_sign_in/google_sign_in_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.2.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.

## 6.1.34

* Removes unnecessary native code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ public void init(@NonNull Messages.InitParams params) {
optionsBuilder.setHostedDomain(params.getHostedDomain());
}

String forceAccountName = params.getForceAccountName();
if (!Strings.isNullOrEmpty(forceAccountName)) {
optionsBuilder.setAccountName(forceAccountName);
}

signInClient = googleSignInWrapper.getClient(context, optionsBuilder.build());
} catch (Exception e) {
throw new FlutterError(ERROR_REASON_EXCEPTION, e.getMessage(), null);
Expand Down
Loading

0 comments on commit bedfeeb

Please sign in to comment.