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 5 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
6 changes: 5 additions & 1 deletion packages/google_sign_in/google_sign_in/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## NEXT
## 5.0.9

* Re-use server auth code obtained on login.

## 5.0.8

* Updated Android lint settings.

Expand Down
14 changes: 11 additions & 3 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 @@ -44,7 +44,8 @@ class GoogleSignInAccount implements GoogleIdentity {
email = data.email,
id = data.id,
photoUrl = data.photoUrl,
_idToken = data.idToken {
_idToken = data.idToken,
_serverAuthCode = data.serverAuthCode {
assert(id != null);
}

Expand All @@ -69,6 +70,7 @@ class GoogleSignInAccount implements GoogleIdentity {
final String? photoUrl;

final String? _idToken;
final String? _serverAuthCode;
final GoogleSignIn _googleSignIn;

/// Retrieve [GoogleSignInAuthentication] for this account.
Expand Down Expand Up @@ -97,6 +99,10 @@ class GoogleSignInAccount implements GoogleIdentity {
if (response.idToken == null) {
response.idToken = _idToken;
}
// re-use auth code obtained on login.
if (response.serverAuthCode == null) {
response.serverAuthCode = _serverAuthCode;
}
p-shapovalov marked this conversation as resolved.
Show resolved Hide resolved
return GoogleSignInAuthentication._(response);
}

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

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

@override
String toString() {
Expand Down
2 changes: 1 addition & 1 deletion packages/google_sign_in/google_sign_in/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ flutter:
dependencies:
flutter:
sdk: flutter
google_sign_in_platform_interface: ^2.0.1
google_sign_in_platform_interface: ^2.0.2
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 @@ -36,7 +37,7 @@ void main() {
'getTokens': <dynamic, dynamic>{
'idToken': '123',
'accessToken': '456',
'serverAuthCode': '789',
'serverAuthCode': null,
p-shapovalov marked this conversation as resolved.
Show resolved Hide resolved
},
};

Expand Down