Skip to content

Commit 72571a0

Browse files
feat(ui_auth): use google_sign_in on macOS (#255)
* 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 <[email protected]> * Update docs/firebase-ui-auth/providers/oauth.md Co-authored-by: Russell Wheatley <[email protected]> * Update docs/firebase-ui-auth/providers/oauth.md Co-authored-by: Russell Wheatley <[email protected]> * Update docs/firebase-ui-auth/providers/oauth.md Co-authored-by: Russell Wheatley <[email protected]> * Update docs/firebase-ui-auth/providers/oauth.md Co-authored-by: Russell Wheatley <[email protected]> --------- Co-authored-by: Russell Wheatley <[email protected]>
1 parent bab2975 commit 72571a0

File tree

6 files changed

+89
-123
lines changed

6 files changed

+89
-123
lines changed

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

+51
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,59 @@ Now all pre-built screens that support multiple providers (such as `RegisterScre
3535

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

38+
For iOS and macOS, `clientId` can be found in the `GoogleService-Info.plist` file available in the Firebase console under Firebase project settings.
39+
40+
For example, if your `GoogleService-Info.plist` looks like this:
41+
42+
```xml
43+
<?xml version="1.0" encoding="UTF-8"?>
44+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
45+
<plist version="1.0">
46+
<dict>
47+
<key>CLIENT_ID</key>
48+
<string>your-client-id.apps.googleusercontent.com</string>
49+
<!-- more keys -->
50+
</dict>
51+
```
52+
53+
you should set `clientId` to `your-client-id.apps.googleusercontent.com`:
54+
55+
```dart
56+
GoogleProvider(clientId: 'your-client-id.apps.googleusercontent.com'),
57+
```
58+
59+
Additionally, you need to add the following to your `Info.plist` file:
60+
61+
```xml
62+
<key>CFBundleURLTypes</key>
63+
<array>
64+
<dict>
65+
<key>CFBundleTypeRole</key>
66+
<string>Editor</string>
67+
<key>CFBundleURLSchemes</key>
68+
<array>
69+
<string>com.googleusercontent.apps.your-client-id</string>
70+
</array>
71+
</dict>
72+
</array>
73+
```
74+
75+
For Linux and Windows, `clientId` should be set to a web client id:
76+
3877
![Google app client ID](../images/ui-google-provider-client-id.png)
3978

79+
```dart
80+
const iOSClientId = 'your-client-id.apps.googleusercontent.com';
81+
const webClientId = 'your-web-client-id.apps.googleusercontent.com';
82+
83+
String get googleClientId {
84+
return switch (defaultTargetPlatform) {
85+
TargetPlatfrom.iOS || TargetPlatform.macOS => iOSClientId,
86+
_ => webClientId,
87+
}
88+
}
89+
```
90+
4091
See [Custom screens section](#custom-screens) to learn how to use a button on your custom screen.
4192

4293
## Sign in with Apple

packages/firebase_ui_auth/example/lib/config.dart

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: do_not_use_environment, constant_identifier_names
5+
// ignore_for_file: do_not_use_environment, constant_identifier_names, non_constant_identifier_names
6+
7+
import 'package:flutter/foundation.dart';
8+
9+
String get GOOGLE_CLIENT_ID {
10+
if (defaultTargetPlatform == TargetPlatform.macOS) {
11+
return '406099696497-65v1b9ffv6sgfqngfjab5ol5qdikh2rm.apps.googleusercontent.com';
12+
} else {
13+
return '448618578101-sg12d2qin42cpr00f8b0gehs5s7inm0v.apps.googleusercontent.com';
14+
}
15+
}
616

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

packages/firebase_ui_auth/example/macos/Runner/Info.plist

+11
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,16 @@
2828
<string>MainMenu</string>
2929
<key>NSPrincipalClass</key>
3030
<string>NSApplication</string>
31+
<key>CFBundleURLTypes</key>
32+
<array>
33+
<dict>
34+
<key>CFBundleTypeRole</key>
35+
<string>Editor</string>
36+
<key>CFBundleURLSchemes</key>
37+
<array>
38+
<string>com.googleusercontent.apps.406099696497-65v1b9ffv6sgfqngfjab5ol5qdikh2rm</string>
39+
</array>
40+
</dict>
41+
</array>
3142
</dict>
3243
</plist>

packages/firebase_ui_auth/example/macos/Runner/Release.entitlements

+4
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@
1010
<true/>
1111
<key>com.apple.security.network.client</key>
1212
<true/>
13+
<key>keychain-access-groups</key>
14+
<array>
15+
<string>$(AppIdentifierPrefix)com.google.GIDSignIn</string>
16+
</array>
1317
</dict>
1418
</plist>

packages/firebase_ui_oauth/example/macos/Runner/GoogleSignInMacOS.swift

-119
This file was deleted.

packages/firebase_ui_oauth_google/lib/src/provider.dart

+12-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ class GoogleProvider extends OAuthProvider {
8888
});
8989
}
9090

91+
@override
92+
void desktopSignIn(AuthAction action) {
93+
// google_sign_in supports macOS, so mobile auth flow works.
94+
if (defaultTargetPlatform == TargetPlatform.macOS) {
95+
mobileSignIn(action);
96+
} else {
97+
super.desktopSignIn(action);
98+
}
99+
}
100+
91101
@override
92102
OAuthCredential fromDesktopAuthResult(AuthResult result) {
93103
return fba.GoogleAuthProvider.credential(
@@ -99,7 +109,8 @@ class GoogleProvider extends OAuthProvider {
99109
@override
100110
Future<void> logOutProvider() async {
101111
if (defaultTargetPlatform == TargetPlatform.android ||
102-
defaultTargetPlatform == TargetPlatform.iOS) {
112+
defaultTargetPlatform == TargetPlatform.iOS ||
113+
defaultTargetPlatform == TargetPlatform.macOS) {
103114
await provider.signOut();
104115
}
105116
}

0 commit comments

Comments
 (0)