Skip to content

Commit

Permalink
feat(ui_auth): use google_sign_in on macOS (#255)
Browse files Browse the repository at this point in the history
* feat(ui_auth): use google_sign_in on macOS

* chore: drop unused file

* Update docs/firebase-ui-auth/providers/oauth.md

Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com>

* Update docs/firebase-ui-auth/providers/oauth.md

Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com>

* Update docs/firebase-ui-auth/providers/oauth.md

Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com>

* Update docs/firebase-ui-auth/providers/oauth.md

Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com>

* Update docs/firebase-ui-auth/providers/oauth.md

Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com>

---------

Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com>
  • Loading branch information
lesnitsky and russellwheatley authored Jan 17, 2024
1 parent bab2975 commit 72571a0
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 123 deletions.
51 changes: 51 additions & 0 deletions docs/firebase-ui-auth/providers/oauth.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,59 @@ Now all pre-built screens that support multiple providers (such as `RegisterScre

The configuration requires the `clientId` property (which can be found in the Firebase Console) to be set for seamless cross-platform support.

For iOS and macOS, `clientId` can be found in the `GoogleService-Info.plist` file available in the Firebase console under Firebase project settings.

For example, if your `GoogleService-Info.plist` looks like this:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>your-client-id.apps.googleusercontent.com</string>
<!-- more keys -->
</dict>
```

you should set `clientId` to `your-client-id.apps.googleusercontent.com`:

```dart
GoogleProvider(clientId: 'your-client-id.apps.googleusercontent.com'),
```

Additionally, you need to add the following to your `Info.plist` file:

```xml
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.your-client-id</string>
</array>
</dict>
</array>
```

For Linux and Windows, `clientId` should be set to a web client id:

![Google app client ID](../images/ui-google-provider-client-id.png)

```dart
const iOSClientId = 'your-client-id.apps.googleusercontent.com';
const webClientId = 'your-web-client-id.apps.googleusercontent.com';
String get googleClientId {
return switch (defaultTargetPlatform) {
TargetPlatfrom.iOS || TargetPlatform.macOS => iOSClientId,
_ => webClientId,
}
}
```

See [Custom screens section](#custom-screens) to learn how to use a button on your custom screen.

## Sign in with Apple
Expand Down
14 changes: 11 additions & 3 deletions packages/firebase_ui_auth/example/lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// ignore_for_file: do_not_use_environment, constant_identifier_names
// ignore_for_file: do_not_use_environment, constant_identifier_names, non_constant_identifier_names

import 'package:flutter/foundation.dart';

String get GOOGLE_CLIENT_ID {
if (defaultTargetPlatform == TargetPlatform.macOS) {
return '406099696497-65v1b9ffv6sgfqngfjab5ol5qdikh2rm.apps.googleusercontent.com';
} else {
return '448618578101-sg12d2qin42cpr00f8b0gehs5s7inm0v.apps.googleusercontent.com';
}
}

const GOOGLE_CLIENT_ID =
'448618578101-sg12d2qin42cpr00f8b0gehs5s7inm0v.apps.googleusercontent.com';
const GOOGLE_REDIRECT_URI =
'https://react-native-firebase-testing.firebaseapp.com/__/auth/handler';

Expand Down
11 changes: 11 additions & 0 deletions packages/firebase_ui_auth/example/macos/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,16 @@
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.406099696497-65v1b9ffv6sgfqngfjab5ol5qdikh2rm</string>
</array>
</dict>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)com.google.GIDSignIn</string>
</array>
</dict>
</plist>

This file was deleted.

13 changes: 12 additions & 1 deletion packages/firebase_ui_oauth_google/lib/src/provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ class GoogleProvider extends OAuthProvider {
});
}

@override
void desktopSignIn(AuthAction action) {
// google_sign_in supports macOS, so mobile auth flow works.
if (defaultTargetPlatform == TargetPlatform.macOS) {
mobileSignIn(action);
} else {
super.desktopSignIn(action);
}
}

@override
OAuthCredential fromDesktopAuthResult(AuthResult result) {
return fba.GoogleAuthProvider.credential(
Expand All @@ -99,7 +109,8 @@ class GoogleProvider extends OAuthProvider {
@override
Future<void> logOutProvider() async {
if (defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS) {
defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.macOS) {
await provider.signOut();
}
}
Expand Down

0 comments on commit 72571a0

Please sign in to comment.