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

fix(ui_oauth_google): allow GoogleService-Info.plist based configuration #10360

Merged
merged 1 commit into from
Feb 9, 2023
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
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.9
flutter:
sdk: flutter
google_sign_in: ^5.4.0
google_sign_in: ^5.4.4

dev_dependencies:
flutter_test:
Expand Down