You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: packages/google_sign_in/google_sign_in_web/README.md
+89-34
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,87 @@
2
2
3
3
The web implementation of [google_sign_in](https://pub.dev/packages/google_sign_in)
4
4
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
+
5
86
## Usage
6
87
7
88
### Import the package
@@ -12,7 +93,7 @@ normally. This package will be automatically included in your app when you do.
12
93
13
94
### Web integration
14
95
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.
16
97
17
98
On your `web/index.html` file, add the following `meta` tag, somewhere in the
18
99
`head` of the document:
@@ -29,7 +110,10 @@ You can do this by:
29
110
2. Clicking "Edit" in the OAuth 2.0 Web application client that you created above.
30
111
3. Adding the URIs you want to the **Authorized JavaScript origins**.
31
112
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)
[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.**
82
137
83
138
## Example
84
139
85
140
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).
86
141
87
142
## API details
88
143
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.
0 commit comments