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

Commit

Permalink
Add GoogleSignInParams
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold committed Apr 15, 2022
1 parent 5aba502 commit 178cfbb
Show file tree
Hide file tree
Showing 20 changed files with 145 additions and 119 deletions.
12 changes: 7 additions & 5 deletions packages/google_sign_in/google_sign_in/lib/google_sign_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,18 @@ class GoogleSignIn {
}

Future<void> _ensureInitialized() {
return _initialization ??= GoogleSignInPlatform.instance.init2(
return _initialization ??=
GoogleSignInPlatform.instance.initialize(GoogleSignInParams(
signInOption: signInOption,
scopes: scopes,
hostedDomain: hostedDomain,
clientId: clientId,
serverClientId: serverClientId,
)..catchError((dynamic _) {
// Invalidate initialization if it errors out.
_initialization = null;
});
))
..catchError((dynamic _) {
// Invalidate initialization if it errors out.
_initialization = null;
});
}

/// The most recently scheduled method call.
Expand Down
2 changes: 1 addition & 1 deletion packages/google_sign_in/google_sign_in/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies:
sdk: flutter
google_sign_in_android: ^6.0.0
google_sign_in_ios: ^5.2.5
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ class SignInDemoState extends State<SignInDemo> {
}

Future<void> _ensureInitialized() {
return _initialization ??= GoogleSignInPlatform.instance.init(
return _initialization ??=
GoogleSignInPlatform.instance.initialize(GoogleSignInParams(
scopes: <String>[
'email',
'https://www.googleapis.com/auth/contacts.readonly',
],
)..catchError((dynamic _) {
_initialization = null;
});
))
..catchError((dynamic _) {
_initialization = null;
});
}

void _setUser(GoogleSignInUserData? user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
google_sign_in_platform_interface: ^2.1.0
google_sign_in_platform_interface: ^2.2.0
http: ^0.13.0

dev_dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ flutter:
dependencies:
flutter:
sdk: flutter
google_sign_in_platform_interface: ^2.1.0
google_sign_in_platform_interface: ^2.2.0

dev_dependencies:
flutter_driver:
Expand Down
13 changes: 8 additions & 5 deletions packages/google_sign_in/google_sign_in_ios/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class SignInDemo extends StatefulWidget {
class SignInDemoState extends State<SignInDemo> {
GoogleSignInUserData? _currentUser;
String _contactText = '';
// Future that completes when `init` has completed on the sign in instance.
// Future that completes when `initialize` has completed on the sign in
// instance.
Future<void>? _initialization;

@override
Expand All @@ -39,14 +40,16 @@ class SignInDemoState extends State<SignInDemo> {
}

Future<void> _ensureInitialized() {
return _initialization ??= GoogleSignInPlatform.instance.init(
return _initialization ??=
GoogleSignInPlatform.instance.initialize(GoogleSignInParams(
scopes: <String>[
'email',
'https://www.googleapis.com/auth/contacts.readonly',
],
)..catchError((dynamic _) {
_initialization = null;
});
))
..catchError((dynamic _) {
_initialization = null;
});
}

void _setUser(GoogleSignInUserData? user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
google_sign_in_platform_interface: ^2.1.0
google_sign_in_platform_interface: ^2.2.0
http: ^0.13.0

dev_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion packages/google_sign_in/google_sign_in_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ flutter:
dependencies:
flutter:
sdk: flutter
google_sign_in_platform_interface: ^2.1.0
google_sign_in_platform_interface: ^2.2.0

dev_dependencies:
flutter_driver:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Next
## 2.2.0

* Add `GoogleSignInPlatform.init2` and deprecate `GoogleSignInPlatform.init` to support the
`serverClientId` parameter.
* Add `GoogleSignInPlatform.initialize` and deprecate `GoogleSignInPlatform.init`.
* Add support for the `serverClientId` parameter.

## 2.1.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ abstract class GoogleSignInPlatform {
/// methods.
///
/// This method is deprecated and will be removed in the future.
/// Use [init2] instead.
/// Use [initialize] instead.
///
/// The [hostedDomain] argument specifies a hosted domain restriction. By
/// setting this, sign in will be restricted to accounts of the user in the
Expand All @@ -94,33 +94,12 @@ abstract class GoogleSignInPlatform {

/// 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: <https://developers.google.com/identity/protocols/googlescopes>
///
/// The [signInOption] determines the user experience. [SigninOption.games] is
/// only supported on Android.
///
/// See:
/// https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams
Future<void> init2({
List<String> scopes = const <String>[],
SignInOption signInOption = SignInOption.standard,
String? hostedDomain,
String? clientId,
String? serverClientId,
}) async {
Future<void> initialize(GoogleSignInParams params) async {
return init(
scopes: scopes,
signInOption: signInOption,
hostedDomain: hostedDomain,
clientId: clientId,
scopes: params.scopes,
signInOption: params.signInOption,
hostedDomain: params.hostedDomain,
clientId: params.clientId,
);
}

Expand All @@ -129,7 +108,7 @@ abstract class GoogleSignInPlatform {
throw UnimplementedError('signInSilently() has not been implemented.');
}

/// Signs in the user with the options specified to [init].
/// Signs in the user with the options specified to [initialize].
Future<GoogleSignInUserData?> signIn() async {
throw UnimplementedError('signIn() has not been implemented.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,22 @@ class MethodChannelGoogleSignIn extends GoogleSignInPlatform {
String? hostedDomain,
String? clientId,
}) {
return init2(
return initialize(GoogleSignInParams(
scopes: scopes,
signInOption: signInOption,
hostedDomain: hostedDomain,
clientId: clientId,
);
));
}

@override
Future<void> init2({
List<String> scopes = const <String>[],
SignInOption signInOption = SignInOption.standard,
String? hostedDomain,
String? clientId,
String? serverClientId,
}) {
Future<void> initialize(GoogleSignInParams params) {
return channel.invokeMethod<void>('init', <String, dynamic>{
'signInOption': signInOption.toString(),
'scopes': scopes,
'hostedDomain': hostedDomain,
'clientId': clientId,
'serverClientId': serverClientId,
'signInOption': params.signInOption.toString(),
'scopes': params.scopes,
'hostedDomain': params.hostedDomain,
'clientId': params.clientId,
'serverClientId': params.serverClientId,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,42 @@ enum SignInOption {
games
}

/// Plugin parameters that are provided at initialization.
class GoogleSignInParams {
/// Uses the given data to construct an instance.
GoogleSignInParams({
this.scopes = const <String>[],
this.signInOption = SignInOption.standard,
this.hostedDomain,
this.clientId,
this.serverClientId,
});

/// The list of 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: <https://developers.google.com/identity/protocols/googlescopes>
final List<String> scopes;

/// Default configuration option to use when signing in.
///
/// [SigninOption.games] is only supported on Android.
final SignInOption signInOption;

/// The hosted domain to which user account are restricted.
///
/// 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.
final String? hostedDomain;

/// The OAuth client ID of the app.
final String? clientId;

/// The OAuth client ID of the backend server.
final String? serverClientId;
}

/// Holds information about the signed in user.
class GoogleSignInUserData {
/// Uses the given data to construct an instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/google_sign_in
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.2
version: 2.2.0

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ void main() {
'serverClientId': null,
}),
() {
googleSignIn.init2(
hostedDomain: 'example.com',
scopes: <String>['two', 'scopes'],
signInOption: SignInOption.games,
clientId: 'fakeClientId',
serverClientId: 'fakeServerClientId');
googleSignIn.initialize(GoogleSignInParams(
hostedDomain: 'example.com',
scopes: <String>['two', 'scopes'],
signInOption: SignInOption.games,
clientId: 'fakeClientId',
serverClientId: 'fakeServerClientId',
));
}: isMethodCall('init', arguments: <String, dynamic>{
'hostedDomain': 'example.com',
'scopes': <String>['two', 'scopes'],
Expand Down
2 changes: 1 addition & 1 deletion packages/google_sign_in/google_sign_in_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Next

* Adapt to changed signature of `GoogleSignInPlatform.init2`.
* Migrate to new `GoogleSignInPlatform.initialize` method.

## 0.10.1

Expand Down
Loading

0 comments on commit 178cfbb

Please sign in to comment.