From fb3e0e9b88c74ec0540ed8ac9acfa733257ff885 Mon Sep 17 00:00:00 2001 From: ambernardino Date: Tue, 4 Jun 2019 20:08:03 +0100 Subject: [PATCH 1/8] Update google_sign_in.dart --- .../google_sign_in/lib/google_sign_in.dart | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/packages/google_sign_in/lib/google_sign_in.dart b/packages/google_sign_in/lib/google_sign_in.dart index 740188fd8767..3ff788fedcba 100755 --- a/packages/google_sign_in/lib/google_sign_in.dart +++ b/packages/google_sign_in/lib/google_sign_in.dart @@ -18,7 +18,7 @@ enum SignInOption { standard, games } class GoogleSignInAuthentication { GoogleSignInAuthentication._(this._data); - final Map _data; + final Map _data; /// An OpenID Connect ID token that identifies the user. String get idToken => _data['idToken']; @@ -31,12 +31,13 @@ class GoogleSignInAuthentication { } class GoogleSignInAccount implements GoogleIdentity { - GoogleSignInAccount._(this._googleSignIn, Map data) + GoogleSignInAccount._(this._googleSignIn, Map data) : displayName = data['displayName'], email = data['email'], id = data['id'], photoUrl = data['photoUrl'], - _idToken = data['idToken'] { + _idToken = data['idToken'], + authCode = data['authCode'] { assert(id != null); } @@ -60,6 +61,8 @@ class GoogleSignInAccount implements GoogleIdentity { @override final String photoUrl; + final String authCode; + final String _idToken; final GoogleSignIn _googleSignIn; @@ -78,8 +81,11 @@ class GoogleSignInAccount implements GoogleIdentity { throw StateError('User is no longer signed in.'); } - final Map response = - await GoogleSignIn.channel.invokeMapMethod( + final Map response = + // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. + // https://github.com/flutter/flutter/issues/26431 + // ignore: strong_mode_implicit_dynamic_method + await GoogleSignIn.channel.invokeMethod( 'getTokens', { 'email': email, @@ -108,7 +114,10 @@ class GoogleSignInAccount implements GoogleIdentity { /// this method and grab `authHeaders` once again. Future clearAuthCache() async { final String token = (await authentication).accessToken; - await GoogleSignIn.channel.invokeMethod( + // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. + // https://github.com/flutter/flutter/issues/26431 + // ignore: strong_mode_implicit_dynamic_method + await GoogleSignIn.channel.invokeMethod( 'clearAuthCache', {'token': token}, ); @@ -157,14 +166,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 +212,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(); @@ -214,8 +228,10 @@ class GoogleSignIn { Future _callMethod(String method) async { await _ensureInitialized(); - final Map response = - await channel.invokeMapMethod(method); + // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. + // https://github.com/flutter/flutter/issues/26431 + // ignore: strong_mode_implicit_dynamic_method + final Map response = await channel.invokeMethod(method); return _setCurrentUser(response != null && response.isNotEmpty ? GoogleSignInAccount._(this, response) : null); @@ -231,10 +247,14 @@ class GoogleSignIn { Future _ensureInitialized() { if (_initialization == null) { - _initialization = channel.invokeMethod('init', { + // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. + // https://github.com/flutter/flutter/issues/26431 + // ignore: strong_mode_implicit_dynamic_method + _initialization = channel.invokeMethod('init', { 'signInOption': (signInOption ?? SignInOption.standard).toString(), 'scopes': scopes ?? [], 'hostedDomain': hostedDomain, + 'requestAuthCode' : requestAuthCode, }) ..catchError((dynamic _) { // Invalidate initialization if it errored out. @@ -307,7 +327,11 @@ class GoogleSignIn { /// Returns a future that resolves to whether a user is currently signed in. Future isSignedIn() async { await _ensureInitialized(); - return await channel.invokeMethod('isSignedIn'); + // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. + // https://github.com/flutter/flutter/issues/26431 + // ignore: strong_mode_implicit_dynamic_method + final bool result = await channel.invokeMethod('isSignedIn'); + return result; } /// Starts the interactive sign-in process. From 7e0cbefb47d52ce1954bf819be1f5c1f2376f272 Mon Sep 17 00:00:00 2001 From: ambernardino Date: Tue, 4 Jun 2019 20:08:34 +0100 Subject: [PATCH 2/8] Update GoogleSignInPlugin.java --- .../googlesignin/GoogleSignInPlugin.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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()); } From 79612c6e63240875fa892dd39977881b1f7c9920 Mon Sep 17 00:00:00 2001 From: ambernardino Date: Tue, 4 Jun 2019 20:15:26 +0100 Subject: [PATCH 3/8] Update google_sign_in.dart --- .../google_sign_in/lib/google_sign_in.dart | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/packages/google_sign_in/lib/google_sign_in.dart b/packages/google_sign_in/lib/google_sign_in.dart index 3ff788fedcba..523a0360b54d 100755 --- a/packages/google_sign_in/lib/google_sign_in.dart +++ b/packages/google_sign_in/lib/google_sign_in.dart @@ -18,7 +18,7 @@ enum SignInOption { standard, games } class GoogleSignInAuthentication { GoogleSignInAuthentication._(this._data); - final Map _data; + final Map _data; /// An OpenID Connect ID token that identifies the user. String get idToken => _data['idToken']; @@ -31,7 +31,7 @@ class GoogleSignInAuthentication { } class GoogleSignInAccount implements GoogleIdentity { - GoogleSignInAccount._(this._googleSignIn, Map data) + GoogleSignInAccount._(this._googleSignIn, Map data) : displayName = data['displayName'], email = data['email'], id = data['id'], @@ -61,6 +61,7 @@ class GoogleSignInAccount implements GoogleIdentity { @override final String photoUrl; + //TODO Always returns empty on IOS final String authCode; final String _idToken; @@ -82,9 +83,6 @@ class GoogleSignInAccount implements GoogleIdentity { } final Map response = - // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. - // https://github.com/flutter/flutter/issues/26431 - // ignore: strong_mode_implicit_dynamic_method await GoogleSignIn.channel.invokeMethod( 'getTokens', { @@ -114,9 +112,6 @@ class GoogleSignInAccount implements GoogleIdentity { /// this method and grab `authHeaders` once again. Future clearAuthCache() async { final String token = (await authentication).accessToken; - // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. - // https://github.com/flutter/flutter/issues/26431 - // ignore: strong_mode_implicit_dynamic_method await GoogleSignIn.channel.invokeMethod( 'clearAuthCache', {'token': token}, @@ -227,10 +222,7 @@ class GoogleSignIn { Future _callMethod(String method) async { await _ensureInitialized(); - - // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. - // https://github.com/flutter/flutter/issues/26431 - // ignore: strong_mode_implicit_dynamic_method + final Map response = await channel.invokeMethod(method); return _setCurrentUser(response != null && response.isNotEmpty ? GoogleSignInAccount._(this, response) @@ -247,9 +239,6 @@ class GoogleSignIn { Future _ensureInitialized() { if (_initialization == null) { - // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. - // https://github.com/flutter/flutter/issues/26431 - // ignore: strong_mode_implicit_dynamic_method _initialization = channel.invokeMethod('init', { 'signInOption': (signInOption ?? SignInOption.standard).toString(), 'scopes': scopes ?? [], @@ -327,9 +316,6 @@ class GoogleSignIn { /// Returns a future that resolves to whether a user is currently signed in. Future isSignedIn() async { await _ensureInitialized(); - // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. - // https://github.com/flutter/flutter/issues/26431 - // ignore: strong_mode_implicit_dynamic_method final bool result = await channel.invokeMethod('isSignedIn'); return result; } From f443fff76356b26f4198d41024a7522aa019af0d Mon Sep 17 00:00:00 2001 From: ambernardino Date: Tue, 4 Jun 2019 20:18:45 +0100 Subject: [PATCH 4/8] Update google_sign_in.dart --- packages/google_sign_in/lib/google_sign_in.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/google_sign_in/lib/google_sign_in.dart b/packages/google_sign_in/lib/google_sign_in.dart index 523a0360b54d..5dd7d3081411 100755 --- a/packages/google_sign_in/lib/google_sign_in.dart +++ b/packages/google_sign_in/lib/google_sign_in.dart @@ -83,7 +83,7 @@ class GoogleSignInAccount implements GoogleIdentity { } final Map response = - await GoogleSignIn.channel.invokeMethod( + await GoogleSignIn.channel.invokeMapMethod( 'getTokens', { 'email': email, @@ -112,7 +112,7 @@ class GoogleSignInAccount implements GoogleIdentity { /// this method and grab `authHeaders` once again. Future clearAuthCache() async { final String token = (await authentication).accessToken; - await GoogleSignIn.channel.invokeMethod( + await GoogleSignIn.channel.invokeMethod( 'clearAuthCache', {'token': token}, ); @@ -223,7 +223,8 @@ class GoogleSignIn { Future _callMethod(String method) async { await _ensureInitialized(); - final Map response = await channel.invokeMethod(method); + final Map response = + await channel.invokeMapMethod(method); return _setCurrentUser(response != null && response.isNotEmpty ? GoogleSignInAccount._(this, response) : null); @@ -239,7 +240,7 @@ class GoogleSignIn { Future _ensureInitialized() { if (_initialization == null) { - _initialization = channel.invokeMethod('init', { + _initialization = channel.invokeMethod('init', { 'signInOption': (signInOption ?? SignInOption.standard).toString(), 'scopes': scopes ?? [], 'hostedDomain': hostedDomain, @@ -316,8 +317,7 @@ class GoogleSignIn { /// Returns a future that resolves to whether a user is currently signed in. Future isSignedIn() async { await _ensureInitialized(); - final bool result = await channel.invokeMethod('isSignedIn'); - return result; + return await channel.invokeMethod('isSignedIn'); } /// Starts the interactive sign-in process. From 1862673da4562ce865a8f76c19a2143134e26b43 Mon Sep 17 00:00:00 2001 From: ambernardino Date: Tue, 4 Jun 2019 20:19:31 +0100 Subject: [PATCH 5/8] Update google_sign_in.dart --- packages/google_sign_in/lib/google_sign_in.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_sign_in/lib/google_sign_in.dart b/packages/google_sign_in/lib/google_sign_in.dart index 5dd7d3081411..6d78da4bfb46 100755 --- a/packages/google_sign_in/lib/google_sign_in.dart +++ b/packages/google_sign_in/lib/google_sign_in.dart @@ -82,7 +82,7 @@ class GoogleSignInAccount implements GoogleIdentity { throw StateError('User is no longer signed in.'); } - final Map response = + final Map response = await GoogleSignIn.channel.invokeMapMethod( 'getTokens', { From 8b2cc1896584320157e7b19fab01aad4eb4831ba Mon Sep 17 00:00:00 2001 From: ambernardino Date: Tue, 4 Jun 2019 20:27:47 +0100 Subject: [PATCH 6/8] Update CHANGELOG.md --- packages/google_sign_in/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/google_sign_in/CHANGELOG.md b/packages/google_sign_in/CHANGELOG.md index 0a4e8d21cca8..de5d181b9002 100644 --- a/packages/google_sign_in/CHANGELOG.md +++ b/packages/google_sign_in/CHANGELOG.md @@ -1,5 +1,9 @@ ## 4.0.2 +* Support to requesting serverAuthCode on Android + +## 4.0.2 + * Add missing template type parameter to `invokeMethod` calls. * Bump minimum Flutter version to 1.5.0. * Replace invokeMethod with invokeMapMethod wherever necessary. From df0288228a1bb1ac3894b9b3d6bf7b0cd3fbdc52 Mon Sep 17 00:00:00 2001 From: ambernardino Date: Tue, 4 Jun 2019 20:31:17 +0100 Subject: [PATCH 7/8] Update pubspec.yaml --- packages/google_sign_in/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From b247ad6c1dbce86bd2e9adeab3dffa34d244f2d6 Mon Sep 17 00:00:00 2001 From: ambernardino Date: Tue, 4 Jun 2019 20:32:02 +0100 Subject: [PATCH 8/8] Update CHANGELOG.md --- packages/google_sign_in/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_sign_in/CHANGELOG.md b/packages/google_sign_in/CHANGELOG.md index de5d181b9002..23ba5809166e 100644 --- a/packages/google_sign_in/CHANGELOG.md +++ b/packages/google_sign_in/CHANGELOG.md @@ -1,4 +1,4 @@ -## 4.0.2 +## 4.0.3 * Support to requesting serverAuthCode on Android