@jskit-ai/auth-web 0.2.44 → 0.2.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/fixtures/sign-in/main.js +18 -5
- package/locales/en.json +7 -0
- package/package.json +28 -4
- package/patterns/auth-surface/PATTERN.md +10 -8
- package/patterns/auth-surface/example/src/pages/auth/email-change.vue +17 -0
- package/patterns/auth-surface/example/src/views/auth/EmailChangeView.vue +12 -0
- package/src/client/composables/useDefaultEmailChangeView.js +28 -0
- package/src/client/index.js +4 -1
- package/src/client/runtime/emailChangeLink.js +36 -0
- package/src/client/views/AuthProfileWidget.vue +8 -3
- package/src/client/views/DefaultEmailChangeView.vue +53 -0
- package/src/server/AuthWebFeature.js +2 -0
- package/src/server/authRateLimits.js +3 -1
- package/src/server/routes/emailChangeRoutes.js +54 -0
- package/src/server/routes/passSignInRoutes.js +1 -1
- package/src/server/services/AuthWebService.js +3 -2
- package/test/clientSurface.test.js +11 -2
- package/test/emailChangeClient.test.js +28 -0
- package/test/emailChangeRoutes.test.js +104 -0
- package/test/passSignInRoutes.test.js +12 -8
- package/test/secondFactor.browser.test.js +13 -2
- package/test/signIn.browser.test.js +35 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- Up to medium width, the account control's name begins with the initials its avatar shows: "AN ana.ferreira" for ana.ferreira without a picture, the person's name alone with one. That round button is named by its aria-label, and WCAG 2.5.3 Label in Name asks that a control's name hold the text it shows, the words a person using speech input says to press it (axe `label-content-name-mismatch`). Its avatar is hidden from assistive technology (`aria-hidden="true"`), since the name says whose account it is; hiding it alone, as 0.2.45 did, left the finding, as axe counts every word drawn on the screen. On wider windows the control's name is the text it shows, as before.
|
|
6
|
+
- Email change over HTTP: `POST /api/email-change` (signed in, `{ email, password }`) asks for it and `POST /api/email-change/confirm` (public, `{ token }`) uses the link, each limited per address by `config.auth.rateLimits.emailChange` (5 a minute) and `emailChangeConfirm` (10 a minute). The page the link opens is `DefaultEmailChangeView` (`./client/views/DefaultEmailChangeView`, route component `auth-email-change`, the `auth.email-change` route at `/auth/email-change`, public, registered by an application's own page as the sign-in, reset and sign-out pages are): it confirms the link once, takes the token out of the address, and says the new email or why the link was refused (`jskit.auth.emailChange.*`).
|
|
7
|
+
- `POST /api/login/pass` hands `signInWithPass` the request that posted the pass, so local auth keeps the session's address and browser.
|
|
5
8
|
- Its tests name `APP_ENV`, which the auth providers now read in place of `NODE_ENV`; the setup-code field is asked for by a staging or production server.
|
|
6
9
|
- `POST /api/login/pass` reads its settings with `resolvePassSignInFromEnv` from `@jskit-ai/auth-pass/server`, a new dependency, instead of auth-core's removed `./server/passSignIn`. The route behaves as before.
|
|
7
10
|
|
package/fixtures/sign-in/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createApp, h, ref } from "vue";
|
|
1
|
+
import { createApp, defineAsyncComponent, h, ref } from "vue";
|
|
2
2
|
import { createPinia } from "pinia";
|
|
3
|
-
import { createRouter, createWebHistory, RouterView } from "vue-router";
|
|
3
|
+
import { createRouter, createWebHistory, RouterView, useRoute } from "vue-router";
|
|
4
4
|
import { QueryClient, VueQueryPlugin } from "@tanstack/vue-query";
|
|
5
5
|
import "vuetify/styles";
|
|
6
6
|
import "@jskit-ai/material-web/client/material.css";
|
|
@@ -84,7 +84,8 @@ const SecondFactorPage = {
|
|
|
84
84
|
]);
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
|
-
// An application's console: its refund route asks for a code proved
|
|
87
|
+
// An application's console, in the shell's layout as an app's screens are: its refund route asks for a code proved
|
|
88
|
+
// within five minutes, through the step-up dialog, over the page the shell makes inert while the dialog is open.
|
|
88
89
|
const ConsolePage = {
|
|
89
90
|
setup() {
|
|
90
91
|
const { open, run, verified, cancel } = useSecondFactorStepUp();
|
|
@@ -124,7 +125,7 @@ const router = createRouter({
|
|
|
124
125
|
{ path: "/", redirect: "/home" },
|
|
125
126
|
{ path: "/home", component: HomePage },
|
|
126
127
|
{ path: "/account/second-factor", component: SecondFactorPage },
|
|
127
|
-
{ path: "/console", component: ConsolePage },
|
|
128
|
+
{ path: "/console", component: ConsolePage, meta: { shell: true } },
|
|
128
129
|
{ path: "/auth/login", component: DefaultLoginView },
|
|
129
130
|
{ path: "/auth/reset-password", component: DefaultResetPasswordView },
|
|
130
131
|
{ path: "/auth/signout", component: DefaultSignOutView },
|
|
@@ -137,7 +138,19 @@ const router = createRouter({
|
|
|
137
138
|
{ path: "/auth/pattern/signout", component: PatternSignOutPage }
|
|
138
139
|
]
|
|
139
140
|
});
|
|
140
|
-
|
|
141
|
+
// A page in the shell's layout (`meta.shell`) has the layout's main; the others have a plain one. Only the console
|
|
142
|
+
// page is in the layout, so only it loads the layout: the sign-in pages load what they did before.
|
|
143
|
+
const ShellLayout = defineAsyncComponent(() => import("@jskit-ai/shell-web/client/components/ShellLayout"));
|
|
144
|
+
const app = createApp({
|
|
145
|
+
setup() {
|
|
146
|
+
const route = useRoute();
|
|
147
|
+
return () => h(components.VApp, null, {
|
|
148
|
+
default: () => route.meta.shell
|
|
149
|
+
? h(ShellLayout, { title: "Console" }, { default: () => h(RouterView) })
|
|
150
|
+
: h(components.VMain, null, { default: () => h(RouterView) })
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
});
|
|
141
154
|
const pinia = createPinia();
|
|
142
155
|
app.provide(SHELL_WEB_PLACEMENT_RUNTIME_KEY, placement);
|
|
143
156
|
app.provide(SHELL_WEB_ERROR_RUNTIME_KEY, errorRuntime);
|
package/locales/en.json
CHANGED
|
@@ -112,6 +112,13 @@
|
|
|
112
112
|
"recoveryInvalid": "Recovery link is invalid or expired.",
|
|
113
113
|
"updateFailed": "Unable to update password."
|
|
114
114
|
},
|
|
115
|
+
"emailChange": {
|
|
116
|
+
"title": "Confirm your new email",
|
|
117
|
+
"done": "Your email is now {email}.",
|
|
118
|
+
"linkMissing": "Open this page from the link in the email.",
|
|
119
|
+
"failed": "Unable to change your email.",
|
|
120
|
+
"continue": "Continue"
|
|
121
|
+
},
|
|
115
122
|
"signOut": {
|
|
116
123
|
"title": "Signing you out",
|
|
117
124
|
"pending": "Please wait while we end your session.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.46",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"./client/types": "./src/client/types.js",
|
|
17
17
|
"./client/views/DefaultLoginView": "./src/client/views/DefaultLoginView.vue",
|
|
18
18
|
"./client/views/DefaultResetPasswordView": "./src/client/views/DefaultResetPasswordView.vue",
|
|
19
|
+
"./client/views/DefaultEmailChangeView": "./src/client/views/DefaultEmailChangeView.vue",
|
|
19
20
|
"./client/views/DefaultSignOutView": "./src/client/views/DefaultSignOutView.vue",
|
|
20
21
|
"./client/views/SecondFactorDialog": "./src/client/views/SecondFactorDialog.vue",
|
|
21
22
|
"./client/views/SecondFactorPrompt": "./src/client/views/SecondFactorPrompt.vue",
|
|
@@ -32,10 +33,10 @@
|
|
|
32
33
|
"uqr": "0.1.3"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
|
-
"@jskit-ai/auth-core": "0.2.
|
|
36
|
+
"@jskit-ai/auth-core": "0.2.31",
|
|
36
37
|
"@jskit-ai/http-runtime": "0.2.27",
|
|
37
38
|
"@jskit-ai/kernel": "0.2.27",
|
|
38
|
-
"@jskit-ai/shell-web": "0.2.
|
|
39
|
+
"@jskit-ai/shell-web": "0.2.40",
|
|
39
40
|
"@tanstack/vue-query": "^5.90.5",
|
|
40
41
|
"pinia": "^4.0.3",
|
|
41
42
|
"vue": "^3.5.44",
|
|
@@ -114,6 +115,16 @@
|
|
|
114
115
|
},
|
|
115
116
|
"server": {
|
|
116
117
|
"routes": [
|
|
118
|
+
{
|
|
119
|
+
"method": "POST",
|
|
120
|
+
"path": "/api/email-change",
|
|
121
|
+
"summary": "Ask to change the signed-in account's email: a link goes to the new address"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"method": "POST",
|
|
125
|
+
"path": "/api/email-change/confirm",
|
|
126
|
+
"summary": "Confirm an email change with the link sent to the new address"
|
|
127
|
+
},
|
|
117
128
|
{
|
|
118
129
|
"method": "POST",
|
|
119
130
|
"path": "/api/login",
|
|
@@ -247,6 +258,19 @@
|
|
|
247
258
|
},
|
|
248
259
|
"purpose": "Public password reset screen for recovery links."
|
|
249
260
|
},
|
|
261
|
+
{
|
|
262
|
+
"id": "auth.email-change",
|
|
263
|
+
"path": "/auth/email-change",
|
|
264
|
+
"scope": "surface",
|
|
265
|
+
"surface": "auth",
|
|
266
|
+
"name": "auth-email-change",
|
|
267
|
+
"componentKey": "auth-email-change",
|
|
268
|
+
"autoRegister": false,
|
|
269
|
+
"guard": {
|
|
270
|
+
"policy": "public"
|
|
271
|
+
},
|
|
272
|
+
"purpose": "Public screen that confirms an email change from the link sent to the new address."
|
|
273
|
+
},
|
|
250
274
|
{
|
|
251
275
|
"id": "auth.default-login",
|
|
252
276
|
"path": "/auth/default-login",
|
|
@@ -347,6 +371,6 @@
|
|
|
347
371
|
}
|
|
348
372
|
},
|
|
349
373
|
"devDependencies": {
|
|
350
|
-
"@jskit-ai/material-web": "0.1.
|
|
374
|
+
"@jskit-ai/material-web": "0.1.9"
|
|
351
375
|
}
|
|
352
376
|
}
|
|
@@ -27,8 +27,8 @@ Those choices must be known before adapting the example.
|
|
|
27
27
|
## Framework APIs
|
|
28
28
|
|
|
29
29
|
Use the views, auth guard, HTTP client integration, sign-out runtime, providers,
|
|
30
|
-
and Playwright auth helper exported by `@jskit-ai/auth-web`. The sign-in, reset
|
|
31
|
-
and sign-out screens show the app's identity: the pages render the app's view
|
|
30
|
+
and Playwright auth helper exported by `@jskit-ai/auth-web`. The sign-in, reset,
|
|
31
|
+
email change and sign-out screens show the app's identity: the pages render the app's view
|
|
32
32
|
wrappers (`src/views/auth/`), and each wrapper fills the default view's `brand`
|
|
33
33
|
slot (given `{ compact }`) with `src/components/AppBrand.vue`, the app's name
|
|
34
34
|
as `index.html`'s `<title>` spells it. JSKIT lays the slot out as a pane beside
|
|
@@ -107,9 +107,10 @@ a user as a side effect.
|
|
|
107
107
|
exercised.
|
|
108
108
|
- Public auth routes do not require an existing session.
|
|
109
109
|
- Protected routes use the framework auth policy rather than page-local checks.
|
|
110
|
-
- Login, sign-out, and
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
- Login, sign-out, reset and email change views use the public auth
|
|
111
|
+
components/composables.
|
|
112
|
+
- The sign-in, reset, email change and sign-out pages render the app's view
|
|
113
|
+
wrappers, which fill the `brand` slot with the app's identity (`AppBrand.vue`): a person
|
|
113
114
|
always sees which app they are signing in to. Renaming the app renames
|
|
114
115
|
`AppBrand.vue` with `index.html`'s `<title>`; the brand adds no heading.
|
|
115
116
|
- A custom login view must preserve the default view's initial session check:
|
|
@@ -152,9 +153,10 @@ placements, and post-auth destinations while retaining the runtime contracts.
|
|
|
152
153
|
|
|
153
154
|
## Verification
|
|
154
155
|
|
|
155
|
-
Check that the sign-in, reset and sign-out screens show the
|
|
156
|
-
pane on a wide window and in the row on a phone. Exercise
|
|
157
|
-
login, sign-out, reset,
|
|
156
|
+
Check that the sign-in, reset, email change and sign-out screens show the
|
|
157
|
+
app's name, in the pane on a wide window and in the row on a phone. Exercise
|
|
158
|
+
failed and successful login, sign-out, reset, an email change link, protected
|
|
159
|
+
navigation,
|
|
158
160
|
keyboard interaction, warm-cache return navigation, and browser refresh.
|
|
159
161
|
Open the login route with an existing authenticated session and confirm it
|
|
160
162
|
returns to the requested screen; repeat signed out and confirm the form remains.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<route lang="json">
|
|
2
|
+
{
|
|
3
|
+
"meta": {
|
|
4
|
+
"guard": {
|
|
5
|
+
"policy": "public"
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
</route>
|
|
10
|
+
|
|
11
|
+
<script setup>
|
|
12
|
+
import EmailChangeView from "@/views/auth/EmailChangeView.vue";
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<EmailChangeView />
|
|
17
|
+
</template>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import DefaultEmailChangeView from "@jskit-ai/auth-web/client/views/DefaultEmailChangeView";
|
|
3
|
+
import AppBrand from "@/components/AppBrand.vue";
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<template>
|
|
7
|
+
<DefaultEmailChangeView>
|
|
8
|
+
<template #brand="{ compact }">
|
|
9
|
+
<AppBrand :compact="compact" />
|
|
10
|
+
</template>
|
|
11
|
+
</DefaultEmailChangeView>
|
|
12
|
+
</template>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { onMounted, ref } from "vue";
|
|
2
|
+
import { confirmEmailChangeLink } from "../runtime/emailChangeLink.js";
|
|
3
|
+
import { useJskitText } from "../i18n.js";
|
|
4
|
+
|
|
5
|
+
/** The email change page: it confirms the link it was opened with once, then says what happened. */
|
|
6
|
+
export function useDefaultEmailChangeView() {
|
|
7
|
+
const { serverMessage, t } = useJskitText();
|
|
8
|
+
const status = ref("checking");
|
|
9
|
+
const message = ref("");
|
|
10
|
+
|
|
11
|
+
async function confirmLink() {
|
|
12
|
+
const result = await confirmEmailChangeLink(window.location.href);
|
|
13
|
+
// The link works once: it leaves the address bar and the history.
|
|
14
|
+
window.history.replaceState(window.history.state, "", window.location.pathname);
|
|
15
|
+
status.value = result.status === "done" ? "done" : "error";
|
|
16
|
+
if (result.status === "done") {
|
|
17
|
+
message.value = t("jskit.auth.emailChange.done", { email: result.email });
|
|
18
|
+
} else if (result.status === "missing") {
|
|
19
|
+
message.value = t("jskit.auth.emailChange.linkMissing");
|
|
20
|
+
} else {
|
|
21
|
+
message.value = serverMessage(result.error, t("jskit.auth.emailChange.failed"));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
onMounted(confirmLink);
|
|
26
|
+
|
|
27
|
+
return { status, message };
|
|
28
|
+
}
|
package/src/client/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import DefaultLoginView from "./views/DefaultLoginView.vue";
|
|
2
2
|
import DefaultSignOutView from "./views/DefaultSignOutView.vue";
|
|
3
3
|
import DefaultResetPasswordView from "./views/DefaultResetPasswordView.vue";
|
|
4
|
+
import DefaultEmailChangeView from "./views/DefaultEmailChangeView.vue";
|
|
4
5
|
|
|
5
6
|
export { AuthWebClientProvider } from "./providers/AuthWebClientProvider.js";
|
|
6
7
|
export { default as DefaultLoginView } from "./views/DefaultLoginView.vue";
|
|
7
8
|
export { default as DefaultSignOutView } from "./views/DefaultSignOutView.vue";
|
|
8
9
|
export { default as DefaultResetPasswordView } from "./views/DefaultResetPasswordView.vue";
|
|
10
|
+
export { default as DefaultEmailChangeView } from "./views/DefaultEmailChangeView.vue";
|
|
9
11
|
export { default as AuthProfileWidget } from "./views/AuthProfileWidget.vue";
|
|
10
12
|
export { default as AuthProfileMenuLinkItem } from "./views/AuthProfileMenuLinkItem.vue";
|
|
11
13
|
export { useSecondFactorStepUp } from "./composables/secondFactor/useSecondFactorStepUp.js";
|
|
@@ -25,7 +27,8 @@ const routeComponents = Object.freeze({
|
|
|
25
27
|
"auth-login": DefaultLoginView,
|
|
26
28
|
"auth-signout": DefaultSignOutView,
|
|
27
29
|
"auth-default-login": DefaultLoginView,
|
|
28
|
-
"auth-reset-password": DefaultResetPasswordView
|
|
30
|
+
"auth-reset-password": DefaultResetPasswordView,
|
|
31
|
+
"auth-email-change": DefaultEmailChangeView
|
|
29
32
|
});
|
|
30
33
|
|
|
31
34
|
export { routeComponents };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AUTH_PATHS } from "@jskit-ai/auth-core/shared/authPaths";
|
|
2
|
+
import { authHttpRequest } from "./authHttpClient.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The token of an email change link from a page's address: "" when it has none.
|
|
6
|
+
* @param {string} href
|
|
7
|
+
*/
|
|
8
|
+
function readEmailChangeToken(href) {
|
|
9
|
+
try {
|
|
10
|
+
return new URL(href).searchParams.get("token") || "";
|
|
11
|
+
} catch {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Confirms the email change a page's link names: `done` with the account's new email, `error` with the refusal, or
|
|
18
|
+
* `missing` when the address has no link, without asking the server.
|
|
19
|
+
* @param {string} href The page's address.
|
|
20
|
+
* @param {typeof authHttpRequest} [request]
|
|
21
|
+
* @returns {Promise<{ status: "done" | "error" | "missing", email: string, error: unknown }>}
|
|
22
|
+
*/
|
|
23
|
+
async function confirmEmailChangeLink(href, request = authHttpRequest) {
|
|
24
|
+
const token = readEmailChangeToken(href);
|
|
25
|
+
if (!token) {
|
|
26
|
+
return { status: "missing", email: "", error: null };
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const answer = await request(AUTH_PATHS.EMAIL_CHANGE_CONFIRM, { method: "POST", body: { token } });
|
|
30
|
+
return { status: "done", email: String(answer?.email || ""), error: null };
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return { status: "error", email: "", error };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { confirmEmailChangeLink, readEmailChangeToken };
|
|
@@ -11,7 +11,10 @@ const { t } = useJskitText();
|
|
|
11
11
|
const { context: shellPlacementContext } = useWebPlacementContext();
|
|
12
12
|
// On expanded windows the activator is a pill with the name beside the avatar, the name ending in an ellipsis past
|
|
13
13
|
// 12rem; on medium and compact windows, where the app bar's title and actions need the room, it is a round icon
|
|
14
|
-
// button around the avatar, named by its aria-label.
|
|
14
|
+
// button around the avatar, named by its aria-label. A control's name holds the text it shows (WCAG 2.5.3 Label in
|
|
15
|
+
// Name), the words a person using speech input says to press it, and every word drawn on the screen counts, hidden
|
|
16
|
+
// from assistive technology or not; so without a picture that name begins with the initials the avatar shows,
|
|
17
|
+
// "AN ana.ferreira". The avatar itself stays hidden from assistive technology: the name says whose account it is.
|
|
15
18
|
const { isExpanded, isLarge } = useShellWindowSizeClass();
|
|
16
19
|
const showsName = computed(() => isExpanded.value || isLarge.value);
|
|
17
20
|
|
|
@@ -60,6 +63,8 @@ const initials = computed(() => {
|
|
|
60
63
|
return text.slice(0, 2).toUpperCase();
|
|
61
64
|
});
|
|
62
65
|
|
|
66
|
+
const compactName = computed(() => (avatarUrl.value ? displayName.value : `${initials.value} ${displayName.value}`));
|
|
67
|
+
|
|
63
68
|
const placementContext = computed(() => {
|
|
64
69
|
return {
|
|
65
70
|
auth: auth.authState,
|
|
@@ -83,8 +88,8 @@ const placementContext = computed(() => {
|
|
|
83
88
|
</v-avatar>
|
|
84
89
|
<span class="auth-profile-widget__name ml-2 text-body-medium">{{ displayName }}</span>
|
|
85
90
|
</v-btn>
|
|
86
|
-
<v-btn v-else v-bind="props" icon variant="text" class="auth-profile-widget__activator" :aria-label="
|
|
87
|
-
<v-avatar size="32" color="primary" variant="tonal">
|
|
91
|
+
<v-btn v-else v-bind="props" icon variant="text" class="auth-profile-widget__activator" :aria-label="compactName">
|
|
92
|
+
<v-avatar size="32" color="primary" variant="tonal" aria-hidden="true">
|
|
88
93
|
<v-img v-if="avatarUrl" :src="avatarUrl" cover />
|
|
89
94
|
<span v-else class="text-body-small font-weight-medium">{{ initials }}</span>
|
|
90
95
|
</v-avatar>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<AuthScreen class="email-change-screen">
|
|
3
|
+
<template v-if="$slots.brand" #brand="brand">
|
|
4
|
+
<slot name="brand" v-bind="brand" />
|
|
5
|
+
</template>
|
|
6
|
+
<v-card
|
|
7
|
+
class="email-change-card"
|
|
8
|
+
:class="{ 'email-change-card--mobile': isMobileViewport }"
|
|
9
|
+
variant="flat"
|
|
10
|
+
:rounded="isMobileViewport ? false : undefined"
|
|
11
|
+
>
|
|
12
|
+
<v-card-text class="email-change-content">
|
|
13
|
+
<h1 class="text-headline-medium mb-5">{{ t("jskit.auth.emailChange.title") }}</h1>
|
|
14
|
+
<v-progress-linear v-if="status === 'checking'" indeterminate color="primary" />
|
|
15
|
+
<v-alert v-else :type="status === 'done' ? 'success' : 'error'" variant="tonal">
|
|
16
|
+
{{ message }}
|
|
17
|
+
</v-alert>
|
|
18
|
+
<div v-if="status !== 'checking'" class="mt-4 d-flex justify-end">
|
|
19
|
+
<v-btn variant="text" color="secondary" href="/">
|
|
20
|
+
{{ t("jskit.auth.emailChange.continue") }}
|
|
21
|
+
</v-btn>
|
|
22
|
+
</div>
|
|
23
|
+
</v-card-text>
|
|
24
|
+
</v-card>
|
|
25
|
+
</AuthScreen>
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
<script setup>
|
|
29
|
+
import { useDisplay } from "vuetify";
|
|
30
|
+
import AuthScreen from "./AuthScreen.vue";
|
|
31
|
+
import { useDefaultEmailChangeView } from "../composables/useDefaultEmailChangeView.js";
|
|
32
|
+
import { useJskitText } from "../i18n.js";
|
|
33
|
+
|
|
34
|
+
const { mobile: isMobileViewport } = useDisplay({ mobileBreakpoint: 960 });
|
|
35
|
+
const { t } = useJskitText();
|
|
36
|
+
const { status, message } = useDefaultEmailChangeView();
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<style scoped>
|
|
40
|
+
.email-change-card {
|
|
41
|
+
width: min(480px, 100%);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* On a phone the card is the screen below the brand row, if any. */
|
|
45
|
+
.email-change-card--mobile {
|
|
46
|
+
flex: 1 0 auto;
|
|
47
|
+
width: 100%;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.email-change-content {
|
|
51
|
+
padding: 28px;
|
|
52
|
+
}
|
|
53
|
+
</style>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineFeature } from "@jskit-ai/kernel/server/features";
|
|
2
2
|
import { createAuthWeb } from "./authWeb.js";
|
|
3
|
+
import { registerEmailChangeRoutes } from "./routes/emailChangeRoutes.js";
|
|
3
4
|
import { registerPassSignInRoutes } from "./routes/passSignInRoutes.js";
|
|
4
5
|
import { registerSecondFactorRoutes } from "./routes/secondFactorRoutes.js";
|
|
5
6
|
|
|
@@ -29,6 +30,7 @@ const AuthWebFeature = defineFeature({
|
|
|
29
30
|
http.router.register(route.method, route.path, route, route.handler);
|
|
30
31
|
}
|
|
31
32
|
registerSecondFactorRoutes(http.router, { rateLimits: authWeb.rateLimits });
|
|
33
|
+
registerEmailChangeRoutes(http.router, { rateLimits: authWeb.rateLimits });
|
|
32
34
|
return { authWeb };
|
|
33
35
|
},
|
|
34
36
|
/**
|
|
@@ -23,7 +23,9 @@ const DEFAULT_AUTH_RATE_LIMITS = Object.freeze({
|
|
|
23
23
|
secondFactorSetupConfirm: Object.freeze({ max: 10, timeWindow: "1 minute" }),
|
|
24
24
|
secondFactorVerify: Object.freeze({ max: 10, timeWindow: "1 minute" }),
|
|
25
25
|
secondFactorRecoveryCodes: Object.freeze({ max: 5, timeWindow: "1 minute" }),
|
|
26
|
-
secondFactorRemove: Object.freeze({ max: 5, timeWindow: "1 minute" })
|
|
26
|
+
secondFactorRemove: Object.freeze({ max: 5, timeWindow: "1 minute" }),
|
|
27
|
+
emailChange: Object.freeze({ max: 5, timeWindow: "1 minute" }),
|
|
28
|
+
emailChangeConfirm: Object.freeze({ max: 10, timeWindow: "1 minute" })
|
|
27
29
|
});
|
|
28
30
|
|
|
29
31
|
/**
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ACTION_CONFIRM_EMAIL_CHANGE,
|
|
3
|
+
ACTION_REQUEST_EMAIL_CHANGE
|
|
4
|
+
} from "@jskit-ai/auth-core/server/actions/emailChangeActions";
|
|
5
|
+
import { AUTH_PATHS } from "@jskit-ai/auth-core/shared/authPaths";
|
|
6
|
+
import { authEmailChangeConfirmCommand, authEmailChangeRequestCommand } from "@jskit-ai/auth-core/shared/commands";
|
|
7
|
+
import { withStandardErrorResponses } from "@jskit-ai/http-runtime/shared/validators/errorResponses";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An account's email change: the signed-in person asks for a new address with their password, and the link sent to
|
|
11
|
+
* it confirms the change, from a browser signed in or not. Each route runs its auth.emailChange action, limited per
|
|
12
|
+
* client address by its entry in `rateLimits` (none when that entry is null).
|
|
13
|
+
* @param {import("@jskit-ai/kernel/server/types").RuntimeRouter} router
|
|
14
|
+
* @param {{ rateLimits: import("../types.js").AuthRateLimits }} dependencies
|
|
15
|
+
*/
|
|
16
|
+
function registerEmailChangeRoutes(router, { rateLimits }) {
|
|
17
|
+
router.register(
|
|
18
|
+
"POST",
|
|
19
|
+
AUTH_PATHS.EMAIL_CHANGE,
|
|
20
|
+
{
|
|
21
|
+
auth: "required",
|
|
22
|
+
meta: { tags: ["auth"], summary: "Ask to change the signed-in account's email: a link goes to the new address" },
|
|
23
|
+
body: authEmailChangeRequestCommand.operation.body,
|
|
24
|
+
responses: withStandardErrorResponses(
|
|
25
|
+
{ 200: authEmailChangeRequestCommand.operation.response },
|
|
26
|
+
{ includeValidation400: true }
|
|
27
|
+
),
|
|
28
|
+
rateLimit: rateLimits.emailChange
|
|
29
|
+
},
|
|
30
|
+
async function (request, reply) {
|
|
31
|
+
reply.code(200).send(await request.executeAction({ actionId: ACTION_REQUEST_EMAIL_CHANGE, input: request.input.body }));
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
router.register(
|
|
36
|
+
"POST",
|
|
37
|
+
AUTH_PATHS.EMAIL_CHANGE_CONFIRM,
|
|
38
|
+
{
|
|
39
|
+
auth: "public",
|
|
40
|
+
meta: { tags: ["auth"], summary: "Confirm an email change with the link sent to the new address" },
|
|
41
|
+
body: authEmailChangeConfirmCommand.operation.body,
|
|
42
|
+
responses: withStandardErrorResponses(
|
|
43
|
+
{ 200: authEmailChangeConfirmCommand.operation.response },
|
|
44
|
+
{ includeValidation400: true }
|
|
45
|
+
),
|
|
46
|
+
rateLimit: rateLimits.emailChangeConfirm
|
|
47
|
+
},
|
|
48
|
+
async function (request, reply) {
|
|
49
|
+
reply.code(200).send(await request.executeAction({ actionId: ACTION_CONFIRM_EMAIL_CHANGE, input: request.input.body }));
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { registerEmailChangeRoutes };
|
|
@@ -34,7 +34,7 @@ async function registerPassSignInRoutes(fastify, { service, rateLimit }) {
|
|
|
34
34
|
const form = /** @type {{ pass?: unknown } | undefined} */ (request.body);
|
|
35
35
|
let result;
|
|
36
36
|
try {
|
|
37
|
-
result = await service.signInWithPass({ pass: String(form?.pass ?? "") });
|
|
37
|
+
result = await service.signInWithPass({ pass: String(form?.pass ?? "") }, request);
|
|
38
38
|
} catch (error) {
|
|
39
39
|
if (!(error instanceof AppError) || error.statusCode >= 500) {
|
|
40
40
|
throw error;
|
|
@@ -124,14 +124,15 @@ class AuthWebService {
|
|
|
124
124
|
/**
|
|
125
125
|
* Signs in the account a one-time signed pass names; a provider without pass sign-in refuses it as unsupported.
|
|
126
126
|
* @param {{ pass: string }} input
|
|
127
|
+
* @param {object} request The request that posted the pass.
|
|
127
128
|
*/
|
|
128
|
-
async signInWithPass(input) {
|
|
129
|
+
async signInWithPass(input, request) {
|
|
129
130
|
const { authService } = this;
|
|
130
131
|
// readable-check: allow method-probe - optional operation: signInWithPass is an optional auth.service operation
|
|
131
132
|
if (typeof authService.signInWithPass !== "function") {
|
|
132
133
|
return throwUnsupportedAuthOperation("signInWithPass");
|
|
133
134
|
}
|
|
134
|
-
return authService.signInWithPass(input);
|
|
135
|
+
return authService.signInWithPass(input, request);
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
writeSessionCookies(reply, session) {
|
|
@@ -78,7 +78,7 @@ test("auth profile activator keeps Material 3's 48dp touch target without a fixe
|
|
|
78
78
|
// Without the name, up to medium width, the activator is an icon button, so its state layer is a circle round the
|
|
79
79
|
// avatar; the name shows on expanded windows only, through the shell's window size classes.
|
|
80
80
|
assert.match(widgetSource, /const showsName = computed\(\(\) => isExpanded\.value \|\| isLarge\.value\);/u);
|
|
81
|
-
assert.match(widgetSource, /<v-btn v-else v-bind="props" icon variant="text" class="auth-profile-widget__activator" :aria-label="
|
|
81
|
+
assert.match(widgetSource, /<v-btn v-else v-bind="props" icon variant="text" class="auth-profile-widget__activator" :aria-label="compactName">/u);
|
|
82
82
|
// material-web gives every default-size button a 48dp touch target around its 40dp body; a fixed height would
|
|
83
83
|
// make the button itself taller than Material 3 draws it.
|
|
84
84
|
assert.doesNotMatch(widgetSource, /min-height/u);
|
|
@@ -93,7 +93,12 @@ test("the auth views fill the viewport through AuthScreen: a card on wide window
|
|
|
93
93
|
// The full-viewport screen starts below shell banners shown on this bar-less surface.
|
|
94
94
|
assert.match(screen, /\.auth-screen\s*\{[\s\S]*inset:\s*var\(--shell-error-banners-inline-height, 0px\) 0 0;/);
|
|
95
95
|
assert.doesNotMatch(screen, /min-height:\s*100dvh/);
|
|
96
|
-
for (const [name, card] of [
|
|
96
|
+
for (const [name, card] of [
|
|
97
|
+
["DefaultLoginView", "auth-card"],
|
|
98
|
+
["DefaultResetPasswordView", "reset-card"],
|
|
99
|
+
["DefaultSignOutView", "signout-card"],
|
|
100
|
+
["DefaultEmailChangeView", "email-change-card"]
|
|
101
|
+
]) {
|
|
97
102
|
const view = read(name);
|
|
98
103
|
assert.match(view, /<AuthScreen\b/, name);
|
|
99
104
|
// The app's brand slot reaches the screen's pane and row.
|
|
@@ -164,6 +169,10 @@ test("auth-web package exports only minimal client runtime/view subpaths", () =>
|
|
|
164
169
|
exportsMap["./client/views/DefaultSignOutView"],
|
|
165
170
|
"./src/client/views/DefaultSignOutView.vue"
|
|
166
171
|
);
|
|
172
|
+
assert.equal(
|
|
173
|
+
exportsMap["./client/views/DefaultEmailChangeView"],
|
|
174
|
+
"./src/client/views/DefaultEmailChangeView.vue"
|
|
175
|
+
);
|
|
167
176
|
assert.equal(
|
|
168
177
|
exportsMap["./client/runtime/authGuardRuntime"],
|
|
169
178
|
"./src/client/runtime/authGuardRuntime.js"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { confirmEmailChangeLink } from "../src/client/runtime/emailChangeLink.js";
|
|
4
|
+
|
|
5
|
+
test("an email change page confirms the link it was opened with, once; a page without one asks nothing", async () => {
|
|
6
|
+
const calls = [];
|
|
7
|
+
const request = async (url, options) => {
|
|
8
|
+
calls.push([url, options]);
|
|
9
|
+
return { ok: true, email: "new@example.com" };
|
|
10
|
+
};
|
|
11
|
+
assert.deepEqual(await confirmEmailChangeLink("https://app.example/auth/email-change?token=link-token", request),
|
|
12
|
+
{ status: "done", email: "new@example.com", error: null });
|
|
13
|
+
assert.deepEqual(calls, [["/api/email-change/confirm", { method: "POST", body: { token: "link-token" } }]]);
|
|
14
|
+
|
|
15
|
+
assert.deepEqual(await confirmEmailChangeLink("https://app.example/auth/email-change", request),
|
|
16
|
+
{ status: "missing", email: "", error: null });
|
|
17
|
+
assert.deepEqual(await confirmEmailChangeLink("not an address", request), { status: "missing", email: "", error: null });
|
|
18
|
+
assert.equal(calls.length, 1);
|
|
19
|
+
|
|
20
|
+
const refused = Object.assign(new Error("This email change link is invalid, used or expired. Ask for the change again."), {
|
|
21
|
+
status: 400,
|
|
22
|
+
code: "auth.local.emailChange.linkInvalid"
|
|
23
|
+
});
|
|
24
|
+
const failed = await confirmEmailChangeLink("https://app.example/auth/email-change?token=used", async () => {
|
|
25
|
+
throw refused;
|
|
26
|
+
});
|
|
27
|
+
assert.deepEqual(failed, { status: "error", email: "", error: refused });
|
|
28
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
import Fastify from "fastify";
|
|
7
|
+
import { AuthExtensionsProvider } from "@jskit-ai/auth-core/server/providers/AuthExtensionsProvider";
|
|
8
|
+
import { AuthFeature } from "@jskit-ai/auth-core/server/providers/AuthFeature";
|
|
9
|
+
import { AuthPolicyProvider } from "@jskit-ai/auth-core/server/providers/AuthPolicyProvider";
|
|
10
|
+
import { ActionProvider } from "@jskit-ai/kernel/server/actions";
|
|
11
|
+
import { HttpProvider } from "@jskit-ai/kernel/server/http";
|
|
12
|
+
import { EventProvider } from "@jskit-ai/kernel/server/runtime";
|
|
13
|
+
import { silentLogger } from "@jskit-ai/kernel/server/runtime/logger";
|
|
14
|
+
import { createCapabilityRuntime } from "@jskit-ai/kernel/shared/capabilities";
|
|
15
|
+
import { createLocalFileBackend } from "../../auth-provider-local-core/src/server/lib/index.js";
|
|
16
|
+
import { emailChangeService } from "../../auth-provider-local-core/test-support/emailChangeScenario.js";
|
|
17
|
+
import { sessionCookies } from "../../auth-provider-local-core/test-support/oauthHarness.js";
|
|
18
|
+
import { AuthWebFeature } from "../src/server/AuthWebFeature.js";
|
|
19
|
+
import { DEFAULT_AUTH_RATE_LIMITS } from "../src/server/authRateLimits.js";
|
|
20
|
+
|
|
21
|
+
const PASSWORD = "correct horse battery staple";
|
|
22
|
+
|
|
23
|
+
/** The auth routes over local auth in a store of the test's own, whose email-change sender keeps what it sends. */
|
|
24
|
+
async function startApp(t, config = {}) {
|
|
25
|
+
const storeDir = await fs.mkdtemp(path.join(os.tmpdir(), "jskit-auth-web-email-change-"));
|
|
26
|
+
t.after(() => fs.rm(storeDir, { recursive: true, force: true }));
|
|
27
|
+
const { service, takeSent } = emailChangeService(createLocalFileBackend({ storeDir }));
|
|
28
|
+
const app = Fastify();
|
|
29
|
+
const runtime = createCapabilityRuntime({
|
|
30
|
+
inputs: {
|
|
31
|
+
"auth.service": service,
|
|
32
|
+
"runtime.config": config,
|
|
33
|
+
"runtime.env": { APP_ENV: "test" },
|
|
34
|
+
"runtime.fastify": app,
|
|
35
|
+
"runtime.logger": silentLogger
|
|
36
|
+
},
|
|
37
|
+
providers: [EventProvider, ActionProvider, HttpProvider, AuthExtensionsProvider, AuthFeature, AuthPolicyProvider, AuthWebFeature]
|
|
38
|
+
});
|
|
39
|
+
await runtime.start();
|
|
40
|
+
t.after(async () => {
|
|
41
|
+
await runtime.shutdown();
|
|
42
|
+
await app.close();
|
|
43
|
+
});
|
|
44
|
+
return { app, service, takeSent };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A browser: its cookies and CSRF token, signed in as the email when one is given. */
|
|
48
|
+
async function browser(app, service, email = "") {
|
|
49
|
+
const cookies = email
|
|
50
|
+
? sessionCookies((await service.register({ email, password: PASSWORD })).session)
|
|
51
|
+
: {};
|
|
52
|
+
const session = await app.inject({ method: "GET", url: "/api/session", cookies });
|
|
53
|
+
for (const cookie of session.cookies) {
|
|
54
|
+
cookies[cookie.name] = cookie.value;
|
|
55
|
+
}
|
|
56
|
+
const csrfToken = session.json().csrfToken;
|
|
57
|
+
return (url, payload) => app.inject({ method: "POST", url, cookies, headers: { "csrf-token": csrfToken }, payload });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
test("the signed-in person asks to change their email, and the link's page confirms it signed in or not", async (t) => {
|
|
61
|
+
const { app, service, takeSent } = await startApp(t);
|
|
62
|
+
const ada = await browser(app, service, "ada@example.com");
|
|
63
|
+
const stranger = await browser(app, service);
|
|
64
|
+
|
|
65
|
+
const refused = async (response, status, code) => {
|
|
66
|
+
assert.equal(response.statusCode, status, response.body);
|
|
67
|
+
assert.equal(response.json().code, code);
|
|
68
|
+
};
|
|
69
|
+
await refused(await stranger("/api/email-change", { email: "new@example.com", password: PASSWORD }), 401, "auth.session.required");
|
|
70
|
+
await refused(await ada("/api/email-change", { email: "new@example.com", password: "a wrong password" }), 400,
|
|
71
|
+
"auth.local.emailChange.passwordInvalid");
|
|
72
|
+
await refused(await ada("/api/email-change", { email: "new@example.com" }), 400, "validation_failed");
|
|
73
|
+
assert.deepEqual(await takeSent(), []);
|
|
74
|
+
|
|
75
|
+
const asked = await ada("/api/email-change", { email: "new@example.com", password: PASSWORD });
|
|
76
|
+
assert.equal(asked.statusCode, 200, asked.body);
|
|
77
|
+
assert.deepEqual(asked.json(), { ok: true, email: "new@example.com" });
|
|
78
|
+
const [link] = await takeSent();
|
|
79
|
+
const token = new URL(link.confirmationUrl).searchParams.get("token");
|
|
80
|
+
|
|
81
|
+
await refused(await stranger("/api/email-change/confirm", {}), 400, "validation_failed");
|
|
82
|
+
const confirmed = await stranger("/api/email-change/confirm", { token });
|
|
83
|
+
assert.equal(confirmed.statusCode, 200, confirmed.body);
|
|
84
|
+
assert.deepEqual(confirmed.json(), { ok: true, email: "new@example.com" });
|
|
85
|
+
await refused(await stranger("/api/email-change/confirm", { token }), 400, "auth.local.emailChange.linkInvalid");
|
|
86
|
+
assert.equal((await service.login({ email: "new@example.com", password: PASSWORD })).actor.email, "new@example.com");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("asking for an email change, and confirming one, are each limited per address", async (t) => {
|
|
90
|
+
assert.deepEqual([DEFAULT_AUTH_RATE_LIMITS.emailChange, DEFAULT_AUTH_RATE_LIMITS.emailChangeConfirm],
|
|
91
|
+
[{ max: 5, timeWindow: "1 minute" }, { max: 10, timeWindow: "1 minute" }]);
|
|
92
|
+
const { app, service } = await startApp(t, {
|
|
93
|
+
auth: { rateLimits: { emailChange: { max: 2 }, emailChangeConfirm: { max: 2 } } }
|
|
94
|
+
});
|
|
95
|
+
const ada = await browser(app, service, "ada@example.com");
|
|
96
|
+
const asked = [];
|
|
97
|
+
const confirmed = [];
|
|
98
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
99
|
+
asked.push((await ada("/api/email-change", { email: "new@example.com", password: "a wrong password" })).statusCode);
|
|
100
|
+
confirmed.push((await ada("/api/email-change/confirm", { token: "not-a-link" })).statusCode);
|
|
101
|
+
}
|
|
102
|
+
assert.deepEqual(asked, [400, 400, 429]);
|
|
103
|
+
assert.deepEqual(confirmed, [400, 400, 429]);
|
|
104
|
+
});
|
|
@@ -13,6 +13,7 @@ import { EventProvider } from "@jskit-ai/kernel/server/runtime";
|
|
|
13
13
|
import { silentLogger } from "@jskit-ai/kernel/server/runtime/logger";
|
|
14
14
|
import { createCapabilityRuntime } from "@jskit-ai/kernel/shared/capabilities";
|
|
15
15
|
import { createLocalAuthService, createLocalFileBackend } from "../../auth-provider-local-core/src/server/lib/index.js";
|
|
16
|
+
import { sha256Base64url } from "../../auth-provider-local-core/src/server/lib/tokens.js";
|
|
16
17
|
import { localServiceOptions } from "../../auth-provider-local-core/test-support/localService.js";
|
|
17
18
|
import { createPassIssuer, passIdentityByEmail, passwordlessAccount } from "../../auth-provider-local-core/test-support/passSignInScenario.js";
|
|
18
19
|
import { AuthWebFeature } from "../src/server/AuthWebFeature.js";
|
|
@@ -20,7 +21,7 @@ import { DEFAULT_AUTH_RATE_LIMITS } from "../src/server/authRateLimits.js";
|
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* The auth routes and policy over local auth in a store of the test's own, trusting the issuer's passes when `env`
|
|
23
|
-
* carries its key.
|
|
24
|
+
* carries its key, and the store it keeps.
|
|
24
25
|
* @param {import("node:test").TestContext} t
|
|
25
26
|
* @param {{ env?: Record<string, string>, config?: object }} [options]
|
|
26
27
|
*/
|
|
@@ -44,7 +45,7 @@ async function startApp(t, { env = {}, config = {} } = {}) {
|
|
|
44
45
|
t.after(() => app.close());
|
|
45
46
|
await runtime.start();
|
|
46
47
|
t.after(() => runtime.shutdown());
|
|
47
|
-
return app;
|
|
48
|
+
return { app, backend };
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
/** The browser's form post of a pass, from the issuer's page, with no CSRF token and no cookies. */
|
|
@@ -53,7 +54,7 @@ function postPass(app, pass, remoteAddress = "203.0.113.7") {
|
|
|
53
54
|
method: "POST",
|
|
54
55
|
url: "/api/login/pass",
|
|
55
56
|
remoteAddress,
|
|
56
|
-
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
57
|
+
headers: { "content-type": "application/x-www-form-urlencoded", "user-agent": "Issuer Page Browser/1.0" },
|
|
57
58
|
payload: new URLSearchParams({ pass }).toString()
|
|
58
59
|
});
|
|
59
60
|
}
|
|
@@ -71,7 +72,7 @@ function sentToSignIn(response, code) {
|
|
|
71
72
|
|
|
72
73
|
test("a pass posted as a form signs its person in and goes home; posted again, it goes to the sign-in page as replayed", async (t) => {
|
|
73
74
|
const issuer = createPassIssuer();
|
|
74
|
-
const app = await startApp(t, { env: issuer.env });
|
|
75
|
+
const { app, backend } = await startApp(t, { env: issuer.env });
|
|
75
76
|
const pass = issuer.pass("ada@example.com");
|
|
76
77
|
|
|
77
78
|
const signedIn = await postPass(app, pass);
|
|
@@ -83,6 +84,9 @@ test("a pass posted as a form signs its person in and goes home; posted again, i
|
|
|
83
84
|
const session = await app.inject({ method: "GET", url: "/api/session", cookies });
|
|
84
85
|
assert.equal(session.json().authenticated, true);
|
|
85
86
|
assert.equal(session.json().email, "ada@example.com");
|
|
87
|
+
// The session keeps the address and browser the pass was posted from.
|
|
88
|
+
const kept = await backend.withTransaction((tx) => tx.sessions.findByTokenHash(sha256Base64url(cookies.jskit_local_refresh_token)));
|
|
89
|
+
assert.deepEqual([kept.ip, kept.userAgent], ["203.0.113.7", "Issuer Page Browser/1.0"]);
|
|
86
90
|
|
|
87
91
|
sentToSignIn(await postPass(app, pass), "auth.pass.replayed");
|
|
88
92
|
sentToSignIn(await postPass(app, issuer.pass("nobody@example.com")), "auth.pass.unmapped");
|
|
@@ -93,7 +97,7 @@ test("a pass posted as a form signs its person in and goes home; posted again, i
|
|
|
93
97
|
|
|
94
98
|
test("one address may post 20 passes a minute; the next is refused with 429 and Retry-After", async (t) => {
|
|
95
99
|
const issuer = createPassIssuer();
|
|
96
|
-
const app = await startApp(t, { env: issuer.env });
|
|
100
|
+
const { app } = await startApp(t, { env: issuer.env });
|
|
97
101
|
assert.deepEqual(DEFAULT_AUTH_RATE_LIMITS.passSignIn, { max: 20, timeWindow: "1 minute" });
|
|
98
102
|
for (let attempt = 0; attempt < 20; attempt += 1) {
|
|
99
103
|
sentToSignIn(await postPass(app, "not a pass"), "auth.pass.malformed");
|
|
@@ -108,14 +112,14 @@ test("one address may post 20 passes a minute; the next is refused with 429 and
|
|
|
108
112
|
|
|
109
113
|
test("without AUTH_PASS_PUBLIC_KEY the app has no pass sign-in route", async (t) => {
|
|
110
114
|
const issuer = createPassIssuer();
|
|
111
|
-
const app = await startApp(t);
|
|
115
|
+
const { app } = await startApp(t);
|
|
112
116
|
assert.equal(app.hasRoute({ method: "POST", url: "/api/login/pass" }), false);
|
|
113
117
|
// The post meets the policy every unknown API post meets, and signs nobody in.
|
|
114
118
|
const posted = await postPass(app, issuer.pass("ada@example.com"));
|
|
115
119
|
assert.equal(posted.statusCode, 403, posted.body);
|
|
116
120
|
assert.deepEqual(posted.cookies, []);
|
|
117
121
|
|
|
118
|
-
const withPasses = await startApp(t, { env: issuer.env });
|
|
122
|
+
const { app: withPasses } = await startApp(t, { env: issuer.env });
|
|
119
123
|
assert.equal(withPasses.hasRoute({ method: "POST", url: "/api/login/pass" }), true);
|
|
120
124
|
});
|
|
121
125
|
|
|
@@ -127,6 +131,6 @@ test("a pass sign-in limit with no limiter to enforce it stops startup", async (
|
|
|
127
131
|
await assert.rejects(startApp(t, { env: issuer.env, config: { auth: { rateLimits: everyOtherLimitOff } } }),
|
|
128
132
|
(error) => /config\.auth\.rateLimits\.passSignIn limits one-time pass sign-in, and no route rate limiter is registered/u
|
|
129
133
|
.test(String(error.details?.cause?.message || error.message)));
|
|
130
|
-
const unlimited = await startApp(t, { env: issuer.env, config: { auth: { rateLimits: { ...everyOtherLimitOff, passSignIn: false } } } });
|
|
134
|
+
const { app: unlimited } = await startApp(t, { env: issuer.env, config: { auth: { rateLimits: { ...everyOtherLimitOff, passSignIn: false } } } });
|
|
131
135
|
assert.equal((await postPass(unlimited, issuer.pass("ada@example.com"))).headers.location, "/");
|
|
132
136
|
});
|
|
@@ -190,7 +190,14 @@ test("removing the authenticator takes a code or a recovery code, shows a wait b
|
|
|
190
190
|
await finish(api);
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
// Whether every part of the shell's page around the console (its app bar and main at least) is inert, as it is while
|
|
194
|
+
// the step-up dialog is open, or else every part live.
|
|
195
|
+
async function shellPageIs(page, inert) {
|
|
196
|
+
const parts = await page.evaluate(() => [...document.querySelectorAll("[data-shell-page]")].map((part) => part.inert));
|
|
197
|
+
return parts.length >= 2 && parts.every((part) => part === inert);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
test("a route that asks for a fresh code opens the step-up dialog over an inert page, runs again after the code, and Escape cancels it, focus returning to the control each time", options, async () => {
|
|
194
201
|
const api = await openApp({
|
|
195
202
|
"POST /api/console/refund": [REQUIRED, { json: { refunded: true } }, REQUIRED],
|
|
196
203
|
"POST /api/second-factor/verify": [
|
|
@@ -205,6 +212,7 @@ test("a route that asks for a fresh code opens the step-up dialog, runs again af
|
|
|
205
212
|
const dialog = page.getByRole("dialog", { name: "Confirm it's you" });
|
|
206
213
|
await expect(dialog.getByRole("heading", { name: "Confirm it's you" })).toBeVisible();
|
|
207
214
|
await expect(dialog.getByLabel("6-digit code")).toBeFocused();
|
|
215
|
+
assert.ok(await shellPageIs(page, true), "the shell's app bar and main are inert behind the dialog");
|
|
208
216
|
await fitsTheScreen(page);
|
|
209
217
|
await page.keyboard.type("000000");
|
|
210
218
|
await page.keyboard.press("Enter");
|
|
@@ -213,15 +221,18 @@ test("a route that asks for a fresh code opens the step-up dialog, runs again af
|
|
|
213
221
|
await page.keyboard.press("Enter");
|
|
214
222
|
await expect(page.getByTestId("console-outcome")).toHaveText("Refunded");
|
|
215
223
|
await expect(dialog).toBeHidden();
|
|
216
|
-
// Focus is back on the control that sent the request, after a code as after cancelling.
|
|
224
|
+
// Focus is back on the control that sent the request, after a code as after cancelling, on a live page.
|
|
217
225
|
await expect(page.getByRole("button", { name: "Refund" })).toBeFocused();
|
|
226
|
+
assert.ok(await shellPageIs(page, false), "the page is live again");
|
|
218
227
|
|
|
219
228
|
await page.keyboard.press("Enter");
|
|
220
229
|
await expect(dialog.getByLabel("6-digit code")).toBeFocused();
|
|
230
|
+
assert.ok(await shellPageIs(page, true), "the page is inert behind the dialog again");
|
|
221
231
|
await page.keyboard.press("Escape");
|
|
222
232
|
await expect(dialog).toBeHidden();
|
|
223
233
|
await expect(page.getByTestId("console-outcome")).toHaveText("Refund failed: Confirm it's you with a code from your authenticator app.");
|
|
224
234
|
await expect(page.getByRole("button", { name: "Refund" })).toBeFocused();
|
|
235
|
+
assert.ok(await shellPageIs(page, false), "the page is live after Escape");
|
|
225
236
|
|
|
226
237
|
assert.equal(bodiesOf(api, "POST /api/console/refund").length, 3);
|
|
227
238
|
assert.deepEqual(bodiesOf(api, "POST /api/second-factor/verify"), [{ code: "000000" }, { code: "123456" }]);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
2
3
|
import process from "node:process";
|
|
3
4
|
import { after, before, test } from "node:test";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -6,6 +7,8 @@ import { chromium, expect } from "@playwright/test";
|
|
|
6
7
|
import { createChromiumLaunchOptions, startViteFixture, stopProcess } from "../../../tooling/testUtils/browserFixture.mjs";
|
|
7
8
|
|
|
8
9
|
const RUN = process.env.JSKIT_AUTH_WEB_BROWSER_INTEGRATION === "1";
|
|
10
|
+
// axe-core as the page runs it, to check a rule the way axe reports it on an app's screens.
|
|
11
|
+
const AXE_PATH = createRequire(import.meta.url).resolve("axe-core/axe.min.js");
|
|
9
12
|
const options = { skip: !RUN, timeout: 120_000 };
|
|
10
13
|
const GUARD_EVALUATOR_KEY = "__JSKIT_WEB_SHELL_GUARD_EVALUATOR__";
|
|
11
14
|
const CAPABILITIES = {
|
|
@@ -578,6 +581,32 @@ test("the account control is the avatar alone up to medium width and truncates a
|
|
|
578
581
|
await finish(api);
|
|
579
582
|
});
|
|
580
583
|
|
|
584
|
+
// WCAG 2.5.3 Label in Name: a control's name holds the text it shows, the words a person using speech input says to
|
|
585
|
+
// press it. Up to medium width the account control is a round button named by its aria-label, and without a picture
|
|
586
|
+
// its avatar shows the initials, "AN" for ana.ferreira. axe's label-content-name-mismatch counts every word drawn on
|
|
587
|
+
// the screen, aria-hidden or not, so the name begins with the initials: "AN ana.ferreira".
|
|
588
|
+
test("the account control's name holds the initials it shows on a phone and a tablet: WCAG 2.5.3 (axe label-content-name-mismatch)", options, async () => {
|
|
589
|
+
const name = "ana.ferreira";
|
|
590
|
+
for (const viewport of [{ width: 390, height: 844 }, { width: 768, height: 1024 }]) {
|
|
591
|
+
const at = `${viewport.width}px`;
|
|
592
|
+
const api = await openApp({ session: { ...SIGNED_IN, username: name }, viewport });
|
|
593
|
+
const { page } = api;
|
|
594
|
+
await page.goto("/home");
|
|
595
|
+
const control = page.getByRole("button", { name: /ana\.ferreira/u });
|
|
596
|
+
await expect(control, `${at}: it shows the initials`).toHaveText("AN");
|
|
597
|
+
await page.addScriptTag({ path: AXE_PATH });
|
|
598
|
+
const audit = await control.evaluate(async (button) => {
|
|
599
|
+
const results = await window.axe.run(button, { runOnly: { type: "rule", values: ["label-content-name-mismatch"] } });
|
|
600
|
+
const nodes = (outcome) => outcome.flatMap((rule) => rule.nodes.map((node) => node.failureSummary ?? node.html));
|
|
601
|
+
return { violations: nodes(results.violations), incomplete: nodes(results.incomplete), passed: nodes(results.passes).length };
|
|
602
|
+
});
|
|
603
|
+
assert.deepEqual({ violations: audit.violations, incomplete: audit.incomplete }, { violations: [], incomplete: [] }, at);
|
|
604
|
+
assert.equal(audit.passed, 1, `${at}: axe checked the control's name against what it shows`);
|
|
605
|
+
await expect(control, at).toHaveAccessibleName(`AN ${name}`);
|
|
606
|
+
await finish(api);
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
|
|
581
610
|
// Material 3's segmented button: one outline, equal segments, the selected one on secondary-container with a check.
|
|
582
611
|
// Register has no "Back to sign in": the Sign in segment is the way back.
|
|
583
612
|
test("Sign in and Register are a segmented button, and Register has no way back but its segment", options, async () => {
|
|
@@ -744,9 +773,12 @@ test("every auth screen's text, its field labels and hints included, reads at WC
|
|
|
744
773
|
const { page } = api;
|
|
745
774
|
const failures = [];
|
|
746
775
|
const readable = async (where) => {
|
|
747
|
-
// The modes fade and move their labels in
|
|
748
|
-
|
|
749
|
-
|
|
776
|
+
// The modes fade and move their labels in, and a button's label fades in over 0.2s: a text that stays under the
|
|
777
|
+
// minimum for the whole wait is a finding. The findings are the wait's own last look; a fresh look once it had
|
|
778
|
+
// settled could land at the start of a fade (a "Register" button label at 0.02 opacity read 1.00:1).
|
|
779
|
+
let findings = [];
|
|
780
|
+
await expect.poll(async () => (findings = await unreadableText(page)), { timeout: 5_000 }).toEqual([]).catch(() => undefined);
|
|
781
|
+
failures.push(...findings.map((finding) => `${where}: ${finding}`));
|
|
750
782
|
};
|
|
751
783
|
for (const colorScheme of ["light", "dark"]) {
|
|
752
784
|
await page.emulateMedia({ colorScheme });
|