From b8278c95aedf9e81cd987e8fa9b7bed0c6fabf36 Mon Sep 17 00:00:00 2001 From: ThetaSinner Date: Fri, 20 Aug 2021 00:39:57 +0100 Subject: [PATCH] adds option to re-authenticate on google silent sign in --- .../google_sign_in/google_sign_in/CHANGELOG.md | 4 +++- .../google_sign_in/lib/google_sign_in.dart | 9 ++++++--- .../google_sign_in/google_sign_in/pubspec.yaml | 2 +- .../google_sign_in/test/google_sign_in_test.dart | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/CHANGELOG.md b/packages/google_sign_in/google_sign_in/CHANGELOG.md index 8ac07ae1793b..1f0be2e237b2 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 b45b09c2d7a7..04d60fbc7d21 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 @@ class GoogleSignIn { /// 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 @@ class GoogleSignIn { /// (when an unknown error occurred). Future 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 7e3f221716a8..79009373c5d1 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 @@ description: Flutter plugin for Google Sign-In, a secure authentication system 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 f642bcd2eaf8..444edc4336ce 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 @@ void main() { throwsA(isInstanceOf())); }); + test('signInSilently allows re-authentication to be requested', () async { + await googleSignIn.signInSilently(); + expect(googleSignIn.currentUser, isNotNull); + + await googleSignIn.signInSilently(reAuthenticate: true); + + expect( + log, + [ + _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) {