From 30014b9497113b6d922abe4814522ca9fdd1deca Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Thu, 21 Apr 2022 20:27:32 -0500 Subject: [PATCH 1/6] [force-code-for-refresh-token-platform-interface] Add new SignInInitParameters object --- .../CHANGELOG.md | 3 +- .../google_sign_in_platform_interface.dart | 22 ++++++++- .../src/method_channel_google_sign_in.dart | 21 ++++++-- .../lib/src/types.dart | 49 +++++++++++++++++++ .../pubspec.yaml | 2 +- .../method_channel_google_sign_in_test.dart | 20 ++++++++ 6 files changed, 110 insertions(+), 7 deletions(-) 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..9137a43f4ef4 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. +* Add `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..640889e3f8bf 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 @@ -86,7 +86,27 @@ abstract class GoogleSignInPlatform { String? hostedDomain, String? clientId, }) async { - throw UnimplementedError('init() has not been implemented.'); + await initWithParams( + SignInInitParameters( + scopes: scopes, + signInOption: signInOption, + hostedDomain: hostedDomain, + clientId: clientId, + ), + ); + } + + /// Initializes the plugin. You must call this method before calling other + /// methods. + /// + /// The [params] argument specifies the parameters that will be used to + /// initialize the plugin. + /// + /// See: + /// + /// * [SignInInitParameters] + Future initWithParams(SignInInitParameters params) async { + throw UnimplementedError('initWithParams() has not been implemented'); } /// Attempts to reuse pre-existing credentials to sign in again, without user interaction. 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..f469b7146309 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,24 @@ 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..a8e683be5820 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 @@ -22,6 +22,55 @@ enum SignInOption { games } +/// The parameters to use when initializing the sign in process. +/// +/// 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: +/// +/// The [signInOption] determines the user experience. [SigninOption.games] is +/// only supported on Android. +/// +/// The [forceCodeForRefreshToken] is used on Android to ensure the authentication +/// code can be exchanged for a refresh token after the first request. +/// +/// See: +/// https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams +class SignInInitParameters { + /// The parameters to use when initializing the sign in process. + 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. + List scopes; + + /// The user experience to use when signing in. [SignInOption.games] is + /// only supported on Android. + SignInOption signInOption; + + /// Restricted sign in to accounts of the user in the specified domain. + /// By default, the list of accounts will not be restricted. + String? hostedDomain; + + /// The client ID to use when signing in. + String? clientId; + + /// Ensure the authorization code can be exchanged for an access token. + /// + /// This is only used on Android. + 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..f609cdc428af 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,24 @@ void main() { expect(log, tests.values); }); + + test('initWithParams passes through arguments to the channel', () async { + await googleSignIn.initWithParams( + 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, + }), + ]); + }); }); } From 661fd9d496b5ec9b2e50b5206e966b31b7fd7808 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Thu, 21 Apr 2022 20:37:13 -0500 Subject: [PATCH 2/6] [force-code-for-refresh-token-platform-interface] Use dart format --- .../test/method_channel_google_sign_in_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f609cdc428af..a9a3e13b7cb8 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 @@ -154,7 +154,7 @@ void main() { 'clientId': 'fakeClientId', 'forceCodeForRefreshToken': true, }), - ]); + ]); }); }); } From efd18a58f02923117d9b2ccdeea008cd1f986e8b Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Thu, 21 Apr 2022 20:43:54 -0500 Subject: [PATCH 3/6] [force-code-for-refresh-token-platform-interface] Fix dart format errors --- .../lib/src/method_channel_google_sign_in.dart | 7 ++----- .../test/method_channel_google_sign_in_test.dart | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) 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 f469b7146309..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,14 +25,11 @@ class MethodChannelGoogleSignIn extends GoogleSignInPlatform { String? hostedDomain, String? clientId, }) { - return initWithParams( - SignInInitParameters( + return initWithParams(SignInInitParameters( scopes: scopes, signInOption: signInOption, hostedDomain: hostedDomain, - clientId: clientId - ) - ); + clientId: clientId)); } @override 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 a9a3e13b7cb8..58ba1251b8b3 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 @@ -139,8 +139,7 @@ void main() { }); test('initWithParams passes through arguments to the channel', () async { - await googleSignIn.initWithParams( - SignInInitParameters( + await googleSignIn.initWithParams(SignInInitParameters( hostedDomain: 'example.com', scopes: ['two', 'scopes'], signInOption: SignInOption.games, From 3699c23d955cb0e4aceb3b2709e4e60f1a3f272f Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Wed, 27 Apr 2022 13:24:32 -0500 Subject: [PATCH 4/6] [force-code-for-refresh-token-platform-interface] Address PR feedback --- .../google_sign_in_platform_interface/AUTHORS | 1 + .../CHANGELOG.md | 2 +- .../google_sign_in_platform_interface.dart | 16 ++++----- .../lib/src/types.dart | 34 ++++++------------- .../method_channel_google_sign_in_test.dart | 2 +- 5 files changed, 21 insertions(+), 34 deletions(-) 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 9137a43f4ef4..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,7 +1,7 @@ ## 2.1.3 * Removes unnecessary imports. -* Add `SignInInitParameters` class to hold all sign in params, including the new `forceCodeForRefreshToken`. +* 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 640889e3f8bf..dd8baa0eed9f 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 @@ -86,14 +86,7 @@ abstract class GoogleSignInPlatform { String? hostedDomain, String? clientId, }) async { - await initWithParams( - SignInInitParameters( - scopes: scopes, - signInOption: signInOption, - hostedDomain: hostedDomain, - clientId: clientId, - ), - ); + throw UnimplementedError('init() has not been implemented.'); } /// Initializes the plugin. You must call this method before calling other @@ -106,7 +99,12 @@ abstract class GoogleSignInPlatform { /// /// * [SignInInitParameters] Future initWithParams(SignInInitParameters params) async { - throw UnimplementedError('initWithParams() has not been implemented'); + 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. 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 a8e683be5820..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. @@ -24,26 +25,12 @@ enum SignInOption { /// The parameters to use when initializing the sign in process. /// -/// 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: -/// -/// The [signInOption] determines the user experience. [SigninOption.games] is -/// only supported on Android. -/// -/// The [forceCodeForRefreshToken] is used on Android to ensure the authentication -/// code can be exchanged for a refresh token after the first request. -/// /// See: /// https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams +@immutable class SignInInitParameters { /// The parameters to use when initializing the sign in process. - SignInInitParameters({ + const SignInInitParameters({ this.scopes = const [], this.signInOption = SignInOption.standard, this.hostedDomain, @@ -52,23 +39,24 @@ class SignInInitParameters { }); /// The list of OAuth scope codes to request when signing in. - List scopes; + final List scopes; /// The user experience to use when signing in. [SignInOption.games] is /// only supported on Android. - SignInOption signInOption; + final SignInOption signInOption; - /// Restricted sign in to accounts of the user in the specified domain. + /// Restricts sign in to accounts of the user in the specified domain. /// By default, the list of accounts will not be restricted. - String? hostedDomain; + final String? hostedDomain; /// The client ID to use when signing in. - String? clientId; + final String? clientId; - /// Ensure the authorization code can be exchanged for an access token. + /// If true, ensures the authorization code can be exchanged for an access + /// token. /// /// This is only used on Android. - bool forceCodeForRefreshToken; + final bool forceCodeForRefreshToken; } /// Holds information about the signed in user. 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 58ba1251b8b3..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 @@ -139,7 +139,7 @@ void main() { }); test('initWithParams passes through arguments to the channel', () async { - await googleSignIn.initWithParams(SignInInitParameters( + await googleSignIn.initWithParams(const SignInInitParameters( hostedDomain: 'example.com', scopes: ['two', 'scopes'], signInOption: SignInOption.games, From ae071af5b62c7d1b17afd7ee88251256eabda477 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Tue, 10 May 2022 20:20:03 -0500 Subject: [PATCH 5/6] [force-code-for-refresh-token-platform-interface] Adjust comments per PR feedback --- .../lib/google_sign_in_platform_interface.dart | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 dd8baa0eed9f..3a18d099a1c6 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,8 +88,8 @@ abstract class GoogleSignInPlatform { throw UnimplementedError('init() has not been implemented.'); } - /// Initializes the plugin. You must call this method before calling other - /// methods. + /// Initializes the plugin with [params]. You must call this method before + /// calling other methods. /// /// The [params] argument specifies the parameters that will be used to /// initialize the plugin. From 56af573cdabf1be4baf6d12b6dc52d696afa1c87 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Tue, 10 May 2022 20:24:10 -0500 Subject: [PATCH 6/6] [force-code-for-refresh-token-platform-interface] One more update to comments --- .../lib/google_sign_in_platform_interface.dart | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 3a18d099a1c6..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 @@ -88,11 +88,8 @@ abstract class GoogleSignInPlatform { throw UnimplementedError('init() has not been implemented.'); } - /// Initializes the plugin with [params]. You must call this method before - /// calling other methods. - /// - /// The [params] argument specifies the parameters that will be used to - /// initialize the plugin. + /// Initializes the plugin with specified [params]. You must call this method + /// before calling other methods. /// /// See: ///