diff --git a/packages/google_sign_in/CHANGELOG.md b/packages/google_sign_in/CHANGELOG.md index 0a4e8d21cca8..23ba5809166e 100644 --- a/packages/google_sign_in/CHANGELOG.md +++ b/packages/google_sign_in/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.0.3 + +* Support to requesting serverAuthCode on Android + ## 4.0.2 * Add missing template type parameter to `invokeMethod` calls. diff --git a/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java b/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java index d2fc260c7b1c..382237fc1d76 100755 --- a/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java +++ b/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java @@ -66,7 +66,8 @@ public void onMethodCall(MethodCall call, Result result) { String signInOption = call.argument("signInOption"); List requestedScopes = call.argument("scopes"); String hostedDomain = call.argument("hostedDomain"); - delegate.init(result, signInOption, requestedScopes, hostedDomain); + boolean requestAuthCode = call.argument("requestAuthCode"); + delegate.init(result, signInOption, requestedScopes, hostedDomain, requestAuthCode); break; case METHOD_SIGN_IN_SILENTLY: @@ -113,7 +114,7 @@ public void onMethodCall(MethodCall call, Result result) { public interface IDelegate { /** Initializes this delegate so that it is ready to perform other operations. */ public void init( - Result result, String signInOption, List requestedScopes, String hostedDomain); + Result result, String signInOption, List requestedScopes, String hostedDomain, boolean requestAuthCode); /** * Returns the account information for the user who is signed in to this app. If no user is @@ -210,7 +211,7 @@ private void checkAndSetPendingOperation(String method, Result result, Object da */ @Override public void init( - Result result, String signInOption, List requestedScopes, String hostedDomain) { + Result result, String signInOption, List requestedScopes, String hostedDomain, boolean requestAuthCode) { try { GoogleSignInOptions.Builder optionsBuilder; @@ -221,7 +222,8 @@ public void init( break; case DEFAULT_SIGN_IN: optionsBuilder = - new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail(); + new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) + .requestEmail(); break; default: throw new IllegalStateException("Unknown signInOption"); @@ -238,8 +240,13 @@ public void init( .getIdentifier( "default_web_client_id", "string", registrar.context().getPackageName()); if (clientIdIdentifier != 0) { - optionsBuilder.requestIdToken(registrar.context().getString(clientIdIdentifier)); + final String clientIdFromContext = registrar.context().getString(clientIdIdentifier); + optionsBuilder.requestIdToken(clientIdFromContext); + if (requestAuthCode) { + optionsBuilder.requestServerAuthCode(clientIdFromContext); + } } + for (String scope : requestedScopes) { optionsBuilder.requestScopes(new Scope(scope)); } @@ -361,6 +368,7 @@ private void onSignInAccount(GoogleSignInAccount account) { response.put("id", account.getId()); response.put("idToken", account.getIdToken()); response.put("displayName", account.getDisplayName()); + response.put("authCode", account.getServerAuthCode()); if (account.getPhotoUrl() != null) { response.put("photoUrl", account.getPhotoUrl().toString()); } diff --git a/packages/google_sign_in/lib/google_sign_in.dart b/packages/google_sign_in/lib/google_sign_in.dart index 740188fd8767..6d78da4bfb46 100755 --- a/packages/google_sign_in/lib/google_sign_in.dart +++ b/packages/google_sign_in/lib/google_sign_in.dart @@ -36,7 +36,8 @@ class GoogleSignInAccount implements GoogleIdentity { email = data['email'], id = data['id'], photoUrl = data['photoUrl'], - _idToken = data['idToken'] { + _idToken = data['idToken'], + authCode = data['authCode'] { assert(id != null); } @@ -60,6 +61,9 @@ class GoogleSignInAccount implements GoogleIdentity { @override final String photoUrl; + //TODO Always returns empty on IOS + final String authCode; + final String _idToken; final GoogleSignIn _googleSignIn; @@ -157,14 +161,16 @@ class GoogleSignIn { /// The [hostedDomain] argument specifies a hosted domain restriction. By /// setting this, sign in will be restricted to accounts of the user in the /// specified domain. By default, the list of accounts will not be restricted. - GoogleSignIn({this.signInOption, this.scopes, this.hostedDomain}); + GoogleSignIn({this.signInOption, this.scopes, this.hostedDomain, this.requestAuthCode = false}); /// Factory for creating default sign in user experience. - factory GoogleSignIn.standard({List scopes, String hostedDomain}) { + factory GoogleSignIn.standard({List scopes, String hostedDomain, bool requestAuthCode}) { return GoogleSignIn( signInOption: SignInOption.standard, scopes: scopes, - hostedDomain: hostedDomain); + hostedDomain: hostedDomain, + requestAuthCode: requestAuthCode, + ); } /// Factory for creating sign in suitable for games. This option must not be @@ -201,6 +207,9 @@ class GoogleSignIn { /// Domain to restrict sign-in to. final String hostedDomain; + /// Set if server-side login is required + final bool requestAuthCode; + StreamController _currentUserController = StreamController.broadcast(); @@ -213,9 +222,9 @@ class GoogleSignIn { Future _callMethod(String method) async { await _ensureInitialized(); - - final Map response = - await channel.invokeMapMethod(method); + + final Map response = + await channel.invokeMapMethod(method); return _setCurrentUser(response != null && response.isNotEmpty ? GoogleSignInAccount._(this, response) : null); @@ -235,6 +244,7 @@ class GoogleSignIn { 'signInOption': (signInOption ?? SignInOption.standard).toString(), 'scopes': scopes ?? [], 'hostedDomain': hostedDomain, + 'requestAuthCode' : requestAuthCode, }) ..catchError((dynamic _) { // Invalidate initialization if it errored out. diff --git a/packages/google_sign_in/pubspec.yaml b/packages/google_sign_in/pubspec.yaml index 4a14005956ca..f9c18839b048 100755 --- a/packages/google_sign_in/pubspec.yaml +++ b/packages/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. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in -version: 4.0.2 +version: 4.0.3 flutter: plugin: