Viewing version 1.1.3. Open the latest package page.

google_sign_in_web

1.1.3

Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android, iOS and Web.

Download archive

Readme

google_sign_in_web

The web implementation of google_sign_in

Usage

This package is endorsed, which means you can simply use google_sign_in normally. This package will be automatically included in your app when you do, so you do not need to add it to your pubspec.yaml.

However, if you import this package to use any of its APIs directly, you should add it to your pubspec.yaml as usual.

For example, you need to import this package directly if you plan to use the web-only Widget renderButton() method.

Integration

First, go through the instructions here to create your Google Sign-In OAuth client ID.

On your web/index.html file, add the following meta tag, somewhere in the head of the document:

<meta name="google-signin-client_id" content="YOUR_GOOGLE_SIGN_IN_OAUTH_CLIENT_ID.apps.googleusercontent.com">

For this client to work correctly, the last step is to configure the Authorized JavaScript origins, which identify the domains from which your application can send API requests. When in local development, this is normally localhost and some port.

You can do this by:

  1. Going to the Credentials page.
  2. Clicking "Edit" in the OAuth 2.0 Web application client that you created above.
  3. Adding the URIs you want to the Authorized JavaScript origins.

For local development, you must add two localhost entries:

  • http://localhost and
  • http://localhost:7357 (or any port that is free in your machine)

Starting flutter in http://localhost:7357

Normally flutter run starts in a random port. In the case where you need to deal with authentication like the above, that's not the most appropriate behavior.

You can tell flutter run to listen for requests in a specific host and port with the following:

flutter run -d chrome --web-hostname localhost --web-port 7357

Authentication

This implementation returns false for supportsAuthentication, and will throw if authenticate is called. This is because the Google Identity Services (GIS) SDK only allows signing in using UI provided by the SDK.

On the web, instead of providing custom UI that calls authenticate, you should display the Widget returned by renderButton (from web_only.dart), and listen to authenticationEvents to know when the user has signed in.

The GIS SDK does not renew authentication sessions. Once the token expires (after 3600 seconds), if you need to use the idToken again you must trigger a new authentication flow. In most cases, you should use the idToken immediately after authentication, and track sign-in state at the application level, or via a separate server backend.

Migration from versions before 0.12

See Migrating from Google Sign-In for information about the differences between authentication in the GIS SDK and the SDK used in older versions of this plugin.

Since the GIS SDK does not manage user sessions anymore, apps that relied on this feature might break. If long-lived sessions are required, consider using some user authentication system that supports Google Sign In as a federated Authentication provider, like Firebase Auth.

Authorization

The GIS SDK does not renew authorization sessions. Once the token expires (after 3600 seconds), API requests will begin to fail, and you must re-request user authorization. For example:

  • 401: Missing or invalid access token.
  • 403: Expired access token.

See the "Integration considerations > UX separation for authentication and authorization guide" in the official GIS SDK documentation for more information about this.

Migration from versions before 0.12

See Migrate to Google Identity Services for information about the differences between authentication in the GIS SDK and the SDK used in older versions of this plugin.

Changelog

1.1.3

  • Restored previously reverted changes to prevent _initCalled from being invoked twice on web.
  • Fixed renderButton being stuck on "Getting ready" on web by correcting the FutureBuilder state check to use ConnectionState.done.

1.1.2

  • Reverts "Throws a more actionable error when init is called more than once."

1.1.1 (withdrawn)

  • Throws a more actionable error when init is called more than once.
  • Updates minimum supported SDK version to Flutter 3.35/Dart 3.9.

1.1.0

  • Adds support for the clearAuthorizationToken method.
  • Updates minimum supported SDK version to Flutter 3.29/Dart 3.7.

1.0.0

  • BREAKING CHANGE: Switches to implementing version 3.0 of the platform interface package, rather than 2.x, significantly changing the API surface.
  • Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.

0.12.4+4

  • Asserts that new forceAccountName parameter is null (not used in web).
  • Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.

0.12.4+3

  • Fixes callback types for TokenClientConfig.

0.12.4+2

  • Adds support for web: ^1.0.0.

0.12.4+1

  • Fixes README.md typo.

0.12.4

  • Updates dependencies to web: ^0.5.0 and google_identity_services_web: ^0.3.1.

0.12.3+3

  • Updates SDK version to Dart ^3.3.0. Flutter ^3.19.0.
  • Prepares update to package web: ^0.5.0.

0.12.3+2

  • Fixes new lint warnings.

0.12.3+1

  • Updates FlexHtmlElementView (the widget backing renderButton) to not rely on web engine knowledge (a platform view CSS selector) to operate.

0.12.3

  • Migrates to package:web.
  • Updates minimum supported SDK version to Flutter 3.16.0/Dart 3.2.0.

0.12.2+1

  • Re-publishes 0.12.2 with a small fix to the CodeClient initialization.

0.12.2 (withdrawn)

  • Adds server auth code retrieval to google_sign_in_web.
  • Adds web_only library to access web-only methods more easily.

0.12.1

  • Enables FedCM on browsers that support this authentication mechanism.
  • Uses the expiration timestamps of Credential and Token responses to improve the accuracy of isSignedIn and canAccessScopes methods.
  • Deprecates signIn() method.
    • Users should migrate to renderButton and silentSignIn, as described in the README.

0.12.0+5

  • Migrates to dart:ui_web APIs.
  • Updates minimum supported SDK version to Flutter 3.13.0/Dart 3.1.0.

0.12.0+4

  • Adds pub topics to package metadata.
  • Updates minimum supported SDK version to Flutter 3.7/Dart 2.19.

0.12.0+3

  • Fixes null cast error on accounts without picture or name details.

0.12.0+2

  • Adds compatibility with http 1.0.

0.12.0+1

  • Fixes unawaited_futures violations.

0.12.0

  • Authentication:
    • Adds web-only renderButton method and its configuration object, as a new authentication mechanism.
    • Prepares a userDataEvents Stream, so the Google Sign In Button can propagate authentication changes to the core plugin.
    • Breaking Change: signInSilently now returns an authenticated (but not authorized) user.
  • Authorization:
    • Implements the new canAccessScopes method.
    • Ensures that the requestScopes call doesn't trigger user selection when the current user is known (similar to what signIn does).
  • Updates minimum Flutter version to 3.3.

0.11.0+2

  • Clarifies explanation of endorsement in README.
  • Aligns Dart and Flutter SDK constraints.

0.11.0+1

  • Updates links for the merge of flutter/plugins into flutter/packages.

0.11.0

  • Breaking Change: Migrates JS-interop to package:google_identity_services_web
    • Uses the new Google Identity Authentication and Authorization JS SDKs. Docs.
      • Added "Migrating to v0.11" section to the README.md.
  • Updates minimum Flutter version to 3.0.

0.10.2+1

  • Updates code for no_leading_underscores_for_local_identifiers lint.
  • Updates minimum Flutter version to 2.10.
  • Renames generated folder to js_interop.

0.10.2

  • Migrates to new platform-interface initWithParams method.
  • Throws when unsupported serverClientId option is provided.

0.10.1+3

  • Updates references to the obsolete master branch.

0.10.1+2

  • Minor fixes for new analysis options.

0.10.1+1

  • Fixes library_private_types_in_public_api, sort_child_properties_last and use_key_in_widget_constructors lint warnings.

0.10.1

  • Updates minimum Flutter version to 2.8.
  • Passes plugin_name to Google Sign-In's init method so new applications can continue using this plugin after April 30th 2022. Issue #88084.

0.10.0+5

  • Internal code cleanup for stricter analysis options.

0.10.0+4

  • Removes dependency on meta.

0.10.0+3

  • Updated URL to the google_sign_in package in README.

0.10.0+2

  • Add implements to pubspec.

0.10.0+1

  • Updated installation instructions in README.

0.10.0

  • Migrate to null-safety.

0.9.2+1

  • Update Flutter SDK constraint.

0.9.2

  • Throw PlatformExceptions from where the GMaps SDK may throw exceptions: init() and signIn().
  • Add two new JS-interop types to be able to unwrap JS errors in release mode.
  • Align the fields of the thrown PlatformExceptions with the mobile version.
  • Migrate tests to run with flutter drive

0.9.1+2

  • Update package:e2e reference to use the local version in the flutter/plugins repository.

0.9.1+1

  • Remove Android folder from google_sign_in_web.

0.9.1

  • Ensure the web code returns null when the user is not signed in, instead of a null-object User. Fixes issue 52338.

0.9.0

  • Add support for methods introduced in google_sign_in_platform_interface 1.1.0.

0.8.4

  • Remove all fakeConstructor$ from the generated facade. JS interop classes do not support non-external constructors.

0.8.3+2

  • Make the pedantic dev_dependency explicit.

0.8.3+1

  • Updated documentation with more instructions about Google Sign In web setup.

0.8.3

  • Fix initialization error that causes https://github.com/flutter/flutter/issues/48527
  • Throw a PlatformException when there's an initialization problem (like wrong server-side config).
  • Throw a StateError when checking .initialized before calling .init()
  • Update setup instructions in the README.

0.8.2+1

  • Add a non-op Android implementation to avoid a flaky Gradle issue.

0.8.2

  • Require Flutter SDK 1.12.13+hotfix.4 or greater.

0.8.1+2

  • Remove the deprecated author: field from pubspec.yaml
  • Require Flutter SDK 1.10.0 or greater.

0.8.1+1

  • Add missing documentation.

0.8.1

  • Add podspec to enable compilation on iOS.

0.8.0

  • Flutter for web initial release

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add 'google_sign_in_web:1.1.3'
pubspec.yaml
name: google_sign_in_web
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: 1.1.3

environment:
  sdk: ^3.9.0
  flutter: ">=3.35.0"

flutter:
  plugin:
    implements: google_sign_in
    platforms:
      web:
        pluginClass: GoogleSignInPlugin
        fileName: google_sign_in_web.dart

dependencies:
  flutter:
    sdk: flutter
  flutter_web_plugins:
    sdk: flutter
  google_identity_services_web: ^0.3.1
  google_sign_in_platform_interface: ^3.1.0
  http: ">=0.13.0 <2.0.0"
  web: ">=0.5.1 <2.0.0"

dev_dependencies:
  flutter_test:
    sdk: flutter

topics:
  - authentication
  - google-sign-in

Version history

VersionPublishedArchiveSHA-256
0.8.0On demandDownload446c3590…7d8714
0.8.1On demandDownload02a94b41…b6757e
0.8.1+2On demandDownloadfb0d1226…c6a1c9
0.8.2On demandDownloada600ac0b…b4996b
0.8.2+1On demandDownloadf77634e8…b05903
0.8.3On demandDownload6831bbce…7945df
0.8.3+1On demandDownloadfbc83c90…4b69b6
0.8.3+2On demandDownload8610b704…d614d7
0.8.4On demandDownloada71c6020…cc4250
0.9.0On demandDownload6bb8e809…9fa86a
0.9.1On demandDownload04eb0625…734693
0.9.1+1On demandDownload0915cae6…00c5ba
0.9.2On demandDownloadde62ed46…9f3b9b
0.10.0On demandDownload2a0d45a4…6150c4
0.10.0+1On demandDownload0d21f02f…041484
0.10.0+2On demandDownloadb2aa4a0a…1ac12d
0.10.0+3On demandDownload1f033801…b632d9
0.10.0+4On demandDownload2eaacb0b…aa5032
0.10.0+5On demandDownload4c860532…d90901
0.10.1On demandDownloadfd1a6bce…72e3a8
0.10.1+1On demandDownloaddf9460c4…2d5e0b
0.10.1+2On demandDownload9d943fe1…2def3b
0.10.1+3On demandDownloadc4dda2f5…9e86aa
0.10.2On demandDownload5b35c221…263af5
0.10.2+1On demandDownload75cc41eb…720b40
0.11.0On demandDownloada3377878…ca3c49
0.11.0+1On demandDownload824b42c0…be9f95
0.11.0+2On demandDownload9f883b9b…b0f465
0.12.0On demandDownload7e0ec507…0a723f
0.12.0+1On demandDownload7b154bc8…a12924
0.12.0+2On demandDownload69b9ce0e…ea68cc
0.12.0+3On demandDownloadc4ef88c4…561c52
0.12.0+4On demandDownloadb48263e4…19ffbe
0.12.0+5On demandDownload939e9172…279766
0.12.1On demandDownload6b08be47…612d8e
0.12.2On demandDownload0559197e…cc664f
0.12.2+1On demandDownload794f5494…3015e6
0.12.3On demandDownloadd77bc2a7…ad239d
0.12.3+1On demandDownload38e6ec2a…8ff549
0.12.3+2On demandDownloada278ea2d…a69d77
0.12.3+3On demandDownloadf2b3af0b…b35db2
0.12.4On demandDownloadfc0f14ed…e821bd
0.12.4+1On demandDownloadd606264c…572228
0.12.4+2On demandDownload042805a2…f68055
0.12.4+3On demandDownloadada595df…c6281b
0.12.4+4On demandDownload460547be…0e4ded
1.0.0On demandDownload09ac306b…f7b468
1.1.0On demandDownload2fc1f941…75a1da
1.1.1On demandDownloade2658572…38dcb0
1.1.2On demandDownloaddac0676a…db9102
1.1.3Cached · Upstream SHA-256 matchedDownloadd473003e…245d14

Dependencies

flutter { "sdk": "flutter" }

flutter_web_plugins { "sdk": "flutter" }

google_identity_services_web "^0.3.1"

google_sign_in_platform_interface "^3.1.0"

http "\u003e=0.13.0 \u003c2.0.0"

web "\u003e=0.5.1 \u003c2.0.0"