diff --git a/packages/google_sign_in/google_sign_in_platform_interface/AUTHORS b/packages/google_sign_in/google_sign_in_platform_interface/AUTHORS index 493a0b4ef9c2..35d24a5ae0b5 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/AUTHORS +++ b/packages/google_sign_in/google_sign_in_platform_interface/AUTHORS @@ -64,3 +64,4 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> +Twin Sun, LLC 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 da214d3ce6a9..abf01c847d83 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,6 +1,7 @@ -## NEXT +## 2.1.3 * Removes unnecessary imports. +* Adds `SignInInitParameters` class to hold all sign in params, including the new `forceCodeForRefreshToken`. ## 2.1.2 diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart index 50f261bfa578..69d8455b6bd2 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/google_sign_in_platform_interface.dart @@ -63,8 +63,7 @@ abstract class GoogleSignInPlatform { /// if the provided instance is a class implemented with `implements`. void _verifyProvidesDefaultImplementations() {} - /// Initializes the plugin. You must call this method before calling other - /// methods. + /// Initializes the plugin. Deprecated: call [initWithParams] instead. /// /// The [hostedDomain] argument specifies a hosted domain restriction. By /// setting this, sign in will be restricted to accounts of the user in the @@ -89,6 +88,21 @@ abstract class GoogleSignInPlatform { throw UnimplementedError('init() has not been implemented.'); } + /// Initializes the plugin with specified [params]. You must call this method + /// before calling other methods. + /// + /// See: + /// + /// * [SignInInitParameters] + Future initWithParams(SignInInitParameters params) async { + await init( + scopes: params.scopes, + signInOption: params.signInOption, + hostedDomain: params.hostedDomain, + clientId: params.clientId, + ); + } + /// Attempts to reuse pre-existing credentials to sign in again, without user interaction. Future signInSilently() async { throw UnimplementedError('signInSilently() has not been implemented.'); diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart index e56d2028a205..8b755fbf1cdd 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/method_channel_google_sign_in.dart @@ -25,11 +25,21 @@ class MethodChannelGoogleSignIn extends GoogleSignInPlatform { String? hostedDomain, String? clientId, }) { + return initWithParams(SignInInitParameters( + scopes: scopes, + signInOption: signInOption, + hostedDomain: hostedDomain, + clientId: clientId)); + } + + @override + Future initWithParams(SignInInitParameters params) { return channel.invokeMethod('init', { - 'signInOption': signInOption.toString(), - 'scopes': scopes, - 'hostedDomain': hostedDomain, - 'clientId': clientId, + 'signInOption': params.signInOption.toString(), + 'scopes': params.scopes, + 'hostedDomain': params.hostedDomain, + 'clientId': params.clientId, + 'forceCodeForRefreshToken': params.forceCodeForRefreshToken, }); } 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 bc50a1d2516d..2cac5e886729 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 @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/widgets.dart'; import 'package:quiver/core.dart'; /// Default configuration options to use when signing in. @@ -22,6 +23,42 @@ enum SignInOption { games } +/// The parameters to use when initializing the sign in process. +/// +/// See: +/// https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams +@immutable +class SignInInitParameters { + /// The parameters to use when initializing the sign in process. + const SignInInitParameters({ + this.scopes = const [], + this.signInOption = SignInOption.standard, + this.hostedDomain, + this.clientId, + this.forceCodeForRefreshToken = false, + }); + + /// The list of OAuth scope codes to request when signing in. + final List scopes; + + /// The user experience to use when signing in. [SignInOption.games] is + /// only supported on Android. + final SignInOption signInOption; + + /// Restricts sign in to accounts of the user in the specified domain. + /// By default, the list of accounts will not be restricted. + final String? hostedDomain; + + /// The client ID to use when signing in. + final String? clientId; + + /// If true, ensures the authorization code can be exchanged for an access + /// token. + /// + /// This is only used on Android. + final bool forceCodeForRefreshToken; +} + /// Holds information about the signed in user. class GoogleSignInUserData { /// Uses the given data to construct an instance. 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 a5bbaedd51e7..0deafe80a863 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/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.1.3 environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart b/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart index b6604d1e658e..1ffdc5a4f95e 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/test/method_channel_google_sign_in_test.dart @@ -107,6 +107,7 @@ void main() { 'scopes': ['two', 'scopes'], 'signInOption': 'SignInOption.games', 'clientId': 'fakeClientId', + 'forceCodeForRefreshToken': false, }), () { googleSignIn.getTokens( @@ -136,5 +137,23 @@ void main() { expect(log, tests.values); }); + + test('initWithParams passes through arguments to the channel', () async { + await googleSignIn.initWithParams(const SignInInitParameters( + hostedDomain: 'example.com', + scopes: ['two', 'scopes'], + signInOption: SignInOption.games, + clientId: 'fakeClientId', + forceCodeForRefreshToken: true)); + expect(log, [ + isMethodCall('init', arguments: { + 'hostedDomain': 'example.com', + 'scopes': ['two', 'scopes'], + 'signInOption': 'SignInOption.games', + 'clientId': 'fakeClientId', + 'forceCodeForRefreshToken': true, + }), + ]); + }); }); }