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

Commit 0857331

Browse files
authored
adds option to re-authenticate on google silent sign in (#4251)
1 parent 2aa9a09 commit 0857331

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

packages/google_sign_in/google_sign_in/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
## NEXT
1+
## 5.1.0
2+
3+
* Add reAuthenticate option to signInSilently to allow re-authentication to be requested
24

35
* Updated Android lint settings.
46

packages/google_sign_in/google_sign_in/lib/google_sign_in.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,13 @@ class GoogleSignIn {
314314
/// successful sign in or `null` if there is no previously authenticated user.
315315
/// Use [signIn] method to trigger interactive sign in process.
316316
///
317-
/// Authentication process is triggered only if there is no currently signed in
317+
/// Authentication is triggered if there is no currently signed in
318318
/// user (that is when `currentUser == null`), otherwise this method returns
319319
/// a Future which resolves to the same user instance.
320320
///
321-
/// Re-authentication can be triggered only after [signOut] or [disconnect].
321+
/// Re-authentication can be triggered after [signOut] or [disconnect]. It can
322+
/// also be triggered by setting [reAuthenticate] to `true` if a new ID token
323+
/// is required.
322324
///
323325
/// When [suppressErrors] is set to `false` and an error occurred during sign in
324326
/// returned Future completes with [PlatformException] whose `code` can be
@@ -327,10 +329,11 @@ class GoogleSignIn {
327329
/// (when an unknown error occurred).
328330
Future<GoogleSignInAccount?> signInSilently({
329331
bool suppressErrors = true,
332+
bool reAuthenticate = false,
330333
}) async {
331334
try {
332335
return await _addMethodCall(GoogleSignInPlatform.instance.signInSilently,
333-
canSkipCall: true);
336+
canSkipCall: !reAuthenticate);
334337
} catch (_) {
335338
if (suppressErrors) {
336339
return null;

packages/google_sign_in/google_sign_in/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system
33
for signing in with a Google account on Android and iOS.
44
repository: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
6-
version: 5.0.7
6+
version: 5.1.0
77

88
environment:
99
sdk: ">=2.12.0 <3.0.0"

packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,22 @@ void main() {
281281
throwsA(isInstanceOf<PlatformException>()));
282282
});
283283

284+
test('signInSilently allows re-authentication to be requested', () async {
285+
await googleSignIn.signInSilently();
286+
expect(googleSignIn.currentUser, isNotNull);
287+
288+
await googleSignIn.signInSilently(reAuthenticate: true);
289+
290+
expect(
291+
log,
292+
<Matcher>[
293+
_isSignInMethodCall(),
294+
isMethodCall('signInSilently', arguments: null),
295+
isMethodCall('signInSilently', arguments: null),
296+
],
297+
);
298+
});
299+
284300
test('can sign in after init failed before', () async {
285301
int initCount = 0;
286302
channel.setMockMethodCallHandler((MethodCall methodCall) {

0 commit comments

Comments
 (0)