Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit c1be520

Browse files
committed
[google_sign_in_platform_interface] Add support for serverClientId
1 parent d945080 commit c1be520

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.2.0
2+
3+
* Add `GoogleSignInPlatform.init2` and deprecate `GoogleSignInPlatform.init` to support the
4+
`serverClientId` parameter.
5+
16
## 2.1.2
27

38
* Internal code cleanup for stricter analysis options.

packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ abstract class GoogleSignInPlatform {
6666
/// Initializes the plugin. You must call this method before calling other
6767
/// methods.
6868
///
69+
/// This method is deprecated and will be removed in the future.
70+
/// Use [init2] instead.
71+
///
6972
/// The [hostedDomain] argument specifies a hosted domain restriction. By
7073
/// setting this, sign in will be restricted to accounts of the user in the
7174
/// specified domain. By default, the list of accounts will not be restricted.
@@ -89,6 +92,38 @@ abstract class GoogleSignInPlatform {
8992
throw UnimplementedError('init() has not been implemented.');
9093
}
9194

95+
/// Initializes the plugin. You must call this method before calling other
96+
/// methods.
97+
///
98+
/// The [hostedDomain] argument specifies a hosted domain restriction. By
99+
/// setting this, sign in will be restricted to accounts of the user in the
100+
/// specified domain. By default, the list of accounts will not be restricted.
101+
///
102+
/// The list of [scopes] are OAuth scope codes to request when signing in.
103+
/// These scope codes will determine the level of data access that is granted
104+
/// to your application by the user. The full list of available scopes can be
105+
/// found here: <https://developers.google.com/identity/protocols/googlescopes>
106+
///
107+
/// The [signInOption] determines the user experience. [SigninOption.games] is
108+
/// only supported on Android.
109+
///
110+
/// See:
111+
/// https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams
112+
Future<void> init2({
113+
List<String> scopes = const <String>[],
114+
SignInOption signInOption = SignInOption.standard,
115+
String? hostedDomain,
116+
String? clientId,
117+
String? serverClientId,
118+
}) async {
119+
return init(
120+
scopes: scopes,
121+
signInOption: signInOption,
122+
hostedDomain: hostedDomain,
123+
clientId: clientId,
124+
);
125+
}
126+
92127
/// Attempts to reuse pre-existing credentials to sign in again, without user interaction.
93128
Future<GoogleSignInUserData?> signInSilently() async {
94129
throw UnimplementedError('signInSilently() has not been implemented.');

packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,29 @@ class MethodChannelGoogleSignIn extends GoogleSignInPlatform {
2525
SignInOption signInOption = SignInOption.standard,
2626
String? hostedDomain,
2727
String? clientId,
28+
}) {
29+
return init2(
30+
scopes: scopes,
31+
signInOption: signInOption,
32+
hostedDomain: hostedDomain,
33+
clientId: clientId,
34+
);
35+
}
36+
37+
@override
38+
Future<void> init2({
39+
List<String> scopes = const <String>[],
40+
SignInOption signInOption = SignInOption.standard,
41+
String? hostedDomain,
42+
String? clientId,
43+
String? serverClientId,
2844
}) {
2945
return channel.invokeMethod<void>('init', <String, dynamic>{
3046
'signInOption': signInOption.toString(),
3147
'scopes': scopes,
3248
'hostedDomain': hostedDomain,
3349
'clientId': clientId,
50+
'serverClientId': serverClientId,
3451
});
3552
}
3653

packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/google_sign_in
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.1.2
7+
version: 2.2.0
88

99
environment:
1010
sdk: ">=2.12.0 <3.0.0"

packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ void main() {
108108
'scopes': <String>['two', 'scopes'],
109109
'signInOption': 'SignInOption.games',
110110
'clientId': 'fakeClientId',
111+
'serverClientId': null,
112+
}),
113+
() {
114+
googleSignIn.init2(
115+
hostedDomain: 'example.com',
116+
scopes: <String>['two', 'scopes'],
117+
signInOption: SignInOption.games,
118+
clientId: 'fakeClientId',
119+
serverClientId: 'fakeServerClientId');
120+
}: isMethodCall('init', arguments: <String, dynamic>{
121+
'hostedDomain': 'example.com',
122+
'scopes': <String>['two', 'scopes'],
123+
'signInOption': 'SignInOption.games',
124+
'clientId': 'fakeClientId',
125+
'serverClientId': 'fakeServerClientId',
111126
}),
112127
() {
113128
googleSignIn.getTokens(

0 commit comments

Comments
 (0)