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

[google_sign_in] Fix Server Authorization code on android #2792

Closed
Show file tree
Hide file tree
Changes from all 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 @@
## 4.5.2

* Fix serverAuthCode on Android.

## 4.5.1

* Add note on Apple sign in requirement in README.
Expand Down
15 changes: 12 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,11 @@ class GoogleSignInAccount implements GoogleIdentity {
if (response.idToken == null) {
response.idToken = _idToken;
}

if (response.serverAuthCode == null) {
response.serverAuthCode = _serverAuthCode;
}

return GoogleSignInAuthentication._(response);
}

Expand Down Expand Up @@ -130,11 +137,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 @@ -2,7 +2,7 @@ name: google_sign_in
description: Flutter plugin for Google Sign-In, a secure authentication system
for signing in with a Google account on Android and iOS.
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
version: 4.5.1
version: 4.5.2

flutter:
plugin:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.3

* Added serverAuthCode in GoogleSignInUserData.

## 1.1.2

* Update lower bound of dart dependency to 2.1.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ class GoogleSignInUserData {
/// Uses the given data to construct an instance. Any of these parameters
/// could be null.
GoogleSignInUserData(
{this.displayName, this.email, this.id, this.photoUrl, this.idToken});
{this.displayName,
this.email,
this.id,
this.photoUrl,
this.idToken,
this.serverAuthCode});

/// The display name of the signed in user.
///
Expand Down Expand Up @@ -62,9 +67,13 @@ class GoogleSignInUserData {
/// data.
String idToken;

/// Authorization code required to make API calls from the server.
/// Read more on <https://developers.google.com/identity/sign-in/android/offline-access>
String serverAuthCode;

@override
int get hashCode =>
hashObjects(<String>[displayName, email, id, photoUrl, idToken]);
int get hashCode => hashObjects(
<String>[displayName, email, id, photoUrl, idToken, serverAuthCode]);

@override
bool operator ==(dynamic other) {
Expand All @@ -75,7 +84,8 @@ class GoogleSignInUserData {
otherUserData.email == email &&
otherUserData.id == id &&
otherUserData.photoUrl == photoUrl &&
otherUserData.idToken == idToken;
otherUserData.idToken == idToken &&
otherUserData.serverAuthCode == serverAuthCode;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ GoogleSignInUserData getUserDataFromMap(Map<String, dynamic> data) {
return null;
}
return GoogleSignInUserData(
displayName: data['displayName'],
email: data['email'],
id: data['id'],
photoUrl: data['photoUrl'],
idToken: data['idToken']);
displayName: data['displayName'],
email: data['email'],
id: data['id'],
photoUrl: data['photoUrl'],
idToken: data['idToken'],
serverAuthCode: data['serverAuthCode'],
);
}

/// Converts token data coming from native code into the proper platform interface type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A common platform interface for the google_sign_in plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.1.2
version: 1.1.3

dependencies:
flutter:
Expand Down