google_identity_services_web
0.3.3+1A Dart JS-interop layer for Google Identity Services. Google's new sign-in SDK for Web that supports multiple types of credentials.
Readme
google_identity_services_web
A JS-interop layer for Google Identity's Sign In With Google SDK.
See the original JS SDK reference:
Usage
This package is the Dart JS-interop layer of the new Sign In With Google SDK. Here's the API references for both of the sub-libraries:
id.dart: Sign In With Google JavaScript API referenceoauth2.dart: Google 3P Authorization JavaScript Library for websites - API referenceloader.dart: An (optional) loader mechanism that installs the library and resolves aFuture<void>when it's ready.
Loading the SDK
There are two ways to load the JS SDK in your app.
Modify your index.html (most performant)
The most performant way is to modify your web/index.html file to insert a
script tag as recommended.
Place the script tag in the <head> of your site:
<head>
<!-- ··· -->
<!-- Include the GSI SDK below -->
<script src="https://accounts.google.com/gsi/client" async defer></script>
</head>
With the loadWebSdk function (on-demand)
An alternative way, that downloads the SDK on demand, is to use the
loadWebSdk function provided by the library. A simple location to embed
this in a Flutter Web only app can be the main.dart:
import 'package:google_identity_services_web/loader.dart' as gis;
// ···
void main() async {
await gis.loadWebSdk(); // Load the GIS SDK
// The rest of your code...
// ···
}
(Note that the above won't compile for mobile apps, so if you're developing a
cross-platform app, you'll probably need to hide the call to loadWebSdk
behind a conditional import/export.)
Using the SDK
Once the SDK has been loaded, it can be used by importing the correct library:
import 'package:google_identity_services/id.dart';for Authentication.- This will expose an
idJSObject that binds togoogle.accounts.id.
- This will expose an
import 'package:google_identity_services/oauth2.dart';for Authorization.- This will expose an
oauth2JSObject that binds togoogle.accounts.oauth2.
- This will expose an
Troubleshooting
Watch the browser's development tools JS console while using this package. Information about errors during initialization and use of the library will be displayed there.
Some common issues identified so far:
The given origin is not allowed for the given client ID
When you perform local tests or development, you must add both
http://localhostandhttp://localhost:<port_number>to the Authorized JavaScript origins box. The Referrer-Policy response header must also be set tono-referrer-when-downgradewhen using http and localhost.
Browser compatibility
The new SDK is introducing concepts that are on track for standardization to most browsers, and it might not be compatible with older browsers.
Refer to the official documentation site for the latest browser compatibility information of the underlying JS SDK:
- Sign In With Google > Supported browsers and platforms
Changelog
0.3.3+1
- Handles potential exceptions gracefully while fetching
Moment*Reasonfor invalid value.
0.3.3
- Moves all the JavaScript types to extend
JSObject.
0.3.2
- Adds the
nonceparameter toloadWebSdk.
0.3.1+5
- Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
- Cleans up documentation of callbacks in
CodeClientConfig,TokenClientConfig,onGoogleLibraryLoad, andrevoketo indicate they only accept Dart functions and not JS functions.
0.3.1+4
- Restores support for Dart
^3.3.0.
0.3.1+3
- Updates
README.mdto reflect modernindex.htmlscript tag placement.
0.3.1+2
- Adds support for
web: ^1.0.0. - Updates SDK version to Dart
^3.4.0. Flutter^3.22.0.
0.3.1+1
- Uses
TrustedTypesfromweb: ^0.5.1.
0.3.1
- Updates web code to package
web: ^0.5.0. - Updates SDK version to Dart
^3.3.0. Flutter^3.19.0.
0.3.0+2
- Adds
fedcm_autotoCredentialSelectByenum. - Adds
unknown_reasonto allMoment*Reasonenums.
0.3.0+1
- Corrects 0.3.0 changelog entry about the minimum Flutter/Dart dependencies.
0.3.0
- Updates minimum supported SDK version to Flutter 3.16/Dart 3.2.
- Migrates from
package:js/dart:htmltopackage:webso this package can compile to WASM. - Performs the following breaking API changes (in bold) and other fixes to
align with the published GIS SDK:
- Removes the need to explicitly
allowInteropin all callbacks. id:- Changes type:
IdConfiguration.intermediate_iframe_close_callbacktoVoidFn?.
- Adds:
fedcmtoCredentialSelectByenum. - Fixes typo in
storeCredentialcallbackpositional parameter name.
- Changes type:
oauth2:- Removes:
CodeClientConfig.auto_select,hint(nowlogin_hint), andhosted_domain(nowhd).TokenClientConfig.hint(nowlogin_hint) andhosted_domain(nowhd).OverridableTokenClientConfig.hint(nowlogin_hint).
- Changes types:
CodeClientConfig.redirect_uritoUri?.scopeinCodeClientConfigandCodeResponsetoList<String>.CodeResponse.codeandstatetoString?(now nullable).scopeinTokenClientConfig,OverridableTokenClientConfig, andTokenResponsetoList<String>.- The following
TokenResponsegetters are now nullable:access_token,expires_in,hd,prompt,token_type, andstate. - The
error_callbackfunctions now receive aGoogleIdentityServicesErrorparameter, instead ofObject.
- Adds:
include_granted_scopesandenable_granular_consenttoCodeClientConfig.include_granted_scopesandenable_granular_consenttoTokenClientConfig.enable_granular_consenttoOverridableTokenClientConfig.messagetoGoogleIdentityServicesError.
- Fixes:
- Assert that
scopeis not empty when used to createCodeClientConfig,TokenClientConfig, andOverridableTokenClientConfiginstances. - Deprecated
enable_serial_consent.
- Assert that
- Removes:
- Removes the need to explicitly
0.2.2
- Adds the following new fields to
IdConfiguration:login_hint,hdas auto-select hints for users with multiple accounts/domains.use_fedcm_for_promptso FedCM can be enabled.
0.2.1+1
- Adds pub topics to package metadata.
- Updates minimum supported SDK version to Flutter 3.7/Dart 2.19.
0.2.1
- Relaxes the
renderButtonAPI so any JS-Interop Object can be itstarget. - Exposes the
Button*configuration enums, so the rendered button can be configured.
0.2.0
- Adds
renderButtonAPI toid.dart. - Breaking Change: Makes JS-interop API more
dart2wasm-friendly.- Removes external getters for function types
- Introduces an external getter for the whole libraries instead.
- Updates
README.mdwith the new way ofimporting the desired libraries.
0.1.1
- Add optional
scopetoOverridableTokenClientConfigobject. - Mark some callbacks as optional properly.
0.1.0
- Initial release.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add google_identity_services_webpubspec.yaml
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.3+1
environment:
sdk: ^3.4.0
dependencies:
meta: ^1.3.0
web: ">=0.5.1 <2.0.0"
dev_dependencies:
path: ^1.8.1
test: ^1.21.1
topics:
- authentication
- google-identity-services
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.1.0 | On demand | Download | 2c581f4b…39aa34 |
| 0.1.1 | On demand | Download | 925a358d…4fa589 |
| 0.2.0 | On demand | Download | 5d9af2f1…e7d381 |
| 0.2.1 | On demand | Download | 7940fdc3…2efacd |
| 0.2.1+1 | On demand | Download | 554748f2…3838ed |
| 0.2.2 | On demand | Download | 000b7a31…f2484e |
| 0.3.0 | On demand | Download | 3c01a3ff…d6a563 |
| 0.3.0+1 | On demand | Download | 15b85577…af6267 |
| 0.3.0+2 | On demand | Download | 0c56c2c5…37ccf6 |
| 0.3.1 | On demand | Download | 972ff30e…ec5385 |
| 0.3.1+1 | On demand | Download | 9482364c…5265d8 |
| 0.3.1+2 | On demand | Download | e883b73a…402c28 |
| 0.3.1+3 | On demand | Download | c6a67eb2…6335a8 |
| 0.3.1+4 | On demand | Download | 5be19152…6199b6 |
| 0.3.1+5 | On demand | Download | 304e2a4c…f227b6 |
| 0.3.2 | On demand | Download | bf215f34…c6f4d8 |
| 0.3.3 | On demand | Download | 55580f43…c3c6c9 |
| 0.3.3+1 | Cached · Upstream SHA-256 matched | Download | 5d187c46…3ee454 |
Dependencies
meta "^1.3.0"
web "\u003e=0.5.1 \u003c2.0.0"