From 88e85c6a48063cfab9111689179e2582a99b77ff Mon Sep 17 00:00:00 2001 From: Kazuki YAMAGUCHI Date: Wed, 20 May 2020 04:06:01 +0900 Subject: [PATCH] [google_sign_in] Add ability to return serverAuthCode (#2116) --- packages/google_sign_in/google_sign_in/CHANGELOG.md | 4 ++++ .../io/flutter/plugins/googlesignin/GoogleSignInPlugin.java | 2 ++ .../example/android/app/src/main/res/values/strings.xml | 4 ++++ .../example/ios/Runner/GoogleService-Info.plist | 2 ++ .../google_sign_in/ios/Classes/FLTGoogleSignInPlugin.m | 4 ++++ .../google_sign_in/google_sign_in/lib/google_sign_in.dart | 3 +++ packages/google_sign_in/google_sign_in/pubspec.yaml | 4 ++-- .../google_sign_in/test/google_sign_in_test.dart | 2 ++ 8 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 packages/google_sign_in/google_sign_in/example/android/app/src/main/res/values/strings.xml diff --git a/packages/google_sign_in/google_sign_in/CHANGELOG.md b/packages/google_sign_in/google_sign_in/CHANGELOG.md index a0d2d470020d..b3c3955cf50a 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.0 + +* Add support for getting `serverAuthCode`. + ## 4.4.6 * Update lower bound of dart dependency to 2.1.0. 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 e8fcd29075e3..ce04e595080b 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 @@ -335,6 +335,7 @@ public void init( .getIdentifier("default_web_client_id", "string", context.getPackageName()); if (clientIdIdentifier != 0) { optionsBuilder.requestIdToken(context.getString(clientIdIdentifier)); + optionsBuilder.requestServerAuthCode(context.getString(clientIdIdentifier)); } for (String scope : requestedScopes) { optionsBuilder.requestScopes(new Scope(scope)); @@ -484,6 +485,7 @@ private void onSignInAccount(GoogleSignInAccount account) { response.put("email", account.getEmail()); response.put("id", account.getId()); response.put("idToken", account.getIdToken()); + response.put("serverAuthCode", account.getServerAuthCode()); response.put("displayName", account.getDisplayName()); if (account.getPhotoUrl() != null) { response.put("photoUrl", account.getPhotoUrl().toString()); diff --git a/packages/google_sign_in/google_sign_in/example/android/app/src/main/res/values/strings.xml b/packages/google_sign_in/google_sign_in/example/android/app/src/main/res/values/strings.xml new file mode 100644 index 000000000000..c7e28ffcedd1 --- /dev/null +++ b/packages/google_sign_in/google_sign_in/example/android/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + YOUR_WEB_CLIENT_ID + diff --git a/packages/google_sign_in/google_sign_in/example/ios/Runner/GoogleService-Info.plist b/packages/google_sign_in/google_sign_in/example/ios/Runner/GoogleService-Info.plist index 8d24ccc9b130..6042aab908af 100644 --- a/packages/google_sign_in/google_sign_in/example/ios/Runner/GoogleService-Info.plist +++ b/packages/google_sign_in/google_sign_in/example/ios/Runner/GoogleService-Info.plist @@ -38,5 +38,7 @@ 1:479882132969:ios:2643f950e0a0da08 DATABASE_URL https://my-flutter-proj.firebaseio.com + SERVER_CLIENT_ID + YOUR_SERVER_CLIENT_ID \ No newline at end of file diff --git a/packages/google_sign_in/google_sign_in/ios/Classes/FLTGoogleSignInPlugin.m b/packages/google_sign_in/google_sign_in/ios/Classes/FLTGoogleSignInPlugin.m index 9049fcd62a33..f621d1e68312 100644 --- a/packages/google_sign_in/google_sign_in/ios/Classes/FLTGoogleSignInPlugin.m +++ b/packages/google_sign_in/google_sign_in/ios/Classes/FLTGoogleSignInPlugin.m @@ -10,6 +10,8 @@ // for more info. static NSString *const kClientIdKey = @"CLIENT_ID"; +static NSString *const kServerClientIdKey = @"SERVER_CLIENT_ID"; + // These error codes must match with ones declared on Android and Dart sides. static NSString *const kErrorReasonSignInRequired = @"sign_in_required"; static NSString *const kErrorReasonSignInCanceled = @"sign_in_canceled"; @@ -76,6 +78,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result if (path) { NSMutableDictionary *plist = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; [GIDSignIn sharedInstance].clientID = plist[kClientIdKey]; + [GIDSignIn sharedInstance].serverClientID = plist[kServerClientIdKey]; [GIDSignIn sharedInstance].scopes = call.arguments[@"scopes"]; [GIDSignIn sharedInstance].hostedDomain = call.arguments[@"hostedDomain"]; result(nil); @@ -221,6 +224,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/google_sign_in/lib/google_sign_in.dart b/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart index 7402c7a69816..0f1f15bbb8c4 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 @@ -27,6 +27,9 @@ class GoogleSignInAuthentication { /// The OAuth2 access token to access Google services. String get accessToken => _data.accessToken; + /// Server auth code used to access Google Login + String get serverAuthCode => _data.serverAuthCode; + @override String toString() => 'GoogleSignInAuthentication:$_data'; } diff --git a/packages/google_sign_in/google_sign_in/pubspec.yaml b/packages/google_sign_in/google_sign_in/pubspec.yaml index e02c8ee17f11..b82a2bd74856 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.4.6 +version: 4.5.0 flutter: plugin: @@ -16,7 +16,7 @@ flutter: default_package: google_sign_in_web dependencies: - google_sign_in_platform_interface: ^1.1.0 + google_sign_in_platform_interface: ^1.1.1 flutter: sdk: flutter meta: ^1.0.4 diff --git a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart index 898c27fd9f7e..5969edbaba76 100755 --- a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart +++ b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart @@ -36,6 +36,7 @@ void main() { 'getTokens': { 'idToken': '123', 'accessToken': '456', + 'serverAuthCode': '789', }, }; @@ -370,6 +371,7 @@ void main() { expect(auth.accessToken, '456'); expect(auth.idToken, '123'); + expect(auth.serverAuthCode, '789'); expect( log, [