Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
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
5 changes: 5 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,8 @@
## 5.0.1

* Update platforms `init` function to prioritize `clientId` property when available;
* Updates `google_sign_in_platform_interface` version.

## 5.0.0

* Migrate to null safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public void onMethodCall(MethodCall call, Result result) {
String signInOption = call.argument("signInOption");
List<String> requestedScopes = call.argument("scopes");
String hostedDomain = call.argument("hostedDomain");
delegate.init(result, signInOption, requestedScopes, hostedDomain);
String clientId = call.argument("clientId");
delegate.init(result, signInOption, requestedScopes, hostedDomain, clientId);
break;

case METHOD_SIGN_IN_SILENTLY:
Expand Down Expand Up @@ -188,7 +189,11 @@ public void onMethodCall(MethodCall call, Result result) {
public interface IDelegate {
/** Initializes this delegate so that it is ready to perform other operations. */
public void init(
Result result, String signInOption, List<String> requestedScopes, String hostedDomain);
Result result,
String signInOption,
List<String> requestedScopes,
String hostedDomain,
String clientId);

/**
* Returns the account information for the user who is signed in to this app. If no user is
Expand Down Expand Up @@ -309,7 +314,11 @@ private void checkAndSetPendingOperation(String method, Result result, Object da
*/
@Override
public void init(
Result result, String signInOption, List<String> requestedScopes, String hostedDomain) {
Result result,
String signInOption,
List<String> requestedScopes,
String hostedDomain,
String clientId) {
try {
GoogleSignInOptions.Builder optionsBuilder;

Expand All @@ -334,7 +343,10 @@ public void init(
context
.getResources()
.getIdentifier("default_web_client_id", "string", context.getPackageName());
if (clientIdIdentifier != 0) {
if (!Strings.isNullOrEmpty(clientId)) {
optionsBuilder.requestIdToken(clientId);
optionsBuilder.requestServerAuthCode(clientId);
} else if (clientIdIdentifier != 0) {
optionsBuilder.requestIdToken(context.getString(clientIdIdentifier));
optionsBuilder.requestServerAuthCode(context.getString(clientIdIdentifier));
}
Expand Down
2 changes: 2 additions & 0 deletions packages/google_sign_in/google_sign_in/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';

GoogleSignIn _googleSignIn = GoogleSignIn(
// Optional clientId
// clientId: '479882132969-9i9aqik3jfjd7qhci1nqf0bm2g71rm1u.apps.googleusercontent.com',
scopes: <String>[
'email',
'https://www.googleapis.com/auth/contacts.readonly',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
ofType:@"plist"];
if (path) {
NSMutableDictionary *plist = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
[GIDSignIn sharedInstance].clientID = plist[kClientIdKey];
BOOL hasDynamicClientId =
[[call.arguments valueForKey:@"clientId"] isKindOfClass:[NSString class]];

if (hasDynamicClientId) {
[GIDSignIn sharedInstance].clientID = [call.arguments valueForKey:@"clientId"];
} else {
[GIDSignIn sharedInstance].clientID = plist[kClientIdKey];
}

[GIDSignIn sharedInstance].serverClientID = plist[kServerClientIdKey];
[GIDSignIn sharedInstance].scopes = call.arguments[@"scopes"];
[GIDSignIn sharedInstance].hostedDomain = call.arguments[@"hostedDomain"];
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: 5.0.0
version: 5.0.1

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

dependencies:
google_sign_in_platform_interface: ^2.0.0
google_sign_in_platform_interface: ^2.0.1
google_sign_in_web: ^0.10.0
flutter:
sdk: flutter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ void main() {
);
});

test('signIn prioritize clientId parameter when available', () async {
final fakeClientId = 'fakeClientId';
googleSignIn = GoogleSignIn(clientId: fakeClientId);
await googleSignIn.signIn();
expect(googleSignIn.currentUser, isNotNull);
expect(
log,
<Matcher>[
isMethodCall('init', arguments: <String, dynamic>{
'signInOption': 'SignInOption.standard',
'scopes': <String>[],
'hostedDomain': null,
'clientId': fakeClientId,
}),
isMethodCall('signIn', arguments: null),
],
);
});

test('signOut', () async {
await googleSignIn.signOut();
expect(googleSignIn.currentUser, isNull);
Expand Down