adds option to re-authenticate on google silent sign in (#4251)
diff --git a/packages/google_sign_in/google_sign_in/CHANGELOG.md b/packages/google_sign_in/google_sign_in/CHANGELOG.md
index 8ac07ae..1f0be2e 100644
--- a/packages/google_sign_in/google_sign_in/CHANGELOG.md
+++ b/packages/google_sign_in/google_sign_in/CHANGELOG.md
@@ -1,4 +1,6 @@
-## NEXT
+## 5.1.0
+
+* Add reAuthenticate option to signInSilently to allow re-authentication to be requested
* Updated Android lint settings.
diff --git a/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart b/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart
index b45b09c..04d60fb 100644
--- a/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart
+++ b/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart
@@ -314,11 +314,13 @@
/// successful sign in or `null` if there is no previously authenticated user.
/// Use [signIn] method to trigger interactive sign in process.
///
- /// Authentication process is triggered only if there is no currently signed in
+ /// Authentication is triggered if there is no currently signed in
/// user (that is when `currentUser == null`), otherwise this method returns
/// a Future which resolves to the same user instance.
///
- /// Re-authentication can be triggered only after [signOut] or [disconnect].
+ /// Re-authentication can be triggered after [signOut] or [disconnect]. It can
+ /// also be triggered by setting [reAuthenticate] to `true` if a new ID token
+ /// is required.
///
/// When [suppressErrors] is set to `false` and an error occurred during sign in
/// returned Future completes with [PlatformException] whose `code` can be
@@ -327,10 +329,11 @@
/// (when an unknown error occurred).
Future<GoogleSignInAccount?> signInSilently({
bool suppressErrors = true,
+ bool reAuthenticate = false,
}) async {
try {
return await _addMethodCall(GoogleSignInPlatform.instance.signInSilently,
- canSkipCall: true);
+ canSkipCall: !reAuthenticate);
} catch (_) {
if (suppressErrors) {
return null;
diff --git a/packages/google_sign_in/google_sign_in/pubspec.yaml b/packages/google_sign_in/google_sign_in/pubspec.yaml
index 7e3f221..7900937 100644
--- a/packages/google_sign_in/google_sign_in/pubspec.yaml
+++ b/packages/google_sign_in/google_sign_in/pubspec.yaml
@@ -3,7 +3,7 @@
for signing in with a Google account on Android and iOS.
repository: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
-version: 5.0.7
+version: 5.1.0
environment:
sdk: ">=2.12.0 <3.0.0"
diff --git a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart
index f642bcd..444edc4 100644
--- a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart
+++ b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart
@@ -281,6 +281,22 @@
throwsA(isInstanceOf<PlatformException>()));
});
+ test('signInSilently allows re-authentication to be requested', () async {
+ await googleSignIn.signInSilently();
+ expect(googleSignIn.currentUser, isNotNull);
+
+ await googleSignIn.signInSilently(reAuthenticate: true);
+
+ expect(
+ log,
+ <Matcher>[
+ _isSignInMethodCall(),
+ isMethodCall('signInSilently', arguments: null),
+ isMethodCall('signInSilently', arguments: null),
+ ],
+ );
+ });
+
test('can sign in after init failed before', () async {
int initCount = 0;
channel.setMockMethodCallHandler((MethodCall methodCall) {