You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/06-concepts/11-authentication/04-providers/02-google/01-setup.md
+52-26Lines changed: 52 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Setup
2
2
3
-
To set up Sign in with Google, you will need a Google account for your organization and set up a new project. For the project, you need to set up _Credentials_ and _OAuth consent screen_. You will also need to add the `serverpod_auth_idp_flutter` package to your app and do some additional setup depending on each platform.
3
+
To set up Sign in with Google, you will need a Google account for your organization and set up a new project. You will also need to add the `serverpod_auth_idp_flutter` package to your app and do some additional setup depending on each platform.
4
4
5
5
:::note
6
6
Right now, we have official support for iOS, Android, and Web for Google Sign In.
@@ -20,28 +20,54 @@ To be allowed to access user data and use the authentication method in Serverpod
20
20
21
21
[Enable it here](https://console.cloud.google.com/apis/library/people.googleapis.com) or find it yourself by navigating to the _Library_ section under _APIs & Services_. Search for _Google People API_, select it, and click on _Enable_.
22
22
23
-
### Setup OAuth consent screen
23
+
### Configure Google Auth Platform
24
24
25
-
The setup for the OAuth consent screen can be found [here](https://console.cloud.google.com/apis/credentials/consent) or under _APIs & Services_ > _OAuth consent screen_.
25
+
If you haven't already, enable the Google Auth Platform for your project. Navigate to the [Google Auth Platform overview](https://console.cloud.google.com/auth/overview) and click _Get started_.
26
26
27
-
1. Fill in all the required information, for production use you need a domain that adds under `Authorized` domains.
2. Add the scopes `.../auth/userinfo.email` and `.../auth/userinfo.profile`.
29
+
Configure the following settings in the Google Auth Platform:
30
30
31
-
3. Add your email to the test users so that you can test your integration in development mode.
31
+
1.**Data Access**: Navigate to the [Data Access](https://console.cloud.google.com/auth/scopes) page to add the required scopes. Add the scopes `.../auth/userinfo.email` and `.../auth/userinfo.profile`.
If you need access to additional Google APIs (e.g., Calendar, Drive), you can add more scopes here. See [Accessing Google APIs](./configuration#accessing-google-apis) for details on requesting additional scopes and using them with the `getExtraGoogleInfoCallback` on the server.
37
+
:::
38
+
39
+
1.**Audience**: Navigate to the [Audience](https://console.cloud.google.com/auth/audience) page to add test users. Add your email so you can test your integration in development mode.
40
+
41
+
:::tip
42
+
For production apps, you can configure additional branding options on the [Branding](https://console.cloud.google.com/auth/branding) page. See the [Google Auth Platform documentation](https://developers.google.com/identity/protocols/oauth2) for more details.
43
+
:::
44
+
35
45
## Server-side configuration
36
46
37
-
Create the server credentials in the Google Cloud Console. Navigate to _Credentials_ under _APIs & Services_. Click _Create Credentials_ and select _OAuth client ID_. Configure the OAuth client as a _**Web application**_. If you have a domain add it to the `Authorized JavaScript origins` and `Authorized redirect URIs`. For development purposes we can add `http://localhost:8082` to both fields, this is the address to the web server.
47
+
Create the server credentials in the Google Auth Platform. Navigate to _Clients_ and click _Create Client_. Configure the OAuth client as a _**Web application**_. If you have a domain add it to the `Authorized JavaScript origins` and `Authorized redirect URIs`. For development purposes, we can add `http://localhost:8082` to both fields, which is the address to the web server.
Download the JSON file for your web application OAuth client. This file contains both the client id and the client secret. You will need to supply the contents of the file to the `clientSecret` property of the `GoogleIdpConfig` object.
42
52
43
53
This can be done by pasting the contents of the JSON file into the `googleClientSecret` key in the `config/passwords.yaml` file or setting as value of the `SERVERPOD_PASSWORD_googleClientSecret` environment variable. Alternatively, you can read the file contents directly using the `GoogleClientSecret.fromJsonFile()` method.
In your main `server.dart` file, configure the Google identity provider:
46
72
47
73
```dart
@@ -103,27 +129,27 @@ For our client-side configurations, we have to first create client-side credenti
103
129
104
130
### iOS
105
131
106
-
Create the client credentials. Navigate to _Credentials_ under _APIs & Services_. Click _Create Credentials_ and select _OAuth client ID_. Configure the OAuth client as Application type _**iOS**_.
132
+
Create the client credentials in the Google Auth Platform. Navigate to _Clients_ and click _Create Client_. Configure the OAuth client as Application type _**iOS**_.
107
133
108
-
Fill in all the required information, and create the credentials. Then download the `plist` file rename it to `GoogleService-Info.plist` and put it inside your ios project folder. Then drag and drop it into your XCode project to include the file in your build.
134
+
Fill in all the required information and create the credentials. Download the `plist` file - you'll need to extract values from it to configure your app.
109
135
110
-
Open the `GoogleService-Info.plist`in your editor and add the SERVER_CLIENT_ID if it does not exist:
136
+
Open your `ios/Runner/Info.plist` file and add the following keys:
111
137
112
138
```xml
113
139
<dict>
114
140
...
115
-
<key>SERVER_CLIENT_ID</key>
141
+
<key>GIDClientID</key>
142
+
<string>your_ios_client_id</string>
143
+
<key>GIDServerClientID</key>
116
144
<string>your_server_client_id</string>
117
145
</dict>
118
146
```
119
147
120
-
Replace `your_server_client_id` with the client id from the JSON file you put inside the config folder in the server.
148
+
Replace `your_ios_client_id` with the `CLIENT_ID` value from the downloaded plist file, and `your_server_client_id` with the client ID from the server credentials JSON file.
121
149
122
150
#### Add the URL scheme
123
151
124
-
To allow us to navigate back to the app after the user has signed in we have to add the URL Scheme, the scheme is the reversed client ID of your iOS app. You can find it inside the `GoogleService-Info.plist` file.
125
-
126
-
Open the `info.plist` file in your editor and add the following to register the URL Scheme.
152
+
To allow navigation back to the app after sign-in, add the URL scheme to your `Info.plist`. The scheme is the reversed client ID of your iOS app (found as `REVERSED_CLIENT_ID` in the downloaded plist file).
127
153
128
154
```xml
129
155
<dict>
@@ -135,22 +161,22 @@ Open the `info.plist` file in your editor and add the following to register the
Replace `your_reversed_client_id`with your reversed client ID.
171
+
Replace the URL scheme with your actual reversed client ID.
146
172
147
173
:::info
148
174
If you have any social logins in your app you also need to integrate "Sign in with Apple" to publish your app to the app store. ([Read more](https://developer.apple.com/sign-in-with-apple/get-started/)).
149
175
:::
150
176
151
177
### Android
152
178
153
-
Create the client credentials. Navigate to _Credentials_ under _APIs & Services_. Click _Create Credentials_ and select _OAuth client ID_. Configure the OAuth client as Application type _**Android**_.
179
+
Create the client credentials in the Google Auth Platform. Navigate to _Clients_ and click _Create Client_. Configure the OAuth client as Application type _**Android**_.
154
180
155
181
Fill in all required information, you can get the debug SHA-1 hash by running `./gradlew signingReport` in your Android project directory. Create the credentials and download the JSON file.
If you encounter issues with Google Sign-In on Android, check the [official troubleshooting guide](https://pub.dev/packages/google_sign_in_android#troubleshooting) for common solutions.
195
+
:::
196
+
167
197
### Web
168
198
169
-
There is no need to create any client credentials for the web, since it uses the same client ID as the server. However, you have to modify the server credentials inside the Google Cloud Console.
199
+
There is no need to create any client credentials for the web, since it uses the same client ID as the server. However, you have to modify the server credentials in the Google Auth Platform.
170
200
171
-
Navigate to _Credentials_ under _APIs & Services_and select the server credentials. Under `Authorized JavaScript origins` and `Authorized redirect URIs` add the domain for your Flutter app, for development, this is `http://localhost:<port>` where the port is the port you are using.
201
+
Navigate to _Clients_ and select the server credentials (the one configured as a _**Web application**_). Under `Authorized JavaScript origins` and `Authorized redirect URIs` add the domain for your Flutter app, for development, this is `http://localhost:<port>` where the port is the port you are using.
172
202
173
203
:::info
174
204
Force flutter to run on a specific port by running.
@@ -178,11 +208,7 @@ $ flutter run -d chrome --web-port=49660
178
208
```
179
209
:::
180
210
181
-
Set up the actual redirect URI where the user will navigate after the sign-in. You can choose any path you want but it has to be the same in the credentials, your server, and Flutter configurations.
182
-
183
-
For example, using the path `/googlesignin`.
184
-
185
-
For development inside `Authorized redirect URIs` add `http://localhost:8082/googlesignin`, in production use `https://example.com/googlesignin`.
211
+
Set up the redirect URI where the user will navigate after sign-in. For development, add `http://localhost:8082` inside `Authorized redirect URIs`. In production, use your server's domain (e.g., `https://example.com`).
186
212
187
213
Then, on the `web/index.html` file, add the following to the `<head>` section:
Copy file name to clipboardExpand all lines: docs/06-concepts/11-authentication/04-providers/02-google/02-configuration.md
+46-1Lines changed: 46 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ final googleIdpConfig = GoogleIdpConfigFromPasswords(
67
67
68
68
The default setup allows access to basic user information, such as email, profile image, and name. You may require additional access scopes, such as accessing a user's calendar, contacts, or files. To do this, you will need to:
69
69
70
-
- Add the required scopes to the OAuth consent screen.
70
+
- Add the required scopes to the [Data Access](./setup#configure-google-auth-platform) page in the Google Auth Platform.
71
71
- Request access to the scopes when signing in. Do this by setting the `scopes` parameter of the `GoogleSignInWidget` or `GoogleAuthController`.
72
72
73
73
A full list of available scopes can be found [here](https://developers.google.com/identity/protocols/oauth2/scopes).
@@ -122,3 +122,48 @@ If lightweight sign-in fails (e.g., no previous session exists or the user dismi
122
122
:::note
123
123
The lightweight sign-in attempt happens automatically when the controller is initialized, typically at app launch. If successful, users will be signed in without any additional interaction.
124
124
:::
125
+
126
+
### Configuring Client IDs on the App
127
+
128
+
If no client IDs are provided programmatically, the underlying `google_sign_in` package falls back to reading from platform-specific configuration files (e.g., `GoogleService-Info.plist` for iOS, `google-services.json` for Android). To set them programmatically, you can use the following methods.
129
+
130
+
#### Passing Client IDs in Code
131
+
132
+
You can pass the client IDs directly when initializing the Google Sign-In service:
This approach is useful when you need different client IDs per platform and want to manage them in your Dart code.
142
+
143
+
#### Using Environment Variables
144
+
145
+
Alternatively, you can pass client IDs during build time using the `--dart-define` option. The Google Sign-In provider supports the following environment variables:
146
+
147
+
-`GOOGLE_CLIENT_ID`: The platform-specific OAuth client ID
148
+
-`GOOGLE_SERVER_CLIENT_ID`: The server (web application) OAuth client ID
149
+
150
+
If `clientId` and `serverClientId` values are not supplied when initializing the service, the provider will automatically fetch them from these environment variables.
0 commit comments