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/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 3a63f785aa9f..afcea42461b1 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 @@ -348,7 +348,18 @@ public void init( optionsBuilder.requestServerAuthCode(clientId); } else 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 b45b09c2d7a7..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 @@ -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 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. 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 4a70ec4d25ef..0d89835fb498 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) { id: data['id']!, displayName: data['displayName'], 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.