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

[google_sign_in] add serverAuthCode to GoogleSignInAccount #4180

Merged
merged 14 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 and always null.

## 5.1.1

* Update minimum Flutter SDK to 2.5 and iOS deployment target to 9.0.
Expand Down
14 changes: 12 additions & 2 deletions 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,7 +28,9 @@ class GoogleSignInAuthentication {
String? get accessToken => _data.accessToken;

/// Server auth code used to access Google Login
String? get serverAuthCode => _data.serverAuthCode;
@Deprecated(
'Always null. Use the `GoogleSignInAccount.serverAuthCode` property instead')
String? get serverAuthCode => null;
p-shapovalov marked this conversation as resolved.
Show resolved Hide resolved

@override
String toString() => 'GoogleSignInAuthentication:$_data';
Expand All @@ -44,6 +46,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 +71,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 +103,7 @@ class GoogleSignInAccount implements GoogleIdentity {
if (response.idToken == null) {
response.idToken = _idToken;
}

return GoogleSignInAuthentication._(response);
}

Expand Down Expand Up @@ -132,11 +139,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 +154,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 All @@ -33,11 +34,7 @@ void main() {
'disconnect': null,
'isSignedIn': true,
'requestScopes': true,
'getTokens': <dynamic, dynamic>{
'idToken': '123',
'accessToken': '456',
'serverAuthCode': '789',
},
'getTokens': <dynamic, dynamic>{'idToken': '123', 'accessToken': '456'},
};

final List<MethodCall> log = <MethodCall>[];
Expand Down Expand Up @@ -350,7 +347,6 @@ void main() {

expect(auth.accessToken, '456');
expect(auth.idToken, '123');
expect(auth.serverAuthCode, '789');
expect(
log,
<Matcher>[
Expand Down Expand Up @@ -382,11 +378,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 +407,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