Skip to content

Commit 23ba531

Browse files
yamarkzEgor
authored andcommitted
[google_sign_in] Add ability to return serverAuthCode (flutter#2116)
1 parent 807de4d commit 23ba531

File tree

8 files changed

+23
-2
lines changed

8 files changed

+23
-2
lines changed

packages/google_sign_in/google_sign_in/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.5.0
2+
3+
* Add support for getting `serverAuthCode`.
4+
15
## 4.4.6
26

37
* Update lower bound of dart dependency to 2.1.0.

packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public void init(
335335
.getIdentifier("default_web_client_id", "string", context.getPackageName());
336336
if (clientIdIdentifier != 0) {
337337
optionsBuilder.requestIdToken(context.getString(clientIdIdentifier));
338+
optionsBuilder.requestServerAuthCode(context.getString(clientIdIdentifier));
338339
}
339340
for (String scope : requestedScopes) {
340341
optionsBuilder.requestScopes(new Scope(scope));
@@ -484,6 +485,7 @@ private void onSignInAccount(GoogleSignInAccount account) {
484485
response.put("email", account.getEmail());
485486
response.put("id", account.getId());
486487
response.put("idToken", account.getIdToken());
488+
response.put("serverAuthCode", account.getServerAuthCode());
487489
response.put("displayName", account.getDisplayName());
488490
if (account.getPhotoUrl() != null) {
489491
response.put("photoUrl", account.getPhotoUrl().toString());
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="default_web_client_id">YOUR_WEB_CLIENT_ID</string>
4+
</resources>

packages/google_sign_in/google_sign_in/example/ios/Runner/GoogleService-Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@
3838
<string>1:479882132969:ios:2643f950e0a0da08</string>
3939
<key>DATABASE_URL</key>
4040
<string>https://my-flutter-proj.firebaseio.com</string>
41+
<key>SERVER_CLIENT_ID</key>
42+
<string>YOUR_SERVER_CLIENT_ID</string>
4143
</dict>
4244
</plist>

packages/google_sign_in/google_sign_in/ios/Classes/FLTGoogleSignInPlugin.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// for more info.
1111
static NSString *const kClientIdKey = @"CLIENT_ID";
1212

13+
static NSString *const kServerClientIdKey = @"SERVER_CLIENT_ID";
14+
1315
// These error codes must match with ones declared on Android and Dart sides.
1416
static NSString *const kErrorReasonSignInRequired = @"sign_in_required";
1517
static NSString *const kErrorReasonSignInCanceled = @"sign_in_canceled";
@@ -76,6 +78,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
7678
if (path) {
7779
NSMutableDictionary *plist = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
7880
[GIDSignIn sharedInstance].clientID = plist[kClientIdKey];
81+
[GIDSignIn sharedInstance].serverClientID = plist[kServerClientIdKey];
7982
[GIDSignIn sharedInstance].scopes = call.arguments[@"scopes"];
8083
[GIDSignIn sharedInstance].hostedDomain = call.arguments[@"hostedDomain"];
8184
result(nil);
@@ -221,6 +224,7 @@ - (void)signIn:(GIDSignIn *)signIn
221224
@"email" : user.profile.email ?: [NSNull null],
222225
@"id" : user.userID ?: [NSNull null],
223226
@"photoUrl" : [photoUrl absoluteString] ?: [NSNull null],
227+
@"serverAuthCode" : user.serverAuthCode ?: [NSNull null]
224228
}
225229
error:nil];
226230
}

packages/google_sign_in/google_sign_in/lib/google_sign_in.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class GoogleSignInAuthentication {
2727
/// The OAuth2 access token to access Google services.
2828
String get accessToken => _data.accessToken;
2929

30+
/// Server auth code used to access Google Login
31+
String get serverAuthCode => _data.serverAuthCode;
32+
3033
@override
3134
String toString() => 'GoogleSignInAuthentication:$_data';
3235
}

packages/google_sign_in/google_sign_in/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_sign_in
22
description: Flutter plugin for Google Sign-In, a secure authentication system
33
for signing in with a Google account on Android and iOS.
44
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
5-
version: 4.4.6
5+
version: 4.5.0
66

77
flutter:
88
plugin:
@@ -16,7 +16,7 @@ flutter:
1616
default_package: google_sign_in_web
1717

1818
dependencies:
19-
google_sign_in_platform_interface: ^1.1.0
19+
google_sign_in_platform_interface: ^1.1.1
2020
flutter:
2121
sdk: flutter
2222
meta: ^1.0.4

packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void main() {
3636
'getTokens': <dynamic, dynamic>{
3737
'idToken': '123',
3838
'accessToken': '456',
39+
'serverAuthCode': '789',
3940
},
4041
};
4142

@@ -370,6 +371,7 @@ void main() {
370371

371372
expect(auth.accessToken, '456');
372373
expect(auth.idToken, '123');
374+
expect(auth.serverAuthCode, '789');
373375
expect(
374376
log,
375377
<Matcher>[

0 commit comments

Comments
 (0)