Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server auth code #9

Open
wants to merge 4 commits into
base: kawlu
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public void init(
"default_web_client_id", "string", registrar.context().getPackageName());
if (clientIdIdentifier != 0) {
optionsBuilder.requestIdToken(registrar.context().getString(clientIdIdentifier));
optionsBuilder.requestServerAuthCode(registrar.context().getString(clientIdIdentifier));
}
for (String scope : requestedScopes) {
optionsBuilder.requestScopes(new Scope(scope));
Expand Down Expand Up @@ -361,6 +362,7 @@ private void onSignInAccount(GoogleSignInAccount account) {
response.put("id", account.getId());
response.put("idToken", account.getIdToken());
response.put("displayName", account.getDisplayName());
response.put("serverAuthCode", account.getServerAuthCode());
if (account.getPhotoUrl() != null) {
response.put("photoUrl", account.getPhotoUrl().toString());
}
Expand Down
4 changes: 4 additions & 0 deletions packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// for more info.
static NSString *const kClientIdKey = @"CLIENT_ID";

static NSString *const kServerClientIdKey = @"SERVER_CLIENT_ID";

// These error codes must match with ones declared on Android and Dart sides.
static NSString *const kErrorReasonSignInRequired = @"sign_in_required";
static NSString *const kErrorReasonSignInCanceled = @"sign_in_canceled";
Expand Down Expand Up @@ -73,6 +75,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
if (path) {
NSMutableDictionary *plist = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
[GIDSignIn sharedInstance].clientID = plist[kClientIdKey];
[GIDSignIn sharedInstance].serverClientID = plist[kServerClientIdKey];
[GIDSignIn sharedInstance].scopes = call.arguments[@"scopes"];
[GIDSignIn sharedInstance].hostedDomain = call.arguments[@"hostedDomain"];
result(nil);
Expand Down Expand Up @@ -173,6 +176,7 @@ - (void)signIn:(GIDSignIn *)signIn
@"email" : user.profile.email ?: [NSNull null],
@"id" : user.userID ?: [NSNull null],
@"photoUrl" : [photoUrl absoluteString] ?: [NSNull null],
@"serverAuthCode" : user.serverAuthCode ?: [NSNull null]
}
error:nil];
}
Expand Down
15 changes: 13 additions & 2 deletions packages/google_sign_in/lib/google_sign_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class GoogleSignInAuthentication {
/// The OAuth2 access token to access Google services.
String get accessToken => _data['accessToken'];

String get serverAuthCode => _data['serverAuthCode'];

@override
String toString() => 'GoogleSignInAuthentication:$_data';
}
Expand All @@ -36,7 +38,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 @@ -61,6 +64,9 @@ 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 @@ -91,6 +97,10 @@ 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 @@ -123,7 +133,8 @@ class GoogleSignInAccount implements GoogleIdentity {
email == otherAccount.email &&
id == otherAccount.id &&
photoUrl == otherAccount.photoUrl &&
_idToken == otherAccount._idToken;
_idToken == otherAccount._idToken &&
_serverAuthCode == otherAccount._serverAuthCode;
}

@override
Expand Down
2 changes: 1 addition & 1 deletion packages/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.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in
version: 4.0.8
version: 4.0.8+1

flutter:
plugin:
Expand Down