Skip to content

Commit 97503ff

Browse files
authored
Merge pull request #376 from fractal-analytics-platform/login-improvements
Login improvements
2 parents 91fcb7c + d570d24 commit 97503ff

File tree

15 files changed

+103
-50
lines changed

15 files changed

+103
-50
lines changed

.env

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FRACTAL_SERVER_HOST=http://localhost:8000
2+
3+
# AUTH COOKIE
4+
AUTH_COOKIE_NAME=fastapiusersauth
5+
AUTH_COOKIE_SECURE=false
6+
# remember to set this in production
7+
AUTH_COOKIE_DOMAIN=
8+
AUTH_COOKIE_PATH=/
9+
AUTH_COOKIE_MAX_AGE=1800
10+
AUTH_COOKIE_SAME_SITE=lax
11+
AUTH_COOKIE_HTTP_ONLY=true
12+
13+
# PUBLIC VARIABLES (accessible from client side)
14+
PUBLIC_FRACTAL_ADMIN_SUPPORT_EMAIL=help@localhost
15+
PUBLIC_UPDATE_JOBS_INTERVAL=3000
16+
PUBLIC_OAUTH_CLIENT_NAME=

.env.development

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FRACTAL_SERVER_HOST=http://localhost:8000
33
# AUTH COOKIE
44
AUTH_COOKIE_NAME=fastapiusersauth
55
AUTH_COOKIE_SECURE=false
6-
AUTH_COOKIE_DOMAIN=localhost
6+
AUTH_COOKIE_DOMAIN=
77
AUTH_COOKIE_PATH=/
88
AUTH_COOKIE_MAX_AGE=86400
99
AUTH_COOKIE_SAME_SITE=lax
@@ -12,4 +12,4 @@ AUTH_COOKIE_HTTP_ONLY=true
1212
# PUBLIC VARIABLES (accessible from client side)
1313
PUBLIC_FRACTAL_ADMIN_SUPPORT_EMAIL=help@localhost
1414
PUBLIC_UPDATE_JOBS_INTERVAL=3000
15-
#PUBLIC_OAUTH_CLIENT_NAME=github
15+
PUBLIC_OAUTH_CLIENT_NAME=

.github/workflows/lint_and_build.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ jobs:
3737
FRACTAL_SERVER_HOST: http://localhost:8000
3838
AUTH_COOKIE_NAME: fastapiusersauth
3939
AUTH_COOKIE_SECURE: false
40-
AUTH_COOKIE_DOMAIN: localhost
40+
AUTH_COOKIE_DOMAIN:
4141
AUTH_COOKIE_PATH: /
4242
AUTH_COOKIE_MAX_AGE: 1800
4343
AUTH_COOKIE_SAME_SITE: lax
4444
AUTH_COOKIE_HTTP_ONLY: true
45+
PUBLIC_OAUTH_CLIENT_NAME:
4546
run: npm run build

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ node_modules
33
/build
44
/.svelte-kit
55
/package
6-
.env
7-
.env.*
6+
.env.*local
87
!.env.example
98
.idea
109
*.bak

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
*Note: Numbers like (\#123) point to closed Pull Requests on the fractal-web repository.*
22

3+
# Unreleased
4+
5+
* Made PUBLIC_OAUTH_CLIENT_NAME static (\#376).
6+
* Added help messages to user registration (\#376).
7+
* Made AUTH_COOKIE_DOMAIN optional (\#376).
8+
* Fixed hardcoded OAuth2 variable (\#376).
9+
310
# 0.7.1
411

512
* Auto-refresh of tasks table when a tasks collection completes successfully (\#364).

docs/oauth2.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,3 @@ AUTH_COOKIE_DOMAIN=127.0.0.1
3434
PUBLIC_OAUTH_CLIENT_NAME=github
3535
# [all other variables]
3636
```
37-
38-
> A typical gotcha: if there is a mismatch between the cookie domain and the
39-
> URL you are using (e.g. one points to localhost and the other one to
40-
> 127.0.0.1), then the cookie won't be set and this will fail silently,
41-
> therefore likely triggering other unexpected behaviors.

docs/quickstart.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,48 @@ FRACTAL_SERVER_HOST=http://localhost:8000
4343
# AUTH COOKIE
4444
AUTH_COOKIE_NAME=fastapiusersauth
4545
AUTH_COOKIE_SECURE=false
46-
AUTH_COOKIE_DOMAIN=localhost
46+
# remember to set this in production
47+
AUTH_COOKIE_DOMAIN=
4748
AUTH_COOKIE_PATH=/
4849
AUTH_COOKIE_MAX_AGE=1800
4950
AUTH_COOKIE_SAME_SITE=lax
5051
AUTH_COOKIE_HTTP_ONLY=true
5152

5253
# PUBLIC VARIABLES (accessible from client side)
5354
PUBLIC_FRACTAL_ADMIN_SUPPORT_EMAIL=help@localhost
55+
PUBLIC_UPDATE_JOBS_INTERVAL=3000
56+
PUBLIC_OAUTH_CLIENT_NAME=
5457
```
5558

59+
You can also add your customizations in a file named `.env.local` or `.env.development.local` to avoid writing on env files that are under version control.
5660

5761
## Web client startup
5862

59-
Run the client application via
60-
```bash
61-
npm run dev -- --open
62-
```
63-
64-
The application is now running at `http://localhost:5173`.
65-
66-
An alternative way to start fractal-web is
63+
For testing and production, start fractal-web executing
6764
```
6865
npm run build # corresponding to `vite build`, which creates a `build` folder
6966
ORIGIN=http://localhost:5173 PORT=5173 node build
7067
```
71-
note that the `node` command relies on some environment variables, and
68+
69+
The application is now running at `http://localhost:5173`.
70+
71+
Note that the `node` command relies on some environment variables, and
7272
especially on `ORIGIN`:
7373
> HTTP doesn't give SvelteKit a reliable way to know the URL that is currently
7474
> being requested. The simplest way to tell SvelteKit where the app is being
7575
> served is to set the `ORIGIN` environment variable.
7676
> (https://kit.svelte.dev/docs/adapter-node#environment-variables-origin-protocolheader-and-hostheader)
77+
78+
For development, run the client application via
79+
```bash
80+
npm run dev
81+
```
82+
83+
> A typical gotcha: if there is a mismatch between the cookie domain and the
84+
> URL you are using (e.g. one points to localhost and the other one to
85+
> 127.0.0.1), then the cookie won't be set and this will fail silently,
86+
> therefore likely triggering other unexpected behaviors.
87+
> If you leave the `AUTH_COOKIE_DOMAIN` empty, the cookie domain will be
88+
> inferred from the HTTP call. This is useful to avoid domain mismatch issues
89+
> during testing and development, but in production is suggested to set it as
90+
> the name of the domain where the fractal-web server is running.

playwright.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default defineConfig({
3838

3939
webServer: [
4040
{
41-
command: './tests/start-test-server.sh 1.4.0',
41+
command: './tests/start-test-server.sh 1.4.1a2',
4242
port: 8000,
4343
waitForPort: true,
4444
stdout: 'pipe',

src/lib/components/admin/UserEditor.svelte

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,6 @@
142142
<span class="invalid-feedback">{validationErrors['email']}</span>
143143
</div>
144144
</div>
145-
<div class="row mb-3 has-validation">
146-
<label for="username" class="col-sm-3 col-form-label text-end">
147-
<strong>Username</strong>
148-
</label>
149-
<div class="col-sm-9">
150-
<input
151-
autocomplete="off"
152-
aria-autocomplete="none"
153-
type="text"
154-
class="form-control"
155-
id="username"
156-
class:is-invalid={formSubmitted && validationErrors['username']}
157-
bind:value={user.username}
158-
/>
159-
<span class="invalid-feedback">{validationErrors['username']}</span>
160-
</div>
161-
</div>
162145
{#if user.id && user.id !== $page.data.userInfo.id}
163146
<div class="row mb-3">
164147
<div class="col-sm-9 offset-sm-3">
@@ -213,6 +196,7 @@
213196
bind:value={password}
214197
class:is-invalid={formSubmitted && validationErrors['password']}
215198
/>
199+
<span class="form-text">Create a new password for this Fractal user</span>
216200
<span class="invalid-feedback">{validationErrors['password']}</span>
217201
</div>
218202
</div>
@@ -233,7 +217,7 @@
233217
</div>
234218
<div class="row mb-3 has-validation">
235219
<label for="slurmUser" class="col-sm-3 col-form-label text-end">
236-
<strong>Slurm user</strong>
220+
<strong>SLURM user</strong>
237221
</label>
238222
<div class="col-sm-9">
239223
<input
@@ -243,9 +227,33 @@
243227
bind:value={user.slurm_user}
244228
class:is-invalid={formSubmitted && validationErrors['slurm_user']}
245229
/>
230+
<div class="form-text">
231+
The user who will be impersonated by Fractal when running SLURM jobs
232+
</div>
246233
<span class="invalid-feedback">{validationErrors['slurm_user']}</span>
247234
</div>
248235
</div>
236+
<div class="row mb-3 has-validation">
237+
<label for="username" class="col-sm-3 col-form-label text-end">
238+
<strong>Username</strong>
239+
</label>
240+
<div class="col-sm-9">
241+
<input
242+
autocomplete="off"
243+
aria-autocomplete="none"
244+
type="text"
245+
class="form-control"
246+
id="username"
247+
class:is-invalid={formSubmitted && validationErrors['username']}
248+
bind:value={user.username}
249+
/>
250+
<span class="form-text">
251+
Optional property (useful if the user creates their own tasks), not required if the SLURM
252+
user is set
253+
</span>
254+
<span class="invalid-feedback">{validationErrors['username']}</span>
255+
</div>
256+
</div>
249257
<div class="row mb-3 has-validation">
250258
<label for="cacheDir" class="col-sm-3 col-form-label text-end">
251259
<strong>Cache dir</strong>
@@ -258,6 +266,9 @@
258266
bind:value={user.cache_dir}
259267
class:is-invalid={formSubmitted && validationErrors['cache_dir']}
260268
/>
269+
<div class="form-text">
270+
Absolute path to a user-owned folder that will be used as a cache for job-related files
271+
</div>
261272
<span class="invalid-feedback">{validationErrors['cache_dir']}</span>
262273
</div>
263274
</div>

src/routes/auth/login/+page.server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const actions = {
1818
return fail(400, { invalidMessage: 'Invalid credentials', invalid: true });
1919
}
2020

21-
setCookieFromToken(cookies, authData.access_token);
21+
setCookieFromToken(request, cookies, authData.access_token);
2222
throw redirect(302, '/projects');
2323
}
2424
};

0 commit comments

Comments
 (0)