Skip to content

Commit

Permalink
[gis_web] Adds FedCM toggle. (flutter#5123)
Browse files Browse the repository at this point in the history
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#133703
  • Loading branch information
ditman authored Oct 17, 2023
1 parent e8127e7 commit d439062
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/google_identity_services_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.2.2

* Adds the following new fields to `IdConfiguration`:
* `login_hint`, `hd` as auto-select hints for users with multiple accounts/domains.
* `use_fedcm_for_prompt` so FedCM can be enabled.

## 0.2.1+1

* Adds pub topics to package metadata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:google_identity_services_web/id.dart';
import 'package:integration_test/integration_test.dart';
import 'package:js/js.dart';
import 'package:js/js_util.dart' as js_util show getProperty;

import 'src/dom.dart';
import 'utils.dart' as utils;
Expand All @@ -31,6 +32,53 @@ void main() async {
});
});

group('IdConfig', () {
testWidgets('passes values from Dart to JS', (_) async {
final IdConfiguration config = IdConfiguration(
client_id: 'testing_1-2-3',
auto_select: false,
callback: allowInterop((_) {}),
login_uri: Uri.parse('https://www.example.com/login'),
native_callback: allowInterop((_) {}),
cancel_on_tap_outside: false,
prompt_parent_id: 'some_dom_id',
nonce: 's0m3_r4ndOM_vALu3',
context: OneTapContext.signin,
state_cookie_domain: 'subdomain.example.com',
ux_mode: UxMode.popup,
allowed_parent_origin: <String>['allowed', 'another'],
intermediate_iframe_close_callback: allowInterop((_) {}),
itp_support: true,
login_hint: 'login-hint@example.com',
hd: 'hd_value',
use_fedcm_for_prompt: true,
);

// Save some keystrokes below by partially applying to the 'config' above.
void expectConfigValue(String name, Object? matcher) {
expect(js_util.getProperty(config, name), matcher, reason: name);
}

expectConfigValue('allowed_parent_origin', hasLength(2));
expectConfigValue('auto_select', isFalse);
expectConfigValue('callback', isA<Function>());
expectConfigValue('cancel_on_tap_outside', isFalse);
expectConfigValue('client_id', 'testing_1-2-3');
expectConfigValue('context', isA<OneTapContext>());
expectConfigValue('hd', 'hd_value');
expectConfigValue('intermediate_iframe_close_callback', isA<Function>());
expectConfigValue('itp_support', isTrue);
expectConfigValue('login_hint', 'login-hint@example.com');
expectConfigValue('login_uri', isA<Uri>());
expectConfigValue('native_callback', isA<Function>());
expectConfigValue('nonce', 's0m3_r4ndOM_vALu3');
expectConfigValue('prompt_parent_id', 'some_dom_id');
expectConfigValue('state_cookie_domain', 'subdomain.example.com');
expectConfigValue('use_fedcm_for_prompt', isTrue);
expectConfigValue('ux_mode', isA<UxMode>());
});
});

group('prompt', () {
testWidgets('supports a moment notification callback', (_) async {
id.initialize(IdConfiguration(client_id: 'testing_1-2-3'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void main() async {
final IdConfiguration config = IdConfiguration(
client_id: 'your-client_id.apps.googleusercontent.com',
callback: allowInterop(onCredentialResponse),
use_fedcm_for_prompt: true,
);

id.initialize(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,40 @@ abstract class IdConfiguration {
/// the callback is invoked.
Function? intermediate_iframe_close_callback,

/// determines if the upgraded One Tap UX should be enabled on browsers
/// Determines if the upgraded One Tap UX should be enabled on browsers
/// that support Intelligent Tracking Prevention (ITP). The default value
/// is false.
///
/// See: https://developers.google.com/identity/gsi/web/guides/features#upgraded_ux_on_itp_browsers
bool? itp_support,

/// If your application knows in advance which user should be signed-in, it
/// can provide a login hint to Google.
///
/// When successful, account selection is skipped. Accepted values are:
/// * an email address or
/// * an ID token sub field value.
///
/// For more information, see:
/// * https://developers.google.com/identity/protocols/oauth2/openid-connect#authenticationuriparameters
String? login_hint,

/// When a user has multiple accounts and should only sign-in with their
/// Workspace account use this to provide a domain name hint to Google.
///
/// When successful, user accounts displayed during account selection are
/// limited to the provided domain.
///
/// A wildcard value: `*` offers only Workspace accounts to the user and
/// excludes consumer accounts (user@gmail.com) during account selection.
///
/// For more information, see:
/// * https://developers.google.com/identity/protocols/oauth2/openid-connect#authenticationuriparameters
String? hd,

/// Allow the browser to control user sign-in prompts and mediate the
/// sign-in flow between your website and Google. Defaults to false.
bool? use_fedcm_for_prompt,
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/google_identity_services_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.2.1+1
version: 0.2.2

environment:
sdk: ">=2.19.0 <4.0.0"
Expand Down

0 comments on commit d439062

Please sign in to comment.