Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 46c4bfc

Browse files
committed
[server-auth-code] Add serverClientId option to return serverAuthCode. Relates to issues #16613 and #17813
1 parent 39af90c commit 46c4bfc

File tree

6 files changed

+47
-7
lines changed

6 files changed

+47
-7
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ Ashton Thomas <[email protected]>
2121
Thomas Danner <[email protected]>
2222
Diego Velásquez <[email protected]>
2323
Hajime Nakamura <[email protected]>
24+
Twin Sun, LLC <[email protected]>

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public void onMethodCall(MethodCall call, Result result) {
6868
String signInOption = call.argument("signInOption");
6969
List<String> requestedScopes = call.argument("scopes");
7070
String hostedDomain = call.argument("hostedDomain");
71-
delegate.init(result, signInOption, requestedScopes, hostedDomain);
71+
String serverClientId = call.argument("serverClientId");
72+
delegate.init(result, signInOption, requestedScopes, hostedDomain, serverClientId);
7273
break;
7374

7475
case METHOD_SIGN_IN_SILENTLY:
@@ -115,7 +116,11 @@ public void onMethodCall(MethodCall call, Result result) {
115116
public interface IDelegate {
116117
/** Initializes this delegate so that it is ready to perform other operations. */
117118
public void init(
118-
Result result, String signInOption, List<String> requestedScopes, String hostedDomain);
119+
Result result,
120+
String signInOption,
121+
List<String> requestedScopes,
122+
String hostedDomain,
123+
String serverClientId);
119124

120125
/**
121126
* Returns the account information for the user who is signed in to this app. If no user is
@@ -212,7 +217,11 @@ private void checkAndSetPendingOperation(String method, Result result, Object da
212217
*/
213218
@Override
214219
public void init(
215-
Result result, String signInOption, List<String> requestedScopes, String hostedDomain) {
220+
Result result,
221+
String signInOption,
222+
List<String> requestedScopes,
223+
String hostedDomain,
224+
String serverClientId) {
216225
try {
217226
GoogleSignInOptions.Builder optionsBuilder;
218227

@@ -248,6 +257,10 @@ public void init(
248257
if (!Strings.isNullOrEmpty(hostedDomain)) {
249258
optionsBuilder.setHostedDomain(hostedDomain);
250259
}
260+
if (!Strings.isNullOrEmpty(serverClientId)) {
261+
optionsBuilder.requestServerAuthCode(serverClientId);
262+
optionsBuilder.requestIdToken(serverClientId);
263+
}
251264

252265
this.requestedScopes = requestedScopes;
253266
signInClient = GoogleSignIn.getClient(registrar.context(), optionsBuilder.build());
@@ -363,6 +376,7 @@ private void onSignInAccount(GoogleSignInAccount account) {
363376
response.put("id", account.getId());
364377
response.put("idToken", account.getIdToken());
365378
response.put("displayName", account.getDisplayName());
379+
response.put("serverAuthCode", account.getServerAuthCode());
366380
if (account.getPhotoUrl() != null) {
367381
response.put("photoUrl", account.getPhotoUrl().toString());
368382
}

packages/google_sign_in/ios/Classes/GoogleSignInPlugin.h

100755100644
File mode changed.

packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
8080
[GIDSignIn sharedInstance].clientID = plist[kClientIdKey];
8181
[GIDSignIn sharedInstance].scopes = call.arguments[@"scopes"];
8282
[GIDSignIn sharedInstance].hostedDomain = call.arguments[@"hostedDomain"];
83+
if (![call.arguments[@"serverClientId"] isEqual:[NSNull null]]) {
84+
[GIDSignIn sharedInstance].serverClientID = call.arguments[@"serverClientId"];
85+
}
8386
result(nil);
8487
} else {
8588
result([FlutterError errorWithCode:@"missing-config"
@@ -173,6 +176,7 @@ - (void)signIn:(GIDSignIn *)signIn
173176
@"email" : user.profile.email ?: [NSNull null],
174177
@"id" : user.userID ?: [NSNull null],
175178
@"photoUrl" : [photoUrl absoluteString] ?: [NSNull null],
179+
@"serverAuthCode" : user.serverAuthCode ?: [NSNull null]
176180
}
177181
error:nil];
178182
}

packages/google_sign_in/lib/google_sign_in.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class GoogleSignInAccount implements GoogleIdentity {
3636
email = data['email'],
3737
id = data['id'],
3838
photoUrl = data['photoUrl'],
39-
_idToken = data['idToken'] {
39+
_idToken = data['idToken'],
40+
serverAuthCode = data['serverAuthCode'] {
4041
assert(id != null);
4142
}
4243

@@ -62,6 +63,7 @@ class GoogleSignInAccount implements GoogleIdentity {
6263

6364
final String _idToken;
6465
final GoogleSignIn _googleSignIn;
66+
final String serverAuthCode;
6567

6668
/// Retrieve [GoogleSignInAuthentication] for this account.
6769
///
@@ -157,14 +159,17 @@ class GoogleSignIn {
157159
/// The [hostedDomain] argument specifies a hosted domain restriction. By
158160
/// setting this, sign in will be restricted to accounts of the user in the
159161
/// specified domain. By default, the list of accounts will not be restricted.
160-
GoogleSignIn({this.signInOption, this.scopes, this.hostedDomain});
162+
GoogleSignIn(
163+
{this.signInOption, this.scopes, this.hostedDomain, this.serverClientId});
161164

162165
/// Factory for creating default sign in user experience.
163-
factory GoogleSignIn.standard({List<String> scopes, String hostedDomain}) {
166+
factory GoogleSignIn.standard(
167+
{List<String> scopes, String hostedDomain, String serverClientId}) {
164168
return GoogleSignIn(
165169
signInOption: SignInOption.standard,
166170
scopes: scopes,
167-
hostedDomain: hostedDomain);
171+
hostedDomain: hostedDomain,
172+
serverClientId: serverClientId);
168173
}
169174

170175
/// Factory for creating sign in suitable for games. This option must not be
@@ -201,6 +206,8 @@ class GoogleSignIn {
201206
/// Domain to restrict sign-in to.
202207
final String hostedDomain;
203208

209+
final String serverClientId;
210+
204211
StreamController<GoogleSignInAccount> _currentUserController =
205212
StreamController<GoogleSignInAccount>.broadcast();
206213

@@ -234,6 +241,7 @@ class GoogleSignIn {
234241
'signInOption': (signInOption ?? SignInOption.standard).toString(),
235242
'scopes': scopes ?? <String>[],
236243
'hostedDomain': hostedDomain,
244+
'serverClientId': serverClientId,
237245
})
238246
..catchError((dynamic _) {
239247
// Invalidate initialization if it errored out.

packages/google_sign_in/test/google_sign_in_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void main() {
5959
'signInOption': 'SignInOption.standard',
6060
'scopes': <String>[],
6161
'hostedDomain': null,
62+
'serverClientId': null,
6263
}),
6364
isMethodCall('signInSilently', arguments: null),
6465
],
@@ -75,6 +76,7 @@ void main() {
7576
'signInOption': 'SignInOption.standard',
7677
'scopes': <String>[],
7778
'hostedDomain': null,
79+
'serverClientId': null,
7880
}),
7981
isMethodCall('signIn', arguments: null),
8082
],
@@ -89,6 +91,7 @@ void main() {
8991
'signInOption': 'SignInOption.standard',
9092
'scopes': <String>[],
9193
'hostedDomain': null,
94+
'serverClientId': null,
9295
}),
9396
isMethodCall('signOut', arguments: null),
9497
]);
@@ -104,6 +107,7 @@ void main() {
104107
'signInOption': 'SignInOption.standard',
105108
'scopes': <String>[],
106109
'hostedDomain': null,
110+
'serverClientId': null,
107111
}),
108112
isMethodCall('disconnect', arguments: null),
109113
],
@@ -121,6 +125,7 @@ void main() {
121125
'signInOption': 'SignInOption.standard',
122126
'scopes': <String>[],
123127
'hostedDomain': null,
128+
'serverClientId': null,
124129
}),
125130
isMethodCall('disconnect', arguments: null),
126131
],
@@ -135,6 +140,7 @@ void main() {
135140
'signInOption': 'SignInOption.standard',
136141
'scopes': <String>[],
137142
'hostedDomain': null,
143+
'serverClientId': null,
138144
}),
139145
isMethodCall('isSignedIn', arguments: null),
140146
]);
@@ -161,6 +167,7 @@ void main() {
161167
'signInOption': 'SignInOption.standard',
162168
'scopes': <String>[],
163169
'hostedDomain': null,
170+
'serverClientId': null,
164171
}),
165172
isMethodCall('signInSilently', arguments: null),
166173
],
@@ -178,6 +185,7 @@ void main() {
178185
'signInOption': 'SignInOption.standard',
179186
'scopes': <String>[],
180187
'hostedDomain': null,
188+
'serverClientId': null,
181189
}),
182190
isMethodCall('signInSilently', arguments: null),
183191
isMethodCall('signIn', arguments: null),
@@ -200,6 +208,7 @@ void main() {
200208
'signInOption': 'SignInOption.standard',
201209
'scopes': <String>[],
202210
'hostedDomain': null,
211+
'serverClientId': null,
203212
}),
204213
isMethodCall('signInSilently', arguments: null),
205214
],
@@ -231,6 +240,7 @@ void main() {
231240
'signInOption': 'SignInOption.standard',
232241
'scopes': <String>[],
233242
'hostedDomain': null,
243+
'serverClientId': null,
234244
}),
235245
isMethodCall('signOut', arguments: null),
236246
isMethodCall('signOut', arguments: null),
@@ -256,6 +266,7 @@ void main() {
256266
'signInOption': 'SignInOption.standard',
257267
'scopes': <String>[],
258268
'hostedDomain': null,
269+
'serverClientId': null,
259270
}),
260271
isMethodCall('signInSilently', arguments: null),
261272
isMethodCall('signOut', arguments: null),
@@ -307,6 +318,7 @@ void main() {
307318
'signInOption': 'SignInOption.standard',
308319
'scopes': <String>[],
309320
'hostedDomain': null,
321+
'serverClientId': null,
310322
}),
311323
isMethodCall('signInSilently', arguments: null),
312324
],
@@ -326,6 +338,7 @@ void main() {
326338
'signInOption': 'SignInOption.games',
327339
'scopes': <String>[],
328340
'hostedDomain': null,
341+
'serverClientId': null,
329342
}),
330343
isMethodCall('signInSilently', arguments: null),
331344
],

0 commit comments

Comments
 (0)