Skip to content

Commit d439062

Browse files
authored
[gis_web] Adds FedCM toggle. (#5123)
This PR updates the `IdConfiguration` object of the Google Identity Services SDK with new values added since this was last updated. The main change is adding `use_fedcm_for_prompt` so [FedCM can be enabled](https://developers.google.com/identity/gsi/web/guides/fedcm-migration) on Flutter Web apps. ### Issues Pre-requirement for: flutter/flutter#133703
1 parent e8127e7 commit d439062

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed

packages/google_identity_services_web/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.2.2
2+
3+
* Adds the following new fields to `IdConfiguration`:
4+
* `login_hint`, `hd` as auto-select hints for users with multiple accounts/domains.
5+
* `use_fedcm_for_prompt` so FedCM can be enabled.
6+
17
## 0.2.1+1
28

39
* Adds pub topics to package metadata.

packages/google_identity_services_web/example/integration_test/js_interop_id_test.dart

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
88
import 'package:google_identity_services_web/id.dart';
99
import 'package:integration_test/integration_test.dart';
1010
import 'package:js/js.dart';
11+
import 'package:js/js_util.dart' as js_util show getProperty;
1112

1213
import 'src/dom.dart';
1314
import 'utils.dart' as utils;
@@ -31,6 +32,53 @@ void main() async {
3132
});
3233
});
3334

35+
group('IdConfig', () {
36+
testWidgets('passes values from Dart to JS', (_) async {
37+
final IdConfiguration config = IdConfiguration(
38+
client_id: 'testing_1-2-3',
39+
auto_select: false,
40+
callback: allowInterop((_) {}),
41+
login_uri: Uri.parse('https://www.example.com/login'),
42+
native_callback: allowInterop((_) {}),
43+
cancel_on_tap_outside: false,
44+
prompt_parent_id: 'some_dom_id',
45+
nonce: 's0m3_r4ndOM_vALu3',
46+
context: OneTapContext.signin,
47+
state_cookie_domain: 'subdomain.example.com',
48+
ux_mode: UxMode.popup,
49+
allowed_parent_origin: <String>['allowed', 'another'],
50+
intermediate_iframe_close_callback: allowInterop((_) {}),
51+
itp_support: true,
52+
login_hint: '[email protected]',
53+
hd: 'hd_value',
54+
use_fedcm_for_prompt: true,
55+
);
56+
57+
// Save some keystrokes below by partially applying to the 'config' above.
58+
void expectConfigValue(String name, Object? matcher) {
59+
expect(js_util.getProperty(config, name), matcher, reason: name);
60+
}
61+
62+
expectConfigValue('allowed_parent_origin', hasLength(2));
63+
expectConfigValue('auto_select', isFalse);
64+
expectConfigValue('callback', isA<Function>());
65+
expectConfigValue('cancel_on_tap_outside', isFalse);
66+
expectConfigValue('client_id', 'testing_1-2-3');
67+
expectConfigValue('context', isA<OneTapContext>());
68+
expectConfigValue('hd', 'hd_value');
69+
expectConfigValue('intermediate_iframe_close_callback', isA<Function>());
70+
expectConfigValue('itp_support', isTrue);
71+
expectConfigValue('login_hint', '[email protected]');
72+
expectConfigValue('login_uri', isA<Uri>());
73+
expectConfigValue('native_callback', isA<Function>());
74+
expectConfigValue('nonce', 's0m3_r4ndOM_vALu3');
75+
expectConfigValue('prompt_parent_id', 'some_dom_id');
76+
expectConfigValue('state_cookie_domain', 'subdomain.example.com');
77+
expectConfigValue('use_fedcm_for_prompt', isTrue);
78+
expectConfigValue('ux_mode', isA<UxMode>());
79+
});
80+
});
81+
3482
group('prompt', () {
3583
testWidgets('supports a moment notification callback', (_) async {
3684
id.initialize(IdConfiguration(client_id: 'testing_1-2-3'));

packages/google_identity_services_web/example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void main() async {
2222
final IdConfiguration config = IdConfiguration(
2323
client_id: 'your-client_id.apps.googleusercontent.com',
2424
callback: allowInterop(onCredentialResponse),
25+
use_fedcm_for_prompt: true,
2526
);
2627

2728
id.initialize(config);

packages/google_identity_services_web/lib/src/js_interop/google_accounts_id.dart

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,40 @@ abstract class IdConfiguration {
230230
/// the callback is invoked.
231231
Function? intermediate_iframe_close_callback,
232232

233-
/// determines if the upgraded One Tap UX should be enabled on browsers
233+
/// Determines if the upgraded One Tap UX should be enabled on browsers
234234
/// that support Intelligent Tracking Prevention (ITP). The default value
235235
/// is false.
236236
///
237237
/// See: https://developers.google.com/identity/gsi/web/guides/features#upgraded_ux_on_itp_browsers
238238
bool? itp_support,
239+
240+
/// If your application knows in advance which user should be signed-in, it
241+
/// can provide a login hint to Google.
242+
///
243+
/// When successful, account selection is skipped. Accepted values are:
244+
/// * an email address or
245+
/// * an ID token sub field value.
246+
///
247+
/// For more information, see:
248+
/// * https://developers.google.com/identity/protocols/oauth2/openid-connect#authenticationuriparameters
249+
String? login_hint,
250+
251+
/// When a user has multiple accounts and should only sign-in with their
252+
/// Workspace account use this to provide a domain name hint to Google.
253+
///
254+
/// When successful, user accounts displayed during account selection are
255+
/// limited to the provided domain.
256+
///
257+
/// A wildcard value: `*` offers only Workspace accounts to the user and
258+
/// excludes consumer accounts ([email protected]) during account selection.
259+
///
260+
/// For more information, see:
261+
/// * https://developers.google.com/identity/protocols/oauth2/openid-connect#authenticationuriparameters
262+
String? hd,
263+
264+
/// Allow the browser to control user sign-in prompts and mediate the
265+
/// sign-in flow between your website and Google. Defaults to false.
266+
bool? use_fedcm_for_prompt,
239267
});
240268
}
241269

packages/google_identity_services_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_identity_services_web
22
description: A Dart JS-interop layer for Google Identity Services. Google's new sign-in SDK for Web that supports multiple types of credentials.
33
repository: https://github.com/flutter/packages/tree/main/packages/google_identity_services_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_identiy_services_web%22
5-
version: 0.2.1+1
5+
version: 0.2.2
66

77
environment:
88
sdk: ">=2.19.0 <4.0.0"

0 commit comments

Comments
 (0)