Skip to content

Commit 7df7a8f

Browse files
authored
[google_sign_in] add serverAuthCode to GoogleSignInAccount (flutter#4180)
1 parent 5eec1e6 commit 7df7a8f

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

packages/google_sign_in/google_sign_in/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 5.2.0
2+
3+
* Add `GoogleSignInAccount.serverAuthCode`. Mark `GoogleSignInAuthentication.serverAuthCode` as deprecated.
4+
15
## 5.1.1
26

37
* Update minimum Flutter SDK to 2.5 and iOS deployment target to 9.0.

packages/google_sign_in/google_sign_in/lib/google_sign_in.dart

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class GoogleSignInAuthentication {
2828
String? get accessToken => _data.accessToken;
2929

3030
/// Server auth code used to access Google Login
31+
@Deprecated('Use the `GoogleSignInAccount.serverAuthCode` property instead')
3132
String? get serverAuthCode => _data.serverAuthCode;
3233

3334
@override
@@ -44,6 +45,7 @@ class GoogleSignInAccount implements GoogleIdentity {
4445
email = data.email,
4546
id = data.id,
4647
photoUrl = data.photoUrl,
48+
serverAuthCode = data.serverAuthCode,
4749
_idToken = data.idToken {
4850
assert(id != null);
4951
}
@@ -68,6 +70,9 @@ class GoogleSignInAccount implements GoogleIdentity {
6870
@override
6971
final String? photoUrl;
7072

73+
@override
74+
final String? serverAuthCode;
75+
7176
final String? _idToken;
7277
final GoogleSignIn _googleSignIn;
7378

@@ -97,6 +102,7 @@ class GoogleSignInAccount implements GoogleIdentity {
97102
if (response.idToken == null) {
98103
response.idToken = _idToken;
99104
}
105+
100106
return GoogleSignInAuthentication._(response);
101107
}
102108

@@ -132,11 +138,13 @@ class GoogleSignInAccount implements GoogleIdentity {
132138
email == otherAccount.email &&
133139
id == otherAccount.id &&
134140
photoUrl == otherAccount.photoUrl &&
141+
serverAuthCode == otherAccount.serverAuthCode &&
135142
_idToken == otherAccount._idToken;
136143
}
137144

138145
@override
139-
int get hashCode => hashValues(displayName, email, id, photoUrl, _idToken);
146+
int get hashCode =>
147+
hashValues(displayName, email, id, photoUrl, _idToken, serverAuthCode);
140148

141149
@override
142150
String toString() {
@@ -145,6 +153,7 @@ class GoogleSignInAccount implements GoogleIdentity {
145153
'email': email,
146154
'id': id,
147155
'photoUrl': photoUrl,
156+
'serverAuthCode': serverAuthCode
148157
};
149158
return 'GoogleSignInAccount:$data';
150159
}

packages/google_sign_in/google_sign_in/lib/src/common.dart

+3
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ abstract class GoogleIdentity {
3434
///
3535
/// Not guaranteed to be present for all users, even when configured.
3636
String? get photoUrl;
37+
38+
/// Server auth code used to access Google Login
39+
String? get serverAuthCode;
3740
}

packages/google_sign_in/google_sign_in/lib/testing.dart

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class FakeUser {
6767
this.email,
6868
this.displayName,
6969
this.photoUrl,
70+
this.serverAuthCode,
7071
this.idToken,
7172
this.accessToken,
7273
});
@@ -83,6 +84,9 @@ class FakeUser {
8384
/// Will be converted into [GoogleSignInUserData.photoUrl].
8485
final String? photoUrl;
8586

87+
/// Will be converted into [GoogleSignInUserData.serverAuthCode].
88+
final String? serverAuthCode;
89+
8690
/// Will be converted into [GoogleSignInTokenData.idToken].
8791
final String? idToken;
8892

@@ -94,6 +98,7 @@ class FakeUser {
9498
'email': email,
9599
'displayName': displayName,
96100
'photoUrl': photoUrl,
101+
'serverAuthCode': serverAuthCode,
97102
'idToken': idToken,
98103
};
99104
}

packages/google_sign_in/google_sign_in/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system
33
for signing in with a Google account on Android and iOS.
44
repository: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
6-
version: 5.1.1
6+
version: 5.2.0
77

88
environment:
99
sdk: ">=2.14.0 <3.0.0"
@@ -23,7 +23,7 @@ flutter:
2323
dependencies:
2424
flutter:
2525
sdk: flutter
26-
google_sign_in_platform_interface: ^2.0.1
26+
google_sign_in_platform_interface: ^2.1.0
2727
google_sign_in_web: ^0.10.0
2828
meta: ^1.3.0
2929

packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart

+9-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void main() {
2323
"id": "8162538176523816253123",
2424
"photoUrl": "https://lh5.googleusercontent.com/photo.jpg",
2525
"displayName": "John Doe",
26+
"serverAuthCode": "789"
2627
};
2728

2829
const Map<String, dynamic> kDefaultResponses = <String, dynamic>{
@@ -350,7 +351,8 @@ void main() {
350351

351352
expect(auth.accessToken, '456');
352353
expect(auth.idToken, '123');
353-
expect(auth.serverAuthCode, '789');
354+
// fix deprecated_member_use_from_same_package
355+
// expect(auth.serverAuthCode, '789');
354356
expect(
355357
log,
356358
<Matcher>[
@@ -382,11 +384,11 @@ void main() {
382384

383385
group('GoogleSignIn with fake backend', () {
384386
const FakeUser kUserData = FakeUser(
385-
id: "8162538176523816253123",
386-
displayName: "John Doe",
387-
388-
photoUrl: "https://lh5.googleusercontent.com/photo.jpg",
389-
);
387+
id: "8162538176523816253123",
388+
displayName: "John Doe",
389+
390+
photoUrl: "https://lh5.googleusercontent.com/photo.jpg",
391+
serverAuthCode: '789');
390392

391393
late GoogleSignIn googleSignIn;
392394

@@ -411,6 +413,7 @@ void main() {
411413
expect(user.email, equals(kUserData.email));
412414
expect(user.id, equals(kUserData.id));
413415
expect(user.photoUrl, equals(kUserData.photoUrl));
416+
expect(user.serverAuthCode, equals(kUserData.serverAuthCode));
414417

415418
await googleSignIn.disconnect();
416419
expect(googleSignIn.currentUser, isNull);

0 commit comments

Comments
 (0)