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.
[google_sign_in_web] Migrate to the GIS SDK. (#6921)
* [google_sign_in_web] Migrate to GIS SDK.
* include_granted_scopes in requestScopes call.
* Remove the old JS-interop layer.
* Introduce a mockable GisSdkClient for tests.
* Split the people utils.
* Delete tests for the old code.
* Add some tests for the new code.
* More utils_test.dart
* Make jsifyAs reusable.
* Ignore the tester in utils_test.dart
* Make Clients overridable, and some renaming.
* Test people.dart
* Make autoDetectedClientId more testable.
* Add mockito.
* Comment about where to better split the code so GisSdkClient is testable too.
* Add google_sign_in_web_test.dart (and its mocks)
* dart format
* Log only in debug.
* Sync min sdk with package gis_web
* Add migration notes to the README.
* When the user is known upon signIn, remove friction.
* Do not ask for user selection again in the authorization popup
* Pass the email of the known user as a hint to the signIn method
* Address PR comments / checks.
* Update migration guide after comments from testers.
* Update README.md
* Remove package:jose from tests.
* Rename to Vincent Adultman
* _isJsSdkLoaded -> _jsSdkLoadedFuture
* Remove idToken comment.
* Link issue to split mocking better.
* Remove dependency in package:jwt_decoder
* Remove unneeded cast call.
object that is returned after `signIn` completes successfully.
67
+
68
+
#### `signInSilently` always returns `null`
69
+
70
+
Previous versions of this plugin were able to return a `GoogleSignInAccount`
71
+
object that was fully populated (signed-in and authorized) from `signInSilently`
72
+
because the former SDK equated "is authenticated" and "is authorized".
73
+
74
+
With the GIS SDK, `signInSilently` only deals with user Authentication, so users
75
+
retrieved "silently" will only contain an `idToken`, but not an `accessToken`.
76
+
77
+
Only after `signIn` or `requestScopes`, a user will be fully formed.
78
+
79
+
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.
82
+
83
+
#### `idToken` is `null` in the `GoogleSignInAccount` object after `signIn`
84
+
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`.
90
+
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.
94
+
95
+
#### User Sessions
96
+
97
+
Since the GIS SDK does _not_ manage user sessions anymore, apps that relied on
98
+
this feature might break.
99
+
100
+
If long-lived sessions are required, consider using some user authentication
101
+
system that supports Google Sign In as a federated Authentication provider,
102
+
like [Firebase Auth](https://firebase.google.com/docs/auth/flutter/federated-auth#google),
103
+
or similar.
104
+
105
+
#### Expired / Invalid Authorization Tokens
106
+
107
+
Since the GIS SDK does _not_ auto-renew authorization tokens anymore, it's now
108
+
the responsibility of your app to do so.
109
+
110
+
Apps now need to monitor the status code of their REST API requests for response
111
+
codes different to `200`. For example:
112
+
113
+
*`401`: Missing or invalid access token.
114
+
*`403`: Expired access token.
115
+
116
+
In either case, your app needs to prompt the end user to `signIn` or
117
+
`requestScopes`, to interactively renew the token.
118
+
119
+
The GIS SDK limits authorization token duration to one hour (3600 seconds).
120
+
5
121
## Usage
6
122
7
123
### Import the package
@@ -12,7 +128,7 @@ normally. This package will be automatically included in your app when you do.
12
128
13
129
### Web integration
14
130
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.
131
+
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
132
17
133
On your `web/index.html` file, add the following `meta` tag, somewhere in the
18
134
`head` of the document:
@@ -29,7 +145,10 @@ You can do this by:
29
145
2. Clicking "Edit" in the OAuth 2.0 Web application client that you created above.
30
146
3. Adding the URIs you want to the **Authorized JavaScript origins**.
31
147
32
-
For local development, may add a `localhost` entry, for example: `http://localhost:7357`
148
+
For local development, you must add two `localhost` entries:
149
+
150
+
*`http://localhost` and
151
+
*`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.
169
+
See the [**Usage** instructions of `package:google_sign_in`](https://pub.dev/packages/google_sign_in#usage)
70
170
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
-
```
171
+
Note that the **`serverClientId` parameter of the `GoogleSignIn` constructor is not supported on Web.**
82
172
83
173
## Example
84
174
85
175
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
176
87
177
## API details
88
178
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.
179
+
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