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

Commit

Permalink
[google_sign_in] add serverAuthCode to GoogleSignInAccount (#4180)
Browse files Browse the repository at this point in the history
  • Loading branch information
p-shapovalov authored Oct 21, 2021
1 parent 5eec1e6 commit 7df7a8f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
4 changes: 4 additions & 0 deletions packages/google_sign_in/google_sign_in/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.2.0

* Add `GoogleSignInAccount.serverAuthCode`. Mark `GoogleSignInAuthentication.serverAuthCode` as deprecated.

## 5.1.1

* Update minimum Flutter SDK to 2.5 and iOS deployment target to 9.0.
Expand Down
11 changes: 10 additions & 1 deletion packages/google_sign_in/google_sign_in/lib/google_sign_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class GoogleSignInAuthentication {
String? get accessToken => _data.accessToken;

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

@override
Expand All @@ -44,6 +45,7 @@ class GoogleSignInAccount implements GoogleIdentity {
email = data.email,
id = data.id,
photoUrl = data.photoUrl,
serverAuthCode = data.serverAuthCode,
_idToken = data.idToken {
assert(id != null);
}
Expand All @@ -68,6 +70,9 @@ class GoogleSignInAccount implements GoogleIdentity {
@override
final String? photoUrl;

@override
final String? serverAuthCode;

final String? _idToken;
final GoogleSignIn _googleSignIn;

Expand Down Expand Up @@ -97,6 +102,7 @@ class GoogleSignInAccount implements GoogleIdentity {
if (response.idToken == null) {
response.idToken = _idToken;
}

return GoogleSignInAuthentication._(response);
}

Expand Down Expand Up @@ -132,11 +138,13 @@ class GoogleSignInAccount implements GoogleIdentity {
email == otherAccount.email &&
id == otherAccount.id &&
photoUrl == otherAccount.photoUrl &&
serverAuthCode == otherAccount.serverAuthCode &&
_idToken == otherAccount._idToken;
}

@override
int get hashCode => hashValues(displayName, email, id, photoUrl, _idToken);
int get hashCode =>
hashValues(displayName, email, id, photoUrl, _idToken, serverAuthCode);

@override
String toString() {
Expand All @@ -145,6 +153,7 @@ class GoogleSignInAccount implements GoogleIdentity {
'email': email,
'id': id,
'photoUrl': photoUrl,
'serverAuthCode': serverAuthCode
};
return 'GoogleSignInAccount:$data';
}
Expand Down
3 changes: 3 additions & 0 deletions packages/google_sign_in/google_sign_in/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ abstract class GoogleIdentity {
///
/// Not guaranteed to be present for all users, even when configured.
String? get photoUrl;

/// Server auth code used to access Google Login
String? get serverAuthCode;
}
5 changes: 5 additions & 0 deletions packages/google_sign_in/google_sign_in/lib/testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class FakeUser {
this.email,
this.displayName,
this.photoUrl,
this.serverAuthCode,
this.idToken,
this.accessToken,
});
Expand All @@ -83,6 +84,9 @@ class FakeUser {
/// Will be converted into [GoogleSignInUserData.photoUrl].
final String? photoUrl;

/// Will be converted into [GoogleSignInUserData.serverAuthCode].
final String? serverAuthCode;

/// Will be converted into [GoogleSignInTokenData.idToken].
final String? idToken;

Expand All @@ -94,6 +98,7 @@ class FakeUser {
'email': email,
'displayName': displayName,
'photoUrl': photoUrl,
'serverAuthCode': serverAuthCode,
'idToken': idToken,
};
}
4 changes: 2 additions & 2 deletions packages/google_sign_in/google_sign_in/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system
for signing in with a Google account on Android and iOS.
repository: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
version: 5.1.1
version: 5.2.0

environment:
sdk: ">=2.14.0 <3.0.0"
Expand All @@ -23,7 +23,7 @@ flutter:
dependencies:
flutter:
sdk: flutter
google_sign_in_platform_interface: ^2.0.1
google_sign_in_platform_interface: ^2.1.0
google_sign_in_web: ^0.10.0
meta: ^1.3.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void main() {
"id": "8162538176523816253123",
"photoUrl": "https://lh5.googleusercontent.com/photo.jpg",
"displayName": "John Doe",
"serverAuthCode": "789"
};

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

expect(auth.accessToken, '456');
expect(auth.idToken, '123');
expect(auth.serverAuthCode, '789');
// fix deprecated_member_use_from_same_package
// expect(auth.serverAuthCode, '789');
expect(
log,
<Matcher>[
Expand Down Expand Up @@ -382,11 +384,11 @@ void main() {

group('GoogleSignIn with fake backend', () {
const FakeUser kUserData = FakeUser(
id: "8162538176523816253123",
displayName: "John Doe",
email: "[email protected]",
photoUrl: "https://lh5.googleusercontent.com/photo.jpg",
);
id: "8162538176523816253123",
displayName: "John Doe",
email: "[email protected]",
photoUrl: "https://lh5.googleusercontent.com/photo.jpg",
serverAuthCode: '789');

late GoogleSignIn googleSignIn;

Expand All @@ -411,6 +413,7 @@ void main() {
expect(user.email, equals(kUserData.email));
expect(user.id, equals(kUserData.id));
expect(user.photoUrl, equals(kUserData.photoUrl));
expect(user.serverAuthCode, equals(kUserData.serverAuthCode));

await googleSignIn.disconnect();
expect(googleSignIn.currentUser, isNull);
Expand Down

0 comments on commit 7df7a8f

Please sign in to comment.