From 143782a04cc4b5ef42986d401c12c6122cc3f230 Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Wed, 6 Nov 2024 16:40:54 -0800 Subject: [PATCH 1/6] Clear-up documentation of callbacks in various APIs and uses of those APIs These APIs used to accept allowInterop'd callbacks. When the implementation was migrated to use dart:js_interop, they were wrapped with toJS. However, starting in 3.5, to be consistent with dart2wasm, double-wrapping a function is an error. The documentation should be clear that it accepts only Dart functions and uses should be cleaned up to not use allowInterop and type the callbacks' parameter and return value correctly. --- packages/google_identity_services_web/CHANGELOG.md | 3 +++ .../integration_test/js_interop_oauth_test.dart | 10 +++++----- .../lib/src/js_interop/google_accounts_id.dart | 3 ++- .../lib/src/js_interop/google_accounts_oauth2.dart | 8 +++----- .../lib/src/js_interop/load_callback.dart | 3 +-- .../google_sign_in_web/lib/src/gis_client.dart | 8 ++++---- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/google_identity_services_web/CHANGELOG.md b/packages/google_identity_services_web/CHANGELOG.md index c9d0ddf7006c..c0cbb02780ef 100644 --- a/packages/google_identity_services_web/CHANGELOG.md +++ b/packages/google_identity_services_web/CHANGELOG.md @@ -5,6 +5,9 @@ ## 0.3.1+4 * Restores support for Dart `^3.3.0`. +* Clean up documentation of callbacks in `CodeClientConfig`, + `TokenClientConfig`, `onGoogleLibraryLoad`, and `revoke` to indicate they only + accept Dart functions and not JS functions. ## 0.3.1+3 diff --git a/packages/google_identity_services_web/example/integration_test/js_interop_oauth_test.dart b/packages/google_identity_services_web/example/integration_test/js_interop_oauth_test.dart index c197b1116dc6..cf243b0859e7 100644 --- a/packages/google_identity_services_web/example/integration_test/js_interop_oauth_test.dart +++ b/packages/google_identity_services_web/example/integration_test/js_interop_oauth_test.dart @@ -26,7 +26,7 @@ void main() async { testWidgets('TokenClientConfig', (_) async { final TokenClientConfig config = TokenClientConfig( client_id: 'testing_1-2-3', - callback: (_) {}, + callback: (TokenResponse _) {}, scope: ['one', 'two', 'three'], include_granted_scopes: true, prompt: 'some-prompt', @@ -34,7 +34,7 @@ void main() async { login_hint: 'login-hint@example.com', hd: 'hd_value', state: 'some-state', - error_callback: (_) {}, + error_callback: (GoogleIdentityServicesError? _) {}, ); final utils.ExpectConfigValueFn expectConfigValue = @@ -79,14 +79,14 @@ void main() async { scope: ['one', 'two', 'three'], include_granted_scopes: true, redirect_uri: Uri.parse('https://www.example.com/login'), - callback: (_) {}, + callback: (CodeResponse _) {}, state: 'some-state', enable_granular_consent: true, login_hint: 'login-hint@example.com', hd: 'hd_value', ux_mode: UxMode.popup, select_account: true, - error_callback: (_) {}, + error_callback: (GoogleIdentityServicesError? _) {}, ); final utils.ExpectConfigValueFn expectConfigValue = @@ -110,7 +110,7 @@ void main() async { testWidgets('returns a tokenClient', (_) async { final TokenClient client = oauth2.initTokenClient(TokenClientConfig( client_id: 'for-tests', - callback: (_) {}, + callback: (TokenResponse _) {}, scope: ['some_scope', 'for_tests', 'not_real'], )); diff --git a/packages/google_identity_services_web/lib/src/js_interop/google_accounts_id.dart b/packages/google_identity_services_web/lib/src/js_interop/google_accounts_id.dart index 8467854640e8..99bc70690a4a 100644 --- a/packages/google_identity_services_web/lib/src/js_interop/google_accounts_id.dart +++ b/packages/google_identity_services_web/lib/src/js_interop/google_accounts_id.dart @@ -164,7 +164,8 @@ extension GoogleAccountsIdExtension on GoogleAccountsId { /// ID is the `sub` property of the [CredentialResponse.credential] payload. /// /// The optional [callback] is a function that gets called to report on the - /// success of the revocation call. + /// success of the revocation call. It must be a Dart function and not a JS + /// function. /// /// Method: google.accounts.id.revoke /// https://developers.google.com/identity/gsi/web/reference/js-reference#google.accounts.id.revoke diff --git a/packages/google_identity_services_web/lib/src/js_interop/google_accounts_oauth2.dart b/packages/google_identity_services_web/lib/src/js_interop/google_accounts_oauth2.dart index 9c97ba43b6aa..723cc81423ca 100644 --- a/packages/google_identity_services_web/lib/src/js_interop/google_accounts_oauth2.dart +++ b/packages/google_identity_services_web/lib/src/js_interop/google_accounts_oauth2.dart @@ -73,7 +73,7 @@ extension GoogleAccountsOauth2Extension on GoogleAccountsOauth2 { /// A valid [accessToken] is required to revoke permissions. /// /// The [done] callback is called once the revoke action is done. It must be - /// manually wrapped in [allowInterop] before being passed to this method. + /// a Dart function and not a JS function. /// /// Method: google.accounts.oauth2.revoke /// https://developers.google.com/identity/oauth2/web/reference/js-reference#google.accounts.oauth2.revoke @@ -103,8 +103,7 @@ extension GoogleAccountsOauth2Extension on GoogleAccountsOauth2 { abstract class CodeClientConfig { /// Constructs a CodeClientConfig object in JavaScript. /// - /// The [callback] property must be wrapped in [allowInterop] before it's - /// passed to this constructor. + /// The [callback] property must be a Dart function and not a JS function. factory CodeClientConfig({ required String client_id, required List scope, @@ -230,8 +229,7 @@ typedef CodeClientCallbackFn = void Function(CodeResponse response); abstract class TokenClientConfig { /// Constructs a TokenClientConfig object in JavaScript. /// - /// The [callback] property must be wrapped in [allowInterop] before it's - /// passed to this constructor. + /// The [callback] property must be a Dart function and not a JS function. factory TokenClientConfig({ required String client_id, required TokenClientCallbackFn callback, diff --git a/packages/google_identity_services_web/lib/src/js_interop/load_callback.dart b/packages/google_identity_services_web/lib/src/js_interop/load_callback.dart index 7df615017f7f..23b08447b8b6 100644 --- a/packages/google_identity_services_web/lib/src/js_interop/load_callback.dart +++ b/packages/google_identity_services_web/lib/src/js_interop/load_callback.dart @@ -23,8 +23,7 @@ external set _onGoogleLibraryLoad(JSFunction callback); /// Method called after the Sign In With Google JavaScript library is loaded. /// -/// The [callback] parameter must be manually wrapped in [allowInterop] -/// before being set to the [onGoogleLibraryLoad] property. +/// The [function] parameter must be a Dart function and not a JS function. set onGoogleLibraryLoad(VoidFn function) { _onGoogleLibraryLoad = function.toJS; } diff --git a/packages/google_sign_in/google_sign_in_web/lib/src/gis_client.dart b/packages/google_sign_in/google_sign_in_web/lib/src/gis_client.dart index b28796b8d68f..421ce1a187fd 100644 --- a/packages/google_sign_in/google_sign_in_web/lib/src/gis_client.dart +++ b/packages/google_sign_in/google_sign_in_web/lib/src/gis_client.dart @@ -188,9 +188,9 @@ class GisSdkClient { // // Token clients have an additional `error_callback` for miscellaneous // errors, like "popup couldn't open" or "popup closed by user". - void _onTokenError(Object? error) { + void _onTokenError(GoogleIdentityServicesError? error) { if (error != null) { - _tokenResponses.addError((error as GoogleIdentityServicesError).type); + _tokenResponses.addError(error.type); } } @@ -223,9 +223,9 @@ class GisSdkClient { } } - void _onCodeError(Object? error) { + void _onCodeError(GoogleIdentityServicesError? error) { if (error != null) { - _codeResponses.addError((error as GoogleIdentityServicesError).type); + _codeResponses.addError(error.type); } } From 09847abdc8e9c160828372c0a1a456a9314c3d23 Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Wed, 6 Nov 2024 17:02:32 -0800 Subject: [PATCH 2/6] Remove unnecessary code doc --- .../lib/src/js_interop/google_accounts_oauth2.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/google_identity_services_web/lib/src/js_interop/google_accounts_oauth2.dart b/packages/google_identity_services_web/lib/src/js_interop/google_accounts_oauth2.dart index 723cc81423ca..30a843b07e05 100644 --- a/packages/google_identity_services_web/lib/src/js_interop/google_accounts_oauth2.dart +++ b/packages/google_identity_services_web/lib/src/js_interop/google_accounts_oauth2.dart @@ -313,9 +313,6 @@ extension TokenClientExtension on TokenClient { @staticInterop abstract class OverridableTokenClientConfig { /// Constructs an OverridableTokenClientConfig object in JavaScript. - /// - /// The [callback] property must be wrapped in [allowInterop] before it's - /// passed to this constructor. factory OverridableTokenClientConfig({ /// A list of scopes that identify the resources that your application could /// access on the user's behalf. These values inform the consent screen that From fddcca17108530e98f5dca2eaba4d8f7544df6d0 Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Wed, 6 Nov 2024 17:13:43 -0800 Subject: [PATCH 3/6] Move changelog entry to next --- packages/google_identity_services_web/CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/google_identity_services_web/CHANGELOG.md b/packages/google_identity_services_web/CHANGELOG.md index c0cbb02780ef..949d61d1d93a 100644 --- a/packages/google_identity_services_web/CHANGELOG.md +++ b/packages/google_identity_services_web/CHANGELOG.md @@ -1,13 +1,13 @@ ## NEXT * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. +* Clean up documentation of callbacks in `CodeClientConfig`, + `TokenClientConfig`, `onGoogleLibraryLoad`, and `revoke` to indicate they only + accept Dart functions and not JS functions. ## 0.3.1+4 * Restores support for Dart `^3.3.0`. -* Clean up documentation of callbacks in `CodeClientConfig`, - `TokenClientConfig`, `onGoogleLibraryLoad`, and `revoke` to indicate they only - accept Dart functions and not JS functions. ## 0.3.1+3 From ccbde11feba34e015fcbf087ca57a93c4995148d Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Wed, 6 Nov 2024 19:28:41 -0800 Subject: [PATCH 4/6] Update version number --- packages/google_identity_services_web/CHANGELOG.md | 2 +- packages/google_identity_services_web/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/google_identity_services_web/CHANGELOG.md b/packages/google_identity_services_web/CHANGELOG.md index 949d61d1d93a..10b7d4d9f8fc 100644 --- a/packages/google_identity_services_web/CHANGELOG.md +++ b/packages/google_identity_services_web/CHANGELOG.md @@ -1,4 +1,4 @@ -## NEXT +## 0.3.1+5 * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. * Clean up documentation of callbacks in `CodeClientConfig`, diff --git a/packages/google_identity_services_web/pubspec.yaml b/packages/google_identity_services_web/pubspec.yaml index e2b79567418b..21f6a0c3d583 100644 --- a/packages/google_identity_services_web/pubspec.yaml +++ b/packages/google_identity_services_web/pubspec.yaml @@ -2,7 +2,7 @@ name: google_identity_services_web description: A Dart JS-interop layer for Google Identity Services. Google's new sign-in SDK for Web that supports multiple types of credentials. repository: https://github.com/flutter/packages/tree/main/packages/google_identity_services_web issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_identiy_services_web%22 -version: 0.3.1+4 +version: 0.3.1+5 environment: sdk: ^3.4.0 From 48d5c294be448fe713bdd9a34cbadd8b261bceac Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Wed, 6 Nov 2024 20:27:36 -0800 Subject: [PATCH 5/6] Add version for google_sign_in --- packages/google_sign_in/google_sign_in_web/CHANGELOG.md | 4 ++++ packages/google_sign_in/google_sign_in_web/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md index 81e264dd4361..886ddc925032 100644 --- a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.12.4+3 + +* Fix callback types for `TokenClientConfig`. + ## 0.12.4+2 * Adds support for `web: ^1.0.0`. diff --git a/packages/google_sign_in/google_sign_in_web/pubspec.yaml b/packages/google_sign_in/google_sign_in_web/pubspec.yaml index ed441ec021a0..85aa2ba45a09 100644 --- a/packages/google_sign_in/google_sign_in_web/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_web/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android, iOS and Web. repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in_web issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 0.12.4+2 +version: 0.12.4+3 environment: sdk: ^3.3.0 From 1d74e4780307476390c6d884b01cd25e47ac9e5b Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Thu, 7 Nov 2024 08:45:09 -0800 Subject: [PATCH 6/6] Use present tense in changelog --- packages/google_identity_services_web/CHANGELOG.md | 2 +- packages/google_sign_in/google_sign_in_web/CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/google_identity_services_web/CHANGELOG.md b/packages/google_identity_services_web/CHANGELOG.md index 10b7d4d9f8fc..8f476099fc4d 100644 --- a/packages/google_identity_services_web/CHANGELOG.md +++ b/packages/google_identity_services_web/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.3.1+5 * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. -* Clean up documentation of callbacks in `CodeClientConfig`, +* Cleans up documentation of callbacks in `CodeClientConfig`, `TokenClientConfig`, `onGoogleLibraryLoad`, and `revoke` to indicate they only accept Dart functions and not JS functions. diff --git a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md index 886ddc925032..7c3db8fd4da4 100644 --- a/packages/google_sign_in/google_sign_in_web/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_web/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.12.4+3 -* Fix callback types for `TokenClientConfig`. +* Fixes callback types for `TokenClientConfig`. ## 0.12.4+2