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 ability to return serverAuthCode (#2116)
Browse files Browse the repository at this point in the history
  • Loading branch information
yamarkz authored May 19, 2020
1 parent 25a585d commit 88e85c6
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 2 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 @@
## 4.5.0

* Add support for getting `serverAuthCode`.

## 4.4.6

* Update lower bound of dart dependency to 2.1.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ public void init(
.getIdentifier("default_web_client_id", "string", context.getPackageName());
if (clientIdIdentifier != 0) {
optionsBuilder.requestIdToken(context.getString(clientIdIdentifier));
optionsBuilder.requestServerAuthCode(context.getString(clientIdIdentifier));
}
for (String scope : requestedScopes) {
optionsBuilder.requestScopes(new Scope(scope));
Expand Down Expand Up @@ -484,6 +485,7 @@ private void onSignInAccount(GoogleSignInAccount account) {
response.put("email", account.getEmail());
response.put("id", account.getId());
response.put("idToken", account.getIdToken());
response.put("serverAuthCode", account.getServerAuthCode());
response.put("displayName", account.getDisplayName());
if (account.getPhotoUrl() != null) {
response.put("photoUrl", account.getPhotoUrl().toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="default_web_client_id">YOUR_WEB_CLIENT_ID</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
<string>1:479882132969:ios:2643f950e0a0da08</string>
<key>DATABASE_URL</key>
<string>https://my-flutter-proj.firebaseio.com</string>
<key>SERVER_CLIENT_ID</key>
<string>YOUR_SERVER_CLIENT_ID</string>
</dict>
</plist>
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 @@ -76,6 +78,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 @@ -221,6 +224,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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class GoogleSignInAuthentication {
/// The OAuth2 access token to access Google services.
String get accessToken => _data.accessToken;

/// Server auth code used to access Google Login
String get serverAuthCode => _data.serverAuthCode;

@override
String toString() => 'GoogleSignInAuthentication:$_data';
}
Expand Down
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 @@ -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.4.6
version: 4.5.0

flutter:
plugin:
Expand All @@ -16,7 +16,7 @@ flutter:
default_package: google_sign_in_web

dependencies:
google_sign_in_platform_interface: ^1.1.0
google_sign_in_platform_interface: ^1.1.1
flutter:
sdk: flutter
meta: ^1.0.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void main() {
'getTokens': <dynamic, dynamic>{
'idToken': '123',
'accessToken': '456',
'serverAuthCode': '789',
},
};

Expand Down Expand Up @@ -370,6 +371,7 @@ void main() {

expect(auth.accessToken, '456');
expect(auth.idToken, '123');
expect(auth.serverAuthCode, '789');
expect(
log,
<Matcher>[
Expand Down

0 comments on commit 88e85c6

Please sign in to comment.