diff --git a/AUTHORS b/AUTHORS index 7d26d11e1d4c..fe82a109bdfc 100644 --- a/AUTHORS +++ b/AUTHORS @@ -26,3 +26,4 @@ Sarthak Verma Mike Diarmid Invertase Elliot Hesp +Twin Sun, LLC 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..879ebbfc1dbf 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); + String serverClientId = call.argument("serverClientId"); + delegate.init(result, signInOption, requestedScopes, hostedDomain, serverClientId); break; case METHOD_SIGN_IN_SILENTLY: @@ -113,7 +114,11 @@ 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, + String serverClientId); /** * Returns the account information for the user who is signed in to this app. If no user is @@ -210,7 +215,11 @@ 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, + String serverClientId) { try { GoogleSignInOptions.Builder optionsBuilder; @@ -246,6 +255,10 @@ public void init( if (!Strings.isNullOrEmpty(hostedDomain)) { optionsBuilder.setHostedDomain(hostedDomain); } + if (!Strings.isNullOrEmpty(serverClientId)) { + optionsBuilder.requestServerAuthCode(serverClientId, true); + optionsBuilder.requestIdToken(serverClientId); + } this.requestedScopes = requestedScopes; signInClient = GoogleSignIn.getClient(registrar.context(), optionsBuilder.build()); @@ -361,6 +374,7 @@ private void onSignInAccount(GoogleSignInAccount account) { response.put("id", account.getId()); response.put("idToken", account.getIdToken()); response.put("displayName", account.getDisplayName()); + response.put("serverAuthCode", account.getServerAuthCode()); if (account.getPhotoUrl() != null) { response.put("photoUrl", account.getPhotoUrl().toString()); } diff --git a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m index 483bc5c6e81c..bfae40d25ec4 100644 --- a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m +++ b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m @@ -75,6 +75,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [GIDSignIn sharedInstance].clientID = plist[kClientIdKey]; [GIDSignIn sharedInstance].scopes = call.arguments[@"scopes"]; [GIDSignIn sharedInstance].hostedDomain = call.arguments[@"hostedDomain"]; + if (![call.arguments[@"serverClientId"] isEqual:[NSNull null]]) { + [GIDSignIn sharedInstance].serverClientID = call.arguments[@"serverClientId"]; + } result(nil); } else { result([FlutterError errorWithCode:@"missing-config" @@ -173,6 +176,7 @@ - (void)signIn:(GIDSignIn *)signIn @"email" : user.profile.email ?: [NSNull null], @"id" : user.userID ?: [NSNull null], @"photoUrl" : [photoUrl absoluteString] ?: [NSNull null], + @"serverAuthCode" : user.serverAuthCode ?: [NSNull null] } error:nil]; } diff --git a/packages/google_sign_in/lib/google_sign_in.dart b/packages/google_sign_in/lib/google_sign_in.dart index 234eb5102da2..b1257bd4a2b1 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'], + serverAuthCode = data['serverAuthCode'] { assert(id != null); } @@ -62,6 +63,7 @@ class GoogleSignInAccount implements GoogleIdentity { final String _idToken; final GoogleSignIn _googleSignIn; + final String serverAuthCode; /// Retrieve [GoogleSignInAuthentication] for this account. /// @@ -163,14 +165,17 @@ 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.serverClientId}); /// Factory for creating default sign in user experience. - factory GoogleSignIn.standard({List scopes, String hostedDomain}) { + factory GoogleSignIn.standard( + {List scopes, String hostedDomain, String serverClientId}) { return GoogleSignIn( signInOption: SignInOption.standard, scopes: scopes, - hostedDomain: hostedDomain); + hostedDomain: hostedDomain, + serverClientId: serverClientId); } /// Factory for creating sign in suitable for games. This option must not be @@ -207,6 +212,8 @@ class GoogleSignIn { /// Domain to restrict sign-in to. final String hostedDomain; + final String serverClientId; + StreamController _currentUserController = StreamController.broadcast(); @@ -246,6 +253,7 @@ class GoogleSignIn { 'signInOption': (signInOption ?? SignInOption.standard).toString(), 'scopes': scopes ?? [], 'hostedDomain': hostedDomain, + 'serverClientId': serverClientId, }) ..catchError((dynamic _) { // Invalidate initialization if it errored out. diff --git a/packages/google_sign_in/test/google_sign_in_test.dart b/packages/google_sign_in/test/google_sign_in_test.dart index b0ba5e82d3e2..c3951a88f12c 100755 --- a/packages/google_sign_in/test/google_sign_in_test.dart +++ b/packages/google_sign_in/test/google_sign_in_test.dart @@ -59,6 +59,7 @@ void main() { 'signInOption': 'SignInOption.standard', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('signInSilently', arguments: null), ], @@ -75,6 +76,7 @@ void main() { 'signInOption': 'SignInOption.standard', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('signIn', arguments: null), ], @@ -89,6 +91,7 @@ void main() { 'signInOption': 'SignInOption.standard', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('signOut', arguments: null), ]); @@ -104,6 +107,7 @@ void main() { 'signInOption': 'SignInOption.standard', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('disconnect', arguments: null), ], @@ -121,6 +125,7 @@ void main() { 'signInOption': 'SignInOption.standard', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('disconnect', arguments: null), ], @@ -135,6 +140,7 @@ void main() { 'signInOption': 'SignInOption.standard', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('isSignedIn', arguments: null), ]); @@ -161,6 +167,7 @@ void main() { 'signInOption': 'SignInOption.standard', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('signInSilently', arguments: null), ], @@ -178,6 +185,7 @@ void main() { 'signInOption': 'SignInOption.standard', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('signInSilently', arguments: null), isMethodCall('signIn', arguments: null), @@ -200,6 +208,7 @@ void main() { 'signInOption': 'SignInOption.standard', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('signInSilently', arguments: null), ], @@ -231,6 +240,7 @@ void main() { 'signInOption': 'SignInOption.standard', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('signOut', arguments: null), isMethodCall('signOut', arguments: null), @@ -256,6 +266,7 @@ void main() { 'signInOption': 'SignInOption.standard', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('signInSilently', arguments: null), isMethodCall('signOut', arguments: null), @@ -307,6 +318,7 @@ void main() { 'signInOption': 'SignInOption.standard', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('signInSilently', arguments: null), ], @@ -326,6 +338,7 @@ void main() { 'signInOption': 'SignInOption.games', 'scopes': [], 'hostedDomain': null, + 'serverClientId': null, }), isMethodCall('signInSilently', arguments: null), ],