# google_identity_services_web 0.3.3+1

A Dart JS-interop layer for Google Identity Services. Google's new sign-in SDK for Web that supports multiple types of credentials.




## Installing
```
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add google_identity_services_web
```
Published: 2025-04-22T18:14:12.605534Z
Expected archive SHA-256: 5d187c46dc59e02646e10fe82665fc3884a9b71bc1c90c2b8b749316d33ee454

Available in cache; verification: upstream_checksum
## Direct dependencies
- meta: ^1.3.0
- web: >=0.5.1 <2.0.0

## Package README (untrusted upstream documentation)
# google_identity_services_web

A JS-interop layer for Google Identity's Sign In With Google SDK.

See the original JS SDK reference:

* [Sign In With Google](https://developers.google.com/identity/gsi/web)

## 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 reference](https://developers.google.com/identity/gsi/web/reference/js-reference)
* `oauth2.dart`: [Google 3P Authorization JavaScript Library for websites - API reference](https://developers.google.com/identity/oauth2/web/reference/js-reference)
* `loader.dart`: An (optional) loader mechanism that installs the library and
resolves a `Future<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](https://developers.google.com/identity/gsi/web/guides/client-library).
Place the `script` tag in the `<head>` of your site:

<?code-excerpt "example/web/index-with-script-tag.html (script-tag)"?>
```html
<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`:

<?code-excerpt "example/lib/main.dart (use-loader)"?>
```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](https://dart.dev/guides/libraries/create-library-packages#conditionally-importing-and-exporting-library-files).)

### 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 `id` JSObject that binds to `google.accounts.id`.
* `import 'package:google_identity_services/oauth2.dart';` for Authorization.
  * This will expose an `oauth2` JSObject that binds to `google.accounts.oauth2`.

### 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://localhost` and `http://localhost:<port_number>` to the
> **Authorized JavaScript origins** box.
> The [Referrer-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy)
> response header must also be set to `no-referrer-when-downgrade` when using
> http and localhost.

* Read more: [Sign In with Google for Web - Setup - Get your Google API client ID](https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid#get_your_google_api_client_id).

## 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](https://developers.google.com/identity/gsi/web/guides/supported-browsers)**

## Changelog
## 0.3.3+1

* Handles potential exceptions gracefully while fetching `Moment*Reason` for invalid value.

## 0.3.3

* Moves all the JavaScript types to extend `JSObject`.

## 0.3.2

* Adds the `nonce` parameter to `loadWebSdk`.

## 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`, and `revoke` to 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.md` to reflect modern `index.html` script 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 `TrustedTypes` from `web: ^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_auto` to `CredentialSelectBy` enum.
* Adds `unknown_reason` to all `Moment*Reason` enums.

## 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:html` to `package:web` so 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 `allowInterop` in all callbacks.**
  * `id`:
    * **Changes type:**
      * `IdConfiguration.intermediate_iframe_close_callback` to
      `VoidFn?`.
    * Adds: `fedcm` to `CredentialSelectBy` enum.
    * Fixes typo in `storeCredential` `callback` positional parameter name.
  * `oauth2`:
    * **Removes:**
      * `CodeClientConfig.auto_select`, `hint` (now `login_hint`), and `hosted_domain` (now `hd`).
      * `TokenClientConfig.hint` (now `login_hint`) and `hosted_domain` (now `hd`).
      * `OverridableTokenClientConfig.hint` (now `login_hint`).
    * **Changes types:**
      * `CodeClientConfig.redirect_uri` to `Uri?`.
      * `scope` in `CodeClientConfig` and `CodeResponse` to `List<String>`.
      * `CodeResponse.code` and `state` to `String?` (now nullable).
      * `scope` in `TokenClientConfig`, `OverridableTokenClientConfig`, and `TokenResponse` to `List<String>`.
      * The following `TokenResponse` getters are now nullable: `access_token`,
        `expires_in`, `hd`, `prompt`, `token_type`, and `state`.
      * The `error_callback` functions now receive a `GoogleIdentityServicesError` parameter, instead of `Object`.
    * Adds:
      * `include_granted_scopes` and `enable_granular_consent` to `CodeClientConfig`.
      * `include_granted_scopes` and `enable_granular_consent` to `TokenClientConfig`.
      * `enable_granular_consent` to `OverridableTokenClientConfig`.
      * `message` to `GoogleIdentityServicesError`.
    * Fixes:
      * Assert that `scope` is not empty when used to create `CodeClientConfig`,
        `TokenClientConfig`, and `OverridableTokenClientConfig` instances.
      * Deprecated `enable_serial_consent`.

## 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.
* Updates minimum supported SDK version to Flutter 3.7/Dart 2.19.

## 0.2.1

* Relaxes the `renderButton` API so any JS-Interop Object can be its `target`.
* Exposes the `Button*` configuration enums, so the rendered button can be configured.

## 0.2.0

* Adds `renderButton` API to `id.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.md` with the new way of `import`ing the desired libraries.

## 0.1.1

* Add optional `scope` to `OverridableTokenClientConfig` object.
* Mark some callbacks as optional properly.

## 0.1.0

* Initial release.







 
