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

[google_sign_in] adds option to re-authenticate on google silent sign in #4251

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/google_sign_in/google_sign_in/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## NEXT
## 5.1.0

* Add reAuthenticate option to signInSilently to allow re-authentication to be requested

* Updated Android lint settings.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -327,10 +329,11 @@ class GoogleSignIn {
/// (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;
Expand Down
2 changes: 1 addition & 1 deletion packages/google_sign_in/google_sign_in/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,22 @@ void main() {
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) {
Expand Down