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
Copy file name to clipboardExpand all lines: packages/google_sign_in/google_sign_in_web/README.md
+69-43Lines changed: 69 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
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)
5
+
## Migrating to v0.11 and v0.12 (Google Identity Services)
6
6
7
7
The `google_sign_in_web` plugin is backed by the new Google Identity Services
8
8
(GIS) JS SDK since version 0.11.0.
@@ -27,15 +27,12 @@ quickly and easily sign users into your app suing their Google accounts.
27
27
flows will not return authentication information.
28
28
* The GIS SDK no longer has direct access to previously-seen users upon initialization.
29
29
*`signInSilently` now displays the One Tap UX for web.
30
-
* The GIS SDK only provides an `idToken` (JWT-encoded info) when the user
31
-
successfully completes an authentication flow. In the plugin: `signInSilently`.
32
-
* The plugin `signIn` method uses the Oauth "Implicit Flow" to Authorize the requested `scopes`.
33
-
* If the user hasn't `signInSilently`, they'll have to sign in as a first step
34
-
of the Authorization popup flow.
35
-
* If `signInSilently` was unsuccessful, the plugin will add extra `scopes` to
36
-
`signIn` and retrieve basic Profile information from the People API via a
37
-
REST call immediately after a successful authorization. In this case, the
38
-
`idToken` field of the `GoogleSignInUserData` will always be null.
30
+
***Since 0.12** The plugin provides an `idToken` (JWT-encoded info) when the
31
+
user successfully completes an authentication flow:
32
+
* In the plugin: `signInSilently` and through the web-only `renderButton` widget.
33
+
* The plugin `signIn` method uses the OAuth "Implicit Flow" to Authorize the requested `scopes`.
34
+
* This method only provides an `accessToken`, and not an `idToken`, so if your
35
+
app needs an `idToken`, this method **should be avoided on the web**.
39
36
* The GIS SDK no longer handles sign-in state and user sessions, it only provides
40
37
Authentication credentials for the moment the user did authenticate.
41
38
* The GIS SDK no longer is able to renew Authorization sessions on the web.
@@ -49,48 +46,74 @@ See more differences in the following migration guides:
49
46
50
47
### New use cases to take into account in your app
51
48
52
-
#### Enable access to the People API for your GCP project
49
+
#### Authentication != Authorization
50
+
51
+
In the GIS SDK, the concepts of Authentication and Authorization have been separated.
52
+
53
+
It is possible now to have an Authenticated user that hasn't Authorized any `scopes`.
54
+
55
+
Flutter apps that need to run in the web must now handle the fact that an Authenticated
56
+
user may not have permissions to access the `scopes` it requires to function.
57
+
58
+
The Google Sign In plugin has a new `canAccessScopes` method that can be used to
59
+
check if a user is Authorized or not.
60
+
61
+
It is also possible that Authorizations expire while users are using an app
62
+
(after 3600 seconds), so apps should monitor response failures from the APIs, and
63
+
prompt users (interactively) to grant permissions again.
64
+
65
+
Check the "Integration considerations > [UX separation for authentication and authorization](https://developers.google.com/identity/gsi/web/guides/integrate#ux_separation_for_authentication_and_authorization)
66
+
guide" in the official GIS SDK documentation for more information about this.
53
67
54
-
Since the GIS SDK is separating Authentication from Authorization, the
The GIS-backed plugin always returns `null` from `signInSilently`, to force apps
80
-
that expect the former logic to perform a full `signIn`, which will result in a
81
-
fully Authenticated and Authorized user, and making this migration easier.
90
+
The drawback of this approach is that the OAuth flow **only returns an `accessToken`**,
91
+
and a synthetic version of the User Data, that does **not include an `idToken`**.
82
92
83
-
#### `idToken` is `null` in the `GoogleSignInAccount` object after `signIn`
93
+
The solution to this is to **migrate your custom "Sign In" buttons in the web to
94
+
the Button Widget provided by this package: `Widget renderButton()`.**
84
95
85
-
Since the GIS SDK is separating Authentication and Authorization, when a user
86
-
fails to Authenticate through `signInSilently` and the plugin performs the
87
-
fallback request to the People API described above,
88
-
the returned `GoogleSignInUserData` object will contain basic profile information
89
-
(name, email, photo, ID), but its `idToken` will be `null`.
96
+
_(Check the [package:google_sign_in example app](https://pub.dev/packages/google_sign_in/example)
97
+
for an example on how to mix the `renderButton` widget on the web, with a custom
98
+
button for the mobile.)_
90
99
91
-
This is because JWT are cryptographically signed by Google Identity Services, and
92
-
this plugin won't spoof that signature when it retrieves the information from a
93
-
simple REST request.
100
+
#### Enable access to the People API for your GCP project
101
+
102
+
If you want to use the `signIn` method on the web, the plugin will do an additional
103
+
request to the PeopleAPI to retrieve the logged-in user information (minus the `idToken`).
104
+
105
+
For this to work, you must enable access to the People API on your Client ID in
106
+
the GCP console.
107
+
108
+
This is **not recommended**. Ideally, your web application should use a mix of
109
+
`signInSilently` and the Google Sign In web `renderButton` to authenticate your
110
+
users, and then `canAccessScopes` and `requestScopes` to authorize the `scopes`
111
+
that are needed.
112
+
113
+
#### Why is the `idToken` missing after `signIn`?
114
+
115
+
The `idToken` is cryptographically signed by Google Identity Services, and
116
+
this plugin can't spoof that signature.
94
117
95
118
#### User Sessions
96
119
@@ -113,8 +136,8 @@ codes different to `200`. For example:
113
136
*`401`: Missing or invalid access token.
114
137
*`403`: Expired access token.
115
138
116
-
In either case, your app needs to prompt the end user to `signIn` or
117
-
`requestScopes`, to interactively renew the token.
139
+
In either case, your app needs to prompt the end user to `requestScopes`, to
140
+
**interactively** renew the token.
118
141
119
142
The GIS SDK limits authorization token duration to one hour (3600 seconds).
120
143
@@ -130,6 +153,9 @@ so you do not need to add it to your `pubspec.yaml`.
130
153
However, if you `import` this package to use any of its APIs directly, you
131
154
should add it to your `pubspec.yaml` as usual.
132
155
156
+
For example, you need to import this package directly if you plan to use the
157
+
web-only `Widget renderButton()` method.
158
+
133
159
### Web integration
134
160
135
161
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.
0 commit comments