Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 6649796

Browse files
committed
Add migration notes to the README.
1 parent 9e4dcae commit 6649796

File tree

2 files changed

+90
-44
lines changed

2 files changed

+90
-44
lines changed

packages/google_sign_in/google_sign_in_web/CHANGELOG.md

+1-10
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@
22

33
* **Breaking Change:** Migrates JS-interop to `package:google_identity_services_web`
44
* Uses the new Google Identity Authentication and Authorization JS SDKs. [Docs](https://developers.google.com/identity).
5-
* TODO: Move the below to a migration instructions doc in the README.
6-
* Authentication and Authorization are now two separate concerns.
7-
* `signInSilently` now displays the One Tap UX for web. The SDK no longer has
8-
direct access to previously-seen users.
9-
* The new SDK only provides an `idToken` when the user does `signInSilently`.
10-
* The plugin attempts to mimic the old behavior (of retrieving Profile information
11-
on `signIn`) but in that case, the `idToken` is not returned.
12-
* The plugin no longer is able to renew Authorization sessions on the web.
13-
Once the session expires, API requests will begin to fail with unauthorized,
14-
and user Authorization is required again.
5+
* Added "Migrating to v0.11" section to the `README.md`.
156
* Updates minimum Flutter version to 3.0.
167

178
## 0.10.2+1

packages/google_sign_in/google_sign_in_web/README.md

+89-34
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,87 @@
22

33
The web implementation of [google_sign_in](https://pub.dev/packages/google_sign_in)
44

5+
## Migrating to v0.11 (Google Identity Services)
6+
7+
The `google_sign_in_web` plugin is backed by the new Google Identity Services
8+
JS SDK since version 0.11.0.
9+
10+
The new SDK is used both for [Authentication](https://developers.google.com/identity/gsi/web/guides/overview)
11+
and [Authorization](https://developers.google.com/identity/oauth2/web/guides/overview) flows.
12+
13+
The new SDK, however, doesn't behave exactly like the one being deprecated.
14+
Some concepts have experienced pretty drastic changes, and that's why this
15+
required a major version update.
16+
17+
### Key differences between the SDK
18+
19+
* For the SDK, Authentication and Authorization are now two separate concerns.
20+
* Authentication (information about the current user) flows will not
21+
authorize `scopes` anymore.
22+
* Authorization (permissions for the app to access certain user information)
23+
flows will not return authentication information.
24+
* The SDK no longer has direct access to previously-seen users upon initialization.
25+
* `signInSilently` now displays the One Tap UX for web.
26+
* The new SDK only provides an `idToken` (JWT-encoded info) when the user
27+
successfully completes `signInSilently`.
28+
* `signIn` uses the Oauth "Implicit Flow" to Authorize the requested `scopes`.
29+
* If the user hasn't `signInSilently`, they'll have to sign in as a first step
30+
of the Authorization popup flow.
31+
* If `signInSilently` was unsuccessful, the plugin will add extra `scopes` to
32+
`signIn` and retrieve basic Profile information from the People API via a
33+
REST call immediately after a successful authorization. In this case, the
34+
`idToken` field of the `GoogleSignInUserData` will always be null.
35+
* The SDK no longer handles sign-in state and user sessions, it only provides
36+
Authentication credentials for the moment the user did authenticate.
37+
* The SDK no longer is able to renew Authorization sessions on the web.
38+
Once the token expires, API requests will begin to fail with unauthorized,
39+
and user Authorization is required again.
40+
41+
See more differences in the following migration guides:
42+
43+
* Authentication > [Migrating from Google Sign-In](https://developers.google.com/identity/gsi/web/guides/migration)
44+
* Authorization > [Migrate to Google Identity Services](https://developers.google.com/identity/oauth2/web/guides/migration-to-gis)
45+
46+
### New use cases to take into account in your app
47+
48+
#### User Sessions
49+
50+
Since the new SDK does *not* manage user sessions anymore, apps that relied on
51+
this feature might break.
52+
53+
If long-lived sessions are required, consider using some User authentication
54+
system that supports Google Sign In as a federated Authentication provider,
55+
like [Firebase Auth](https://firebase.google.com/docs/auth/flutter/federated-auth#google),
56+
or similar (expand this list as other providers become generally available for
57+
Flutter web).
58+
59+
#### Expired / Invalid Authorization Tokens
60+
61+
Since the new SDK does *not* auto-renew authorization tokens anymore, it's now
62+
the responsibility of your app to do so.
63+
64+
Apps now need to monitor the status code of their REST API requests for response
65+
codes different to `200`. For example:
66+
67+
* `401`: Missing or invalid access token.
68+
* `403`: Expired access token.
69+
70+
In either case, your app needs to prompt the end user to `signIn` again, to
71+
interactively renew the token. The GIS SDK limits authorization token duration
72+
to one hour (3600 seconds).
73+
74+
#### Null `idToken`
75+
76+
The `GoogleSignInUserData` returned after `signIn` may contain a `null` `idToken`
77+
field. This is not an indication of the session being invalid, it's just that
78+
the user canceled (or wasn't presented with) the OneTap UX from `signInSilently`.
79+
80+
In cases where the OneTap UX does not authenticate the user, the `signIn` method
81+
will attempt to "fill in the gap" by requesting basic profile information of the
82+
currently signed-in user.
83+
84+
In that case, the `GoogleSignInUserData` will contain a `null` `idToken`.
85+
586
## Usage
687

788
### Import the package
@@ -12,7 +93,7 @@ normally. This package will be automatically included in your app when you do.
1293

1394
### Web integration
1495

15-
First, go through the instructions [here](https://developers.google.com/identity/sign-in/web/sign-in#before_you_begin) to create your Google Sign-In OAuth client ID.
96+
First, go through the instructions [here](https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid) to create your Google Sign-In OAuth client ID.
1697

1798
On your `web/index.html` file, add the following `meta` tag, somewhere in the
1899
`head` of the document:
@@ -29,7 +110,10 @@ You can do this by:
29110
2. Clicking "Edit" in the OAuth 2.0 Web application client that you created above.
30111
3. Adding the URIs you want to the **Authorized JavaScript origins**.
31112

32-
For local development, may add a `localhost` entry, for example: `http://localhost:7357`
113+
For local development, you must add two `localhost` entries:
114+
115+
* `http://localhost` and
116+
* `http://localhost:7357` (or any port that is free in your machine)
33117

34118
#### Starting flutter in http://localhost:7357
35119

@@ -45,48 +129,19 @@ flutter run -d chrome --web-hostname localhost --web-port 7357
45129

46130
Read the rest of the instructions if you need to add extra APIs (like Google People API).
47131

48-
49132
### Using the plugin
50-
Add the following import to your Dart code:
51133

52-
```dart
53-
import 'package:google_sign_in/google_sign_in.dart';
54-
```
134+
See the [**Usage** instructions of `package:google_sign_in`](https://pub.dev/packages/google_sign_in#usage)
55135

56-
Initialize GoogleSignIn with the scopes you want:
57-
58-
```dart
59-
GoogleSignIn _googleSignIn = GoogleSignIn(
60-
scopes: [
61-
'email',
62-
'https://www.googleapis.com/auth/contacts.readonly',
63-
],
64-
);
65-
```
66-
67-
[Full list of available scopes](https://developers.google.com/identity/protocols/googlescopes).
68-
69-
Note that the `serverClientId` parameter of the `GoogleSignIn` constructor is not supported on Web.
70-
71-
You can now use the `GoogleSignIn` class to authenticate in your Dart code, e.g.
72-
73-
```dart
74-
Future<void> _handleSignIn() async {
75-
try {
76-
await _googleSignIn.signIn();
77-
} catch (error) {
78-
print(error);
79-
}
80-
}
81-
```
136+
Note that the **`serverClientId` parameter of the `GoogleSignIn` constructor is not supported on Web.**
82137

83138
## Example
84139

85140
Find the example wiring in the [Google sign-in example application](https://github.com/flutter/plugins/blob/main/packages/google_sign_in/google_sign_in/example/lib/main.dart).
86141

87142
## API details
88143

89-
See the [google_sign_in.dart](https://github.com/flutter/plugins/blob/main/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart) for more API details.
144+
See [google_sign_in.dart](https://github.com/flutter/plugins/blob/main/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart) for more API details.
90145

91146
## Contributions and Testing
92147

0 commit comments

Comments
 (0)