Skip to content

Commit

Permalink
fix(ui_auth, ui_oauth_google): allow GoogleService-Info.plist based c…
Browse files Browse the repository at this point in the history
…onfiguration (#10360)
  • Loading branch information
lesnitsky authored Feb 9, 2023
1 parent 538090f commit 162597f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
31 changes: 23 additions & 8 deletions packages/firebase_ui_oauth_google/lib/src/provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>? scopes;

late GoogleSignIn provider;
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_ui_oauth_google/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 162597f

Please sign in to comment.