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
{{ message }}
Repository navigation
Commit 5351001
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/06-concepts/11-authentication/04-providers/01-email.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ await pod.start();
34
34
35
35
:::info
36
36
37
-
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/chat/chat_server/lib/server.dart).
37
+
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/legacy/chat/chat_server/lib/server.dart).
Copy file name to clipboardExpand all lines: versioned_docs/version-1.0.0/04-concepts/07-authentication.md
+18-3Lines changed: 18 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
1
# Authentication
2
+
2
3
Serverpod comes with built-in user management and authentication. You can either build your custom authentication method or use the `serverpod_auth` module. The module makes it easy to authenticate with email or social sign-ins.
3
4
4
5
## The basics
@@ -20,6 +21,7 @@ It's most common to use the `auth` module for handling sign ins, but you can als
20
21
:::
21
22
22
23
### Restricting access to endpoints
24
+
23
25
It is common to want to restrict access to an endpoint to users that have signed in. You can do this by overriding the `requireLogin` property of the `Endpoint` class.
Serverpod's auth module makes it easy to authenticate users through email or 3rd parties. Currently supported is Signing in with email, Google, Apple, and Firebase. Future versions of the authentication module will include more options. Using this module requires some setup with Google and Apple to work.
57
60
58
61
The authentication module also handles basic user information, such as user names and profile pictures.
@@ -62,6 +65,7 @@ The authentication module also handles basic user information, such as user name
62
65
Please refer to the previous section, [Modules](./modules), for instructions on how to add a module to your project.
63
66
64
67
## App setup
68
+
65
69
First, add dependencies to your app's `pubspec.yaml` file for the methods of signing in that you want to support. Make sure to use the same version numbers as for Serverpod itself.
66
70
67
71
```yaml
@@ -71,7 +75,7 @@ dependencies:
71
75
serverpod_flutter: ^1.x.x
72
76
auth_example_client:
73
77
path: ../auth_example_client
74
-
78
+
75
79
serverpod_auth_shared_flutter: ^1.x.x
76
80
serverpod_auth_email_flutter: ^1.x.x
77
81
serverpod_auth_google_flutter: ^1.x.x
@@ -107,11 +111,13 @@ void main() async {
107
111
```
108
112
109
113
The `SessionManager` has useful methods for viewing and monitoring the user's current state:
114
+
110
115
- The `signedInUser` will return a `UserInfo` if the user is currently signed in (or `null` if the user isn't signed in).
111
116
- Use the `addListener` method to get notified of changes to the user's signed in state.
112
117
- Sign out a user by calling the `signOut` method.
113
118
114
119
## Setting up Sign in with Email
120
+
115
121
To properly configure Sign in with Email, you must connect your Serverpod to an external service that can send the emails. One convenient option is the [mailer](https://pub.dev/packages/mailer) package, which can send emails through any SMTP service. Most email providers, such as Sendgrid or Mandrill, support SMTP.
116
122
117
123
In your main `server.dart` file, you can configure the auth module. First, make sure to include the module:
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/chat/chat_server/lib/server.dart).
147
+
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/legacy/chat/chat_server/lib/server.dart).
141
148
142
149
:::
143
150
144
151
In your app, you will need to add the `serverpod_auth_email_flutter` package to your `pubspec.yaml`. The package includes both methods for creating a custom email sign-in form and a pre-made `SignInWithEmailButton` widget. If you are building custom forms, it is helpful to read the documentation provided in the module and review the code in the [SignInWithEmailDialog](https://github.com/serverpod/serverpod/blob/main/modules/serverpod_auth/serverpod_auth_email_flutter/lib/src/signin_dialog.dart).
145
152
146
153
## Setting up Sign in with Google
154
+
147
155
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_google_flutter` package to your app and do some additional setup depending on each platform.
148
156
149
157
### Configure Google Cloud console and your server
158
+
150
159
In the Google Cloud console, you need to set up a few things:
151
160
152
161
1. Activate the _People API_ for your project. You find it in _APIs & Services_ > _Enabled APIs & services_.
@@ -155,7 +164,7 @@ In the Google Cloud console, you need to set up a few things:
155
164
- Add `.../auth/userinfo.email` and `.../auth/userinfo.profile` to your `Scopes`.
156
165
3. Add OAuth 2.0 credentials for your web application. Do this under _APIs & Services_ > _Credentials_.
157
166
- Create a _Web application OAuth Client ID_. This is required even if you only want to provide sign-in with iOS or Android, as the server uses it to access Google's APIs.
158
-
- For _Authorized JavaScript origins`, enter your domain name.
167
+
- For \_Authorized JavaScript origins`, enter your domain name.
159
168
- For _Authorized redirect URIs_, enter your domain name. You may also want to add your development server here, e.g., `http://localhost:8080`.
160
169
- Download the JSON file for your web application OAuth client. This file contains both the client id and the client secret. Rename the file to `google_client_secret.json` and place it in your server's `config` directory.
161
170
4. Add OAuth 2.0 credentials for iOS and Android.
@@ -172,6 +181,7 @@ The `google_client_secret.json` contains a private key and should not be version
172
181
:::
173
182
174
183
### Configure your app
184
+
175
185
You need to take platform-dependent steps to configure Sign in with Google in your app.
176
186
177
187
- Add the `serverpod_auth_google_flutter` package to your app.
@@ -185,6 +195,7 @@ Rather than using the `GoogleService-Info.plist` file for iOS, you can pass the
185
195
:::
186
196
187
197
### Calling Google APIs
198
+
188
199
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:
189
200
190
201
- Add the required scopes to the OAuth consent screen.
@@ -227,11 +238,13 @@ Adding additional scopes may require approval by Google. On the OAuth consent sc
227
238
:::
228
239
229
240
## Setting up Sign in with Apple
241
+
230
242
You will need an Apple developer account to configure Sign in with Apple. Follow the instructions in [sign_in_with_apple](https://pub.dev/packages/sign_in_with_apple).
231
243
232
244
_Note that Sign in with Apple may not work on some versions of the Simulator (iOS 13.5 works). This issue doesn't affect real devices._
233
245
234
246
## Setting up Sign in with Firebase
247
+
235
248
Serverpod uses FlutterFire UI to handle authentication through Firebase. It allows you to add social sign-in types that Serverpod doesn't directly support.
236
249
237
250
To add authentication with Firebase, you must first install and initialize the Firebase CLI tools and Flutter fire. Follow the instructions [here](https://firebase.google.com/docs/flutter/setup?platform=web) for your Flutter project. In the Firebase console, configure the different social sign-ins you plan to use. Then pass your provider configurations to either the signInWithFirebase method or the SignInWithFirebaseButton of the [serverpod_auth_firebase_flutter](https://pub.dev/packages/serverpod_auth_firebase_flutter) package.
@@ -245,6 +258,7 @@ Serverpod automatically merges accounts that are using the same email addresses,
245
258
:::
246
259
247
260
## Working with users
261
+
248
262
It's a common task to read or update user information on your server. You can always retrieve the id of a signed-in user through the session object.
249
263
250
264
```dart
@@ -266,6 +280,7 @@ The `Users` class contains many other convenient methods for working with users.
266
280
:::
267
281
268
282
## Displaying or editing user images
283
+
269
284
The module has built-in methods for handling a user's basic settings, including uploading new profile pictures.
Copy file name to clipboardExpand all lines: versioned_docs/version-1.1.0/04-concepts/09-authentication.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -140,7 +140,7 @@ await pod.start();
140
140
```
141
141
:::info
142
142
143
-
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/chat/chat_server/lib/server.dart).
143
+
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/legacy/chat/chat_server/lib/server.dart).
Copy file name to clipboardExpand all lines: versioned_docs/version-1.1.1/05-concepts/09-authentication/04-providers/01-email.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,10 +8,9 @@ A comprehensive tutorial covering email/password sign-in complete with sending t
8
8
You need to install the auth module before you continue, see [Setup](../setup).
9
9
:::
10
10
11
-
12
11
## Server-side Configuration
13
12
14
-
In your main `server.dart` file, import the `serverpod_auth_server` module, and set up the authentication configuration:
13
+
In your main `server.dart` file, import the `serverpod_auth_server` module, and set up the authentication configuration:
15
14
16
15
```dart
17
16
import 'package:serverpod_auth_server/module.dart' as auth;
@@ -35,7 +34,7 @@ await pod.start();
35
34
36
35
:::info
37
36
38
-
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/chat/chat_server/lib/server.dart).
37
+
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/legacy/chat/chat_server/lib/server.dart).
39
38
40
39
:::
41
40
@@ -79,7 +78,6 @@ The triggered modal will look like this:
The `serverpod_auth_email_flutter` module provides the `EmailAuthController` class, which encapsulates the functionality for email/password authentication. You can use this class and create a custom UI for user registration, login, and password management.
Copy file name to clipboardExpand all lines: versioned_docs/version-1.2.0/05-concepts/10-authentication/04-providers/01-email.md
+5-8Lines changed: 5 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,10 +8,9 @@ A comprehensive tutorial covering email/password sign-in complete with sending t
8
8
You need to install the auth module before you continue, see [Setup](../setup).
9
9
:::
10
10
11
-
12
11
## Server-side Configuration
13
12
14
-
In your main `server.dart` file, import the `serverpod_auth_server` module, and set up the authentication configuration:
13
+
In your main `server.dart` file, import the `serverpod_auth_server` module, and set up the authentication configuration:
15
14
16
15
```dart
17
16
import 'package:serverpod_auth_server/module.dart' as auth;
@@ -35,7 +34,7 @@ await pod.start();
35
34
36
35
:::info
37
36
38
-
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/chat/chat_server/lib/server.dart).
37
+
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/legacy/chat/chat_server/lib/server.dart).
39
38
40
39
:::
41
40
@@ -79,7 +78,6 @@ The triggered modal will look like this:
The `serverpod_auth_email_flutter` module provides the `EmailAuthController` class, which encapsulates the functionality for email/password authentication. You can use this class and create a custom UI for user registration, login, and password management.
After the password has been reset you have to call the `signIn` method to log in. This can be achieved by either letting the user type in the details again or simply chaining the `resetPassword` method and the `singIn` method for a seamless UX.
124
122
125
-
126
123
## Password storage security
127
124
128
125
Serverpod provides some additional configurable options to provide extra layers of security for stored password hashes.
@@ -144,13 +141,13 @@ development:
144
141
emailPasswordPepper: 'your-pepper'
145
142
```
146
143
147
-
It is essential to keep the pepper secret and never expose it to the client.
144
+
It is essential to keep the pepper secret and never expose it to the client.
148
145
149
-
If the pepper is changed, all passwords in the database will need to be re-hashed with the new pepper.
146
+
If the pepper is changed, all passwords in the database will need to be re-hashed with the new pepper.
150
147
151
148
### Secure random
152
149
153
-
Serverpod uses the `dart:math` library to generate random salts for password hashing. By default, if no secure random number generator is available, a cryptographically unsecure random number is used.
150
+
Serverpod uses the `dart:math` library to generate random salts for password hashing. By default, if no secure random number generator is available, a cryptographically unsecure random number is used.
154
151
155
152
It is possible to prevent this fallback by setting the `allowUnsecureRandom` property in the `AuthConfig` to `false`. If the `allowUnsecureRandom` property is false, the server will throw an exception if a secure random number generator is unavailable.
Copy file name to clipboardExpand all lines: versioned_docs/version-2.0.0/05-concepts/10-authentication/04-providers/01-email.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ You need to install the auth module before you continue, see [Setup](../setup).
10
10
11
11
## Server-side Configuration
12
12
13
-
In your main `server.dart` file, import the `serverpod_auth_server` module, and set up the authentication configuration:
13
+
In your main `server.dart` file, import the `serverpod_auth_server` module, and set up the authentication configuration:
14
14
15
15
```dart
16
16
import 'package:serverpod_auth_server/module.dart' as auth;
@@ -34,7 +34,7 @@ await pod.start();
34
34
35
35
:::info
36
36
37
-
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/chat/chat_server/lib/server.dart).
37
+
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/legacy/chat/chat_server/lib/server.dart).
38
38
39
39
:::
40
40
@@ -141,7 +141,7 @@ development:
141
141
emailPasswordPepper: 'your-pepper'
142
142
```
143
143
144
-
It is essential to keep the pepper secret and never expose it to the client.
144
+
It is essential to keep the pepper secret and never expose it to the client.
Copy file name to clipboardExpand all lines: versioned_docs/version-2.1.0/06-concepts/11-authentication/04-providers/01-email.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ You need to install the auth module before you continue, see [Setup](../setup).
10
10
11
11
## Server-side configuration
12
12
13
-
In your main `server.dart` file, import the `serverpod_auth_server` module, and set up the authentication configuration:
13
+
In your main `server.dart` file, import the `serverpod_auth_server` module, and set up the authentication configuration:
14
14
15
15
```dart
16
16
import 'package:serverpod_auth_server/module.dart' as auth;
@@ -34,7 +34,7 @@ await pod.start();
34
34
35
35
:::info
36
36
37
-
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/chat/chat_server/lib/server.dart).
37
+
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/legacy/chat/chat_server/lib/server.dart).
38
38
39
39
:::
40
40
@@ -141,7 +141,7 @@ development:
141
141
emailPasswordPepper: 'your-pepper'
142
142
```
143
143
144
-
It is essential to keep the pepper secret and never expose it to the client.
144
+
It is essential to keep the pepper secret and never expose it to the client.
145
145
146
146
:::warning
147
147
@@ -190,4 +190,4 @@ It could be useful if you already have stored passwords that should be preserved
190
190
191
191
Using a custom hash generator will permanently disrupt compatibility with the default hash generator.
Copy file name to clipboardExpand all lines: versioned_docs/version-2.2.0/06-concepts/11-authentication/04-providers/01-email.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ You need to install the auth module before you continue, see [Setup](../setup).
10
10
11
11
## Server-side configuration
12
12
13
-
In your main `server.dart` file, import the `serverpod_auth_server` module, and set up the authentication configuration:
13
+
In your main `server.dart` file, import the `serverpod_auth_server` module, and set up the authentication configuration:
14
14
15
15
```dart
16
16
import 'package:serverpod_auth_server/module.dart' as auth;
@@ -34,7 +34,7 @@ await pod.start();
34
34
35
35
:::info
36
36
37
-
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/chat/chat_server/lib/server.dart).
37
+
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/legacy/chat/chat_server/lib/server.dart).
38
38
39
39
:::
40
40
@@ -141,7 +141,7 @@ development:
141
141
emailPasswordPepper: 'your-pepper'
142
142
```
143
143
144
-
It is essential to keep the pepper secret and never expose it to the client.
144
+
It is essential to keep the pepper secret and never expose it to the client.
145
145
146
146
:::warning
147
147
@@ -190,4 +190,4 @@ It could be useful if you already have stored passwords that should be preserved
190
190
191
191
Using a custom hash generator will permanently disrupt compatibility with the default hash generator.
Copy file name to clipboardExpand all lines: versioned_docs/version-2.3.0/06-concepts/11-authentication/04-providers/01-email.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ You need to install the auth module before you continue, see [Setup](../setup).
10
10
11
11
## Server-side configuration
12
12
13
-
In your main `server.dart` file, import the `serverpod_auth_server` module, and set up the authentication configuration:
13
+
In your main `server.dart` file, import the `serverpod_auth_server` module, and set up the authentication configuration:
14
14
15
15
```dart
16
16
import 'package:serverpod_auth_server/module.dart' as auth;
@@ -34,7 +34,7 @@ await pod.start();
34
34
35
35
:::info
36
36
37
-
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/chat/chat_server/lib/server.dart).
37
+
For debugging purposes, you can print the validation code to the console. The chat module example does just this. You can view that code [here](https://github.com/serverpod/serverpod/blob/main/examples/legacy/chat/chat_server/lib/server.dart).
38
38
39
39
:::
40
40
@@ -141,7 +141,7 @@ development:
141
141
emailPasswordPepper: 'your-pepper'
142
142
```
143
143
144
-
It is essential to keep the pepper secret and never expose it to the client.
144
+
It is essential to keep the pepper secret and never expose it to the client.
145
145
146
146
:::warning
147
147
@@ -190,4 +190,4 @@ It could be useful if you already have stored passwords that should be preserved
190
190
191
191
Using a custom hash generator will permanently disrupt compatibility with the default hash generator.
0 commit comments