From 162597f4556b1e0da0601db08574f41ac3585500 Mon Sep 17 00:00:00 2001 From: Andrei Lesnitsky Date: Thu, 9 Feb 2023 13:15:52 +0100 Subject: [PATCH] fix(ui_auth, ui_oauth_google): allow GoogleService-Info.plist based configuration (#10360) --- .../lib/src/provider.dart | 31 ++++++++++++++----- .../firebase_ui_oauth_google/pubspec.yaml | 2 +- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/firebase_ui_oauth_google/lib/src/provider.dart b/packages/firebase_ui_oauth_google/lib/src/provider.dart index fd0f78590c6a..f5d776a81764 100644 --- a/packages/firebase_ui_oauth_google/lib/src/provider.dart +++ b/packages/firebase_ui_oauth_google/lib/src/provider.dart @@ -13,10 +13,19 @@ class GoogleProvider extends OAuthProvider { final providerId = 'google.com'; /// The Google client ID. - /// Will be ignored on Android since it's not needed. + /// Primarily required for desktop platforms. + /// Ignored on Android and iOS (if `iOSPreferPlist` is true). final String clientId; + /// When true, the Google Sign In plugin will use the GoogleService-Info.plist + /// for configuration instead of the `clientId` parameter. + final bool iOSPreferPlist; + + /// The redirect URL to use for the Google Sign In plugin. + /// Required on desktop platforms. final String? redirectUri; + + /// The list of requested authroization scopes requested when signing in. final List? scopes; late GoogleSignIn provider; @@ -37,25 +46,31 @@ class GoogleProvider extends OAuthProvider { required this.clientId, this.redirectUri, this.scopes, + this.iOSPreferPlist = false, }) { firebaseAuthProvider.setCustomParameters(const { 'prompt': 'select_account', }); - // `clientId` is not supported on Android and is misinterpreted as a - // `serverClientId`. This is a workaround to avoid the error. - if (defaultTargetPlatform == TargetPlatform.android) { - provider = GoogleSignIn( - scopes: scopes ?? [], - ); + if (_ignoreClientId()) { + provider = GoogleSignIn(scopes: scopes ?? []); } else { provider = GoogleSignIn( - scopes: scopes ?? [], clientId: clientId, + scopes: scopes ?? [], ); } } + bool _ignoreClientId() { + if (defaultTargetPlatform == TargetPlatform.android) return true; + if (defaultTargetPlatform == TargetPlatform.iOS && iOSPreferPlist) { + return true; + } + + return false; + } + @override void mobileSignIn(AuthAction action) async { provider.signIn().then((user) { diff --git a/packages/firebase_ui_oauth_google/pubspec.yaml b/packages/firebase_ui_oauth_google/pubspec.yaml index d7a3e7369c2f..a68792a0d092 100644 --- a/packages/firebase_ui_oauth_google/pubspec.yaml +++ b/packages/firebase_ui_oauth_google/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: firebase_ui_oauth: ^1.1.10 flutter: sdk: flutter - google_sign_in: ^5.4.0 + google_sign_in: ^5.4.4 dev_dependencies: flutter_test: