From 3d2f2ba659139bd1e3bbcb21adf19e66dc332c6d Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Tue, 14 Mar 2023 20:57:56 -0700 Subject: [PATCH 1/4] [gsi_interface] Introduces 'canAccessScopes' and 'userDataEvents'. --- .../CHANGELOG.md | 3 ++- .../google_sign_in_platform_interface.dart | 18 ++++++++++++++++++ .../pubspec.yaml | 2 +- .../method_channel_google_sign_in_test.dart | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+), 2 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 c3a7366d193..0de7f66bbbb 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,5 +1,6 @@ -## NEXT +## 2.4.0 +* Introduces: `canAccessScopes` method and `userDataEvents` stream. * Updates minimum Flutter version to 3.3. * Aligns Dart and Flutter SDK constraints. 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 64fc88d4866..9b9f932ab32 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 @@ -139,4 +139,22 @@ abstract class GoogleSignInPlatform extends PlatformInterface { Future requestScopes(List scopes) async { throw UnimplementedError('requestScopes() has not been implmented.'); } + + /// Determines if the current user can access all [scopes]. + /// + /// Optionally, an [accessToken] can be passed for applications where a + /// long-lived token may be cached (like the web). + Future canAccessScopes( + List scopes, { + String? accessToken, + }) async { + return isSignedIn(); + } + + /// Returns a stream of [GoogleSignInUserData] authentication events. + /// + /// These will normally come from asynchronous flows, like the Google Sign-In + /// Button Widget from the Web implementation, and will be funneled directly + /// to the `onCurrentUserChanged` Stream of the plugin. + Stream? get userDataEvents => null; } 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 17645aa9ad4..2e705919fc7 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/packages/tree/main/packages/google_sign_i 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.3.1 +version: 2.3.2 environment: sdk: ">=2.18.0 <4.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 0837f6d5d02..e501b9217cb 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 @@ -141,6 +141,25 @@ void main() { expect(log, tests.values); }); + test('canAccessScopes is the same as isSignedIn', () async { + await googleSignIn.canAccessScopes(['someScope']); + expect(log, [ + isMethodCall('isSignedIn', arguments: null), + ]); + }); + + test('canAccessScopes can accept an optional accessToken', () async { + await googleSignIn + .canAccessScopes(['someScope'], accessToken: 'token'); + expect(log, [ + isMethodCall('isSignedIn', arguments: null), + ]); + }); + + test('userDataEvents returns null', () async { + expect(googleSignIn.userDataEvents, isNull); + }); + test('initWithParams passes through arguments to the channel', () async { await googleSignIn.initWithParams(const SignInInitParameters( hostedDomain: 'example.com', From 0e3d9b5c55635b4074f28aabef5a312e94783f79 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Mon, 3 Apr 2023 13:44:18 -0700 Subject: [PATCH 2/4] CHANGELOG and pubspec.yaml --- .../google_sign_in_platform_interface/CHANGELOG.md | 2 ++ .../google_sign_in_platform_interface/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) 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 0de7f66bbbb..fff5d10e508 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,8 @@ ## 2.4.0 * Introduces: `canAccessScopes` method and `userDataEvents` stream. + * These enable separation of Authentication and Authorization, and asynchronous + sign-in operations where needed (on the web, for example!) * Updates minimum Flutter version to 3.3. * Aligns Dart and Flutter SDK constraints. 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 2e705919fc7..8b9af5a424e 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/packages/tree/main/packages/google_sign_i 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.3.2 +version: 2.4.0 environment: sdk: ">=2.18.0 <4.0.0" From 2c7dd5591678158ca11d85b4649b308f98b97637 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Mon, 3 Apr 2023 16:02:42 -0700 Subject: [PATCH 3/4] Address PR comments. --- .../lib/google_sign_in_platform_interface.dart | 2 +- .../method_channel_google_sign_in_test.dart | 18 +++++------------- 2 files changed, 6 insertions(+), 14 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 9b9f932ab32..f54d8bd6f5f 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 @@ -148,7 +148,7 @@ abstract class GoogleSignInPlatform extends PlatformInterface { List scopes, { String? accessToken, }) async { - return isSignedIn(); + throw UnimplementedError('canAccessScopes() has not been implmented.'); } /// Returns a stream of [GoogleSignInUserData] authentication events. 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 e501b9217cb..ac8b8ef20aa 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 @@ -141,19 +141,11 @@ void main() { expect(log, tests.values); }); - test('canAccessScopes is the same as isSignedIn', () async { - await googleSignIn.canAccessScopes(['someScope']); - expect(log, [ - isMethodCall('isSignedIn', arguments: null), - ]); - }); - - test('canAccessScopes can accept an optional accessToken', () async { - await googleSignIn - .canAccessScopes(['someScope'], accessToken: 'token'); - expect(log, [ - isMethodCall('isSignedIn', arguments: null), - ]); + test('canAccessScopes is unimplemented', () async { + expect(() async { + await googleSignIn + .canAccessScopes(['someScope'], accessToken: 'token'); + }, throwsUnimplementedError); }); test('userDataEvents returns null', () async { From 1d7c9212d91722203c47e5100259ef81f0d635a4 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Tue, 4 Apr 2023 12:34:03 -0700 Subject: [PATCH 4/4] Fix 'implemented' typo. --- .../lib/google_sign_in_platform_interface.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 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 f54d8bd6f5f..579d0f4c3c3 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 @@ -137,7 +137,7 @@ abstract class GoogleSignInPlatform extends PlatformInterface { /// Scopes should come from the full list /// [here](https://developers.google.com/identity/protocols/googlescopes). Future requestScopes(List scopes) async { - throw UnimplementedError('requestScopes() has not been implmented.'); + throw UnimplementedError('requestScopes() has not been implemented.'); } /// Determines if the current user can access all [scopes]. @@ -148,7 +148,7 @@ abstract class GoogleSignInPlatform extends PlatformInterface { List scopes, { String? accessToken, }) async { - throw UnimplementedError('canAccessScopes() has not been implmented.'); + throw UnimplementedError('canAccessScopes() has not been implemented.'); } /// Returns a stream of [GoogleSignInUserData] authentication events.