From 0a868b4b491cf0c19e7bc8a6311a786d9ae0f8b6 Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Sun, 20 Dec 2020 11:17:25 -0600 Subject: [PATCH 1/4] [force-code-for-refresh-token] Add configurable option for 'forceCodeForRefreshToken' on Android --- AUTHORS | 1 + packages/google_sign_in/google_sign_in/CHANGELOG.md | 4 ++++ packages/google_sign_in/google_sign_in/README.md | 7 ++++++- .../plugins/googlesignin/GoogleSignInPlugin.java | 13 ++++++++++++- .../android/app/src/main/res/values/bools.xml | 4 ++++ .../google_sign_in/lib/google_sign_in.dart | 7 ++++++- packages/google_sign_in/google_sign_in/pubspec.yaml | 4 ++-- 7 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 packages/google_sign_in/google_sign_in/example/android/app/src/main/res/values/bools.xml diff --git a/AUTHORS b/AUTHORS index 51345c9a3481..16b7069666d5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -59,3 +59,4 @@ Kazuki Yamaguchi Eitan Schwartz Chris Rutkowski Juan Alvarez +Twin Sun, LLC diff --git a/packages/google_sign_in/google_sign_in/CHANGELOG.md b/packages/google_sign_in/google_sign_in/CHANGELOG.md index 8a4dd6bc817e..1ebc1b17646b 100644 --- a/packages/google_sign_in/google_sign_in/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.5.9 + +* Add `force_code_for_refresh_token` option for Android + ## 4.5.8 * Fix outdated links across a number of markdown files ([#3276](https://github.com/flutter/plugins/pull/3276)) diff --git a/packages/google_sign_in/google_sign_in/README.md b/packages/google_sign_in/google_sign_in/README.md index 61c4380cdcb7..e47c3e8d9cd9 100755 --- a/packages/google_sign_in/google_sign_in/README.md +++ b/packages/google_sign_in/google_sign_in/README.md @@ -4,7 +4,7 @@ A Flutter plugin for [Google Sign In](https://developers.google.com/identity/). -*Note*: This plugin is still under development, and some APIs might not be available yet. [Feedback](https://github.com/flutter/flutter/issues) and [Pull Requests](https://github.com/flutter/plugins/pulls) are most welcome! +_Note_: This plugin is still under development, and some APIs might not be available yet. [Feedback](https://github.com/flutter/flutter/issues) and [Pull Requests](https://github.com/flutter/plugins/pulls) are most welcome! ## Android integration @@ -20,6 +20,8 @@ enable the [Google People API](https://developers.google.com/people/). Make sure you've filled out all required fields in the console for [OAuth consent screen](https://console.developers.google.com/apis/credentials/consent). Otherwise, you may encounter `APIException` errors. +If you need to force a server auth code to include a refresh token when exchanged for an access token, set `force_code_for_refresh_token` to true as in `google_sign_in/example/android/app/src/main/res/values/bools.xml`. + ## iOS integration 1. [First register your application](https://developers.google.com/mobile/add?platform=ios). @@ -63,9 +65,11 @@ plugin could be an option. ## Usage ### Import the package + To use this plugin, follow the [plugin installation instructions](https://pub.dev/packages/google_sign_in#pub-pkg-tab-installing). ### Use the plugin + Add the following import to your Dart code: ```dart @@ -82,6 +86,7 @@ GoogleSignIn _googleSignIn = GoogleSignIn( ], ); ``` + [Full list of available scopes](https://developers.google.com/identity/protocols/googlescopes). You can now use the `GoogleSignIn` class to authenticate in your Dart code, e.g. diff --git a/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java b/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java index dab6f4c4db8e..3633a33023a5 100755 --- a/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java +++ b/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java @@ -336,7 +336,18 @@ public void init( .getIdentifier("default_web_client_id", "string", context.getPackageName()); if (clientIdIdentifier != 0) { optionsBuilder.requestIdToken(context.getString(clientIdIdentifier)); - optionsBuilder.requestServerAuthCode(context.getString(clientIdIdentifier)); + + boolean forceCodeForRefreshToken = false; + int forceCodeForRefreshTokenIdentifier = + context + .getResources() + .getIdentifier("force_code_for_refresh_token", "bool", context.getPackageName()); + if (forceCodeForRefreshTokenIdentifier != 0) { + forceCodeForRefreshToken = + context.getResources().getBoolean(forceCodeForRefreshTokenIdentifier); + } + optionsBuilder.requestServerAuthCode( + context.getString(clientIdIdentifier), forceCodeForRefreshToken); } for (String scope : requestedScopes) { optionsBuilder.requestScopes(new Scope(scope)); diff --git a/packages/google_sign_in/google_sign_in/example/android/app/src/main/res/values/bools.xml b/packages/google_sign_in/google_sign_in/example/android/app/src/main/res/values/bools.xml new file mode 100644 index 000000000000..c4c2db4aa1eb --- /dev/null +++ b/packages/google_sign_in/google_sign_in/example/android/app/src/main/res/values/bools.xml @@ -0,0 +1,4 @@ + + + false + 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 0f1f15bbb8c4..1adf546f1c38 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 @@ -44,7 +44,8 @@ class GoogleSignInAccount implements GoogleIdentity { email = data.email, id = data.id, photoUrl = data.photoUrl, - _idToken = data.idToken { + _idToken = data.idToken, + _serverAuthCode = data.serverAuthCode { assert(id != null); } @@ -70,6 +71,7 @@ class GoogleSignInAccount implements GoogleIdentity { final String _idToken; final GoogleSignIn _googleSignIn; + final String _serverAuthCode; /// Retrieve [GoogleSignInAuthentication] for this account. /// @@ -97,6 +99,9 @@ class GoogleSignInAccount implements GoogleIdentity { if (response.idToken == null) { response.idToken = _idToken; } + if (response.serverAuthCode == null) { + response.serverAuthCode = _serverAuthCode; + } return GoogleSignInAuthentication._(response); } diff --git a/packages/google_sign_in/google_sign_in/pubspec.yaml b/packages/google_sign_in/google_sign_in/pubspec.yaml index b99b231adb9d..e39db5826929 100644 --- a/packages/google_sign_in/google_sign_in/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in/pubspec.yaml @@ -2,7 +2,7 @@ name: google_sign_in description: Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android and iOS. homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in -version: 4.5.8 +version: 4.5.9 flutter: plugin: @@ -16,7 +16,7 @@ flutter: default_package: google_sign_in_web dependencies: - google_sign_in_platform_interface: ^1.1.1 + google_sign_in_platform_interface: ^1.2.0 flutter: sdk: flutter meta: ^1.0.4 From a09c3f52cd2a506817d73735a28a5b1361a2cd2e Mon Sep 17 00:00:00 2001 From: Jami Couch Date: Sun, 20 Dec 2020 14:09:30 -0600 Subject: [PATCH 2/4] [force-code-for-refresh-token] Add serverAuthCode to GoogleSignInUserData --- .../CHANGELOG.md | 4 ++++ .../lib/src/types.dart | 17 +++++++++++++---- .../lib/src/utils.dart | 3 ++- .../pubspec.yaml | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md b/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md index e69e912195bf..47555dcf199d 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.2.0 + +* Add serverAuthCode to GoogleSignInUserData + ## 1.1.3 * Update Flutter SDK constraint. diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart index c60402200bdd..9f080f602ff4 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart @@ -27,7 +27,12 @@ class GoogleSignInUserData { /// Uses the given data to construct an instance. Any of these parameters /// could be null. GoogleSignInUserData( - {this.displayName, this.email, this.id, this.photoUrl, this.idToken}); + {this.displayName, + this.email, + this.id, + this.photoUrl, + this.idToken, + this.serverAuthCode}); /// The display name of the signed in user. /// @@ -62,9 +67,12 @@ class GoogleSignInUserData { /// data. String idToken; + /// An auth code which can be exchanged by a backend server for an access token and refresh token + String serverAuthCode; + @override - int get hashCode => - hashObjects([displayName, email, id, photoUrl, idToken]); + int get hashCode => hashObjects( + [displayName, email, id, photoUrl, idToken, serverAuthCode]); @override bool operator ==(dynamic other) { @@ -75,7 +83,8 @@ class GoogleSignInUserData { otherUserData.email == email && otherUserData.id == id && otherUserData.photoUrl == photoUrl && - otherUserData.idToken == idToken; + otherUserData.idToken == idToken && + otherUserData.serverAuthCode == serverAuthCode; } } diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/utils.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/utils.dart index 1ae828604af6..548e3e951c97 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/utils.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/utils.dart @@ -14,7 +14,8 @@ GoogleSignInUserData getUserDataFromMap(Map data) { email: data['email'], id: data['id'], photoUrl: data['photoUrl'], - idToken: data['idToken']); + idToken: data['idToken'], + serverAuthCode: data['serverAuthCode']); } /// Converts token data coming from native code into the proper platform interface type. diff --git a/packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml b/packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml index 8edeba0072a8..47a06e878528 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the google_sign_in plugin. homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 1.1.3 +version: 1.2.0 dependencies: flutter: From 10bdf6882bddffcd1098e7218b776f127e2f5922 Mon Sep 17 00:00:00 2001 From: dreenot Date: Tue, 27 Apr 2021 02:48:07 -0300 Subject: [PATCH 3/4] Updating fix to get serverAuthCode Many changes were made after the PR of commit 0a868b4. I kept the new data when I merged it before this commit, so a few minimal changes were needed to keep it working with master. It's currently getting the serverAuthCode instead of returning null and forceCodeForRefreshToken is now an option. --- AUTHORS | 2 ++ .../google_sign_in/google_sign_in/lib/google_sign_in.dart | 2 +- .../google_sign_in_platform_interface/lib/src/types.dart | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 0ca697b6a756..63b5000301e7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -65,3 +65,5 @@ Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> Daniel Roek +Twin Sun, LLC +Andrew Cardinot \ No newline at end of file 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 42354a03f920..52cb4cb34512 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 @@ -71,7 +71,7 @@ class GoogleSignInAccount implements GoogleIdentity { final String? _idToken; final GoogleSignIn _googleSignIn; - final String _serverAuthCode; + final String? _serverAuthCode; /// Retrieve [GoogleSignInAuthentication] for this account. /// diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart index 61231d1b70b9..c572d905952c 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart @@ -31,8 +31,12 @@ class GoogleSignInUserData { this.displayName, this.photoUrl, this.idToken, + this.serverAuthCode }); + /// Used to perform server-side actions with Google API + String? serverAuthCode; + /// The display name of the signed in user. /// /// Not guaranteed to be present for all users, even when configured. From 8cdce442a189341d581486e07a37a019aa8a600c Mon Sep 17 00:00:00 2001 From: dreenot Date: Tue, 27 Apr 2021 02:48:07 -0300 Subject: [PATCH 4/4] Updating fix to get serverAuthCode Many changes were made after the PR of commit 0a868b4. I kept the new data when I merged it before this commit, so a few minimal changes were needed to keep it working with master. It's currently getting the serverAuthCode instead of returning null and forceCodeForRefreshToken is now an option. --- AUTHORS | 2 ++ packages/google_sign_in/google_sign_in/CHANGELOG.md | 4 ++++ .../google_sign_in/google_sign_in/lib/google_sign_in.dart | 2 +- packages/google_sign_in/google_sign_in/pubspec.yaml | 2 +- .../google_sign_in_platform_interface/lib/src/types.dart | 4 ++++ 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 0ca697b6a756..63b5000301e7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -65,3 +65,5 @@ Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> Daniel Roek +Twin Sun, LLC +Andrew Cardinot \ No newline at end of file diff --git a/packages/google_sign_in/google_sign_in/CHANGELOG.md b/packages/google_sign_in/google_sign_in/CHANGELOG.md index 4e8ed80cba9c..d1fe382fadf1 100644 --- a/packages/google_sign_in/google_sign_in/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.3 + +* Add `force_code_for_refresh_token` option for Android, returns the right serverAuthCode + ## 5.0.2 * Fix flutter/flutter#48602 iOS flow shows account selection, if user is signed in to Google on the device. 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 42354a03f920..52cb4cb34512 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 @@ -71,7 +71,7 @@ class GoogleSignInAccount implements GoogleIdentity { final String? _idToken; final GoogleSignIn _googleSignIn; - final String _serverAuthCode; + final String? _serverAuthCode; /// Retrieve [GoogleSignInAuthentication] for this account. /// diff --git a/packages/google_sign_in/google_sign_in/pubspec.yaml b/packages/google_sign_in/google_sign_in/pubspec.yaml index 388814bb1409..9c0159c15f0b 100644 --- a/packages/google_sign_in/google_sign_in/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in/pubspec.yaml @@ -2,7 +2,7 @@ name: google_sign_in description: Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android and iOS. homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in -version: 5.0.2 +version: 5.0.3 flutter: plugin: diff --git a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart index 61231d1b70b9..c572d905952c 100644 --- a/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart +++ b/packages/google_sign_in/google_sign_in_platform_interface/lib/src/types.dart @@ -31,8 +31,12 @@ class GoogleSignInUserData { this.displayName, this.photoUrl, this.idToken, + this.serverAuthCode }); + /// Used to perform server-side actions with Google API + String? serverAuthCode; + /// The display name of the signed in user. /// /// Not guaranteed to be present for all users, even when configured.