@jskit-ai/auth-core 0.2.13 → 0.2.15
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
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
- `AuthProfileProjector.syncIdentityProfile` documents `onlyWhenChanged`, which providers pass on an ordinary request so a profile that already matches is only read; sign-in and session refresh synchronize in full.
|
|
6
6
|
- `normalizeAuthCapabilities` carries `features.password.selfRegister`: whether anyone may register, not only an invited person or the first account. A provider that doesn't say gets the value of `register`.
|
|
7
7
|
- The register body takes `setupCode`, the first account's one-time setup code, and the capability `features.firstAccountSetupCode` says a provider is waiting for it. New message key: `jskit.auth.validation.setupCodeInvalid`.
|
|
8
|
-
- Registration confirmation: the action and command `auth.register.confirm` (`POST /api/register/confirm`, body `{ token }`, answer `{ ok, email, username, message }` with a message code) confirm a registration's email from the code in its link, and `authApi.confirmRegistration()` calls it. `AuthService.confirmRegistration(
|
|
8
|
+
- Registration confirmation: the action and command `auth.register.confirm` (`POST /api/register/confirm`, body `{ token, password }`, answer `{ ok, email, username, message }` with a message code) confirm a registration's email from the code in its link and the password the registration was made with, so the link alone confirms nothing (a missing password is `auth.validation.passwordRequired`), and `authApi.confirmRegistration()` calls it. `AuthService.confirmRegistration({ token, password })` creates the waiting account and its session; a provider without it answers `AUTH_OPERATION_UNSUPPORTED`. The capability `features.emailConfirmationCode` says the provider takes a code that way. The register and resend answers may carry `confirmationUrl`, the link itself in development. New message keys: `jskit.auth.login.emailUnconfirmed` (refused sign-in, status 403) and `jskit.auth.validation.confirmationCodeRequired`.
|
|
9
9
|
- The dev auth policy and the CSRF cookie's default decide production with the kernel's `isProductionEnv`, the check every JSKIT package now shares; what counts as production is unchanged. `./server/devAuth` no longer exports `isProductionNodeEnv(nodeEnv)`: call `isProductionEnv(env)` from `@jskit-ai/kernel/server/runtime/runtimeMode` instead.
|
|
10
10
|
- The auth policy no longer registers `@fastify/rate-limit`, which it did after the routes existed, so no route limit applied; the kernel now registers it before the routes and enforces each route's `rateLimit`.
|
|
11
11
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -143,6 +143,6 @@
|
|
|
143
143
|
}
|
|
144
144
|
},
|
|
145
145
|
"peerDependencies": {
|
|
146
|
-
"@jskit-ai/kernel": "0.2.
|
|
146
|
+
"@jskit-ai/kernel": "0.2.15"
|
|
147
147
|
}
|
|
148
148
|
}
|
package/src/server/types.js
CHANGED
|
@@ -79,8 +79,9 @@
|
|
|
79
79
|
* @property {() => boolean} isDevAuthBootstrapEnabled
|
|
80
80
|
* @property {(input: object) => Promise<object>} register
|
|
81
81
|
* @property {(input: object) => Promise<object>} resendRegisterConfirmation
|
|
82
|
-
* @property {(input: { token: string }) => Promise<object>} confirmRegistration Creates the account a
|
|
83
|
-
* registration waited to create until its email was confirmed, from its link's code
|
|
82
|
+
* @property {(input: { token: string, password: string }) => Promise<object>} confirmRegistration Creates the account a
|
|
83
|
+
* registration waited to create until its email was confirmed, from its link's code and the password it registered
|
|
84
|
+
* with, and signs the person in.
|
|
84
85
|
* @property {(input: object) => Promise<object>} login
|
|
85
86
|
* @property {(input: object) => Promise<object>} requestOtpLogin
|
|
86
87
|
* @property {(input: object) => Promise<object>} verifyOtpLogin
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createSchema } from "json-rest-schema";
|
|
2
2
|
import { deepFreeze } from "@jskit-ai/kernel/shared/support/deepFreeze";
|
|
3
3
|
import {
|
|
4
|
+
authLoginPasswordFieldDefinition,
|
|
4
5
|
authRecoveryTokenValidator,
|
|
5
6
|
AUTH_FIELD_MESSAGES,
|
|
6
7
|
createCommandMessages,
|
|
@@ -13,15 +14,23 @@ const AUTH_REGISTER_CONFIRM_MESSAGES = createCommandMessages({
|
|
|
13
14
|
required: AUTH_FIELD_MESSAGES.confirmationCodeRequired,
|
|
14
15
|
minLength: AUTH_FIELD_MESSAGES.confirmationCodeRequired,
|
|
15
16
|
default: AUTH_FIELD_MESSAGES.confirmationCodeRequired
|
|
17
|
+
},
|
|
18
|
+
password: {
|
|
19
|
+
required: AUTH_FIELD_MESSAGES.passwordRequired,
|
|
20
|
+
minLength: AUTH_FIELD_MESSAGES.passwordRequired,
|
|
21
|
+
default: AUTH_FIELD_MESSAGES.passwordRequired
|
|
16
22
|
}
|
|
17
23
|
}
|
|
18
24
|
});
|
|
19
25
|
|
|
20
|
-
// The code from a registration's confirmation link
|
|
21
|
-
// account and signs the
|
|
26
|
+
// The code from a registration's confirmation link, with the password the
|
|
27
|
+
// registration was made with: confirming creates the account and signs the
|
|
28
|
+
// person in. The link proves the email; the password proves the registration
|
|
29
|
+
// is the confirming person's own.
|
|
22
30
|
const authRegisterConfirmBodyValidator = deepFreeze({
|
|
23
31
|
schema: createSchema({
|
|
24
|
-
token: { ...authRecoveryTokenValidator, required: true }
|
|
32
|
+
token: { ...authRecoveryTokenValidator, required: true },
|
|
33
|
+
password: { ...authLoginPasswordFieldDefinition, required: true }
|
|
25
34
|
}),
|
|
26
35
|
mode: "create",
|
|
27
36
|
messages: AUTH_REGISTER_CONFIRM_MESSAGES
|
package/test/authApi.test.js
CHANGED
|
@@ -34,7 +34,7 @@ test("authApi exposes the expected methods and request routes", async () => {
|
|
|
34
34
|
await api.login({ email: "x@example.com" });
|
|
35
35
|
await api.devLoginAs({ userId: "42" });
|
|
36
36
|
await api.logout();
|
|
37
|
-
await api.confirmRegistration({ token: "confirmation-code" });
|
|
37
|
+
await api.confirmRegistration({ token: "confirmation-code", password: "correct horse" });
|
|
38
38
|
|
|
39
39
|
assert.equal(calls[0].url, "/api/session");
|
|
40
40
|
assert.equal(calls[1].url, "/api/register/confirmation/resend");
|
|
@@ -46,7 +46,7 @@ test("authApi exposes the expected methods and request routes", async () => {
|
|
|
46
46
|
assert.equal(calls[4].url, "/api/logout");
|
|
47
47
|
assert.equal(calls[4].options.method, "POST");
|
|
48
48
|
assert.equal(calls[5].url, "/api/register/confirm");
|
|
49
|
-
assert.deepEqual(calls[5].options, { method: "POST", body: { token: "confirmation-code" } });
|
|
49
|
+
assert.deepEqual(calls[5].options, { method: "POST", body: { token: "confirmation-code", password: "correct horse" } });
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
test("authApi oauthStartUrl builds provider path with optional returnTo", () => {
|
|
@@ -129,16 +129,21 @@ test("auth command body validators lowercase email inputs", () => {
|
|
|
129
129
|
}
|
|
130
130
|
});
|
|
131
131
|
|
|
132
|
-
test("registration takes the first account's setup code and confirmation takes its link's code", () => {
|
|
132
|
+
test("registration takes the first account's setup code and confirmation takes its link's code and password", () => {
|
|
133
133
|
const registered = authRegisterCommand.operation.body.schema.create({
|
|
134
134
|
email: "owner@example.com",
|
|
135
135
|
password: "correct horse battery staple",
|
|
136
136
|
setupCode: "ABCDE-FGHJK-MNPQR-STVWX"
|
|
137
137
|
});
|
|
138
138
|
assert.equal(registered.validatedObject.setupCode, "ABCDE-FGHJK-MNPQR-STVWX");
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
const confirmBody = authRegisterConfirmCommand.operation.body.schema;
|
|
140
|
+
assert.deepEqual(Object.keys(confirmBody.create({ token: "code", password: "correct horse" }).validatedObject), [
|
|
141
|
+
"token",
|
|
142
|
+
"password"
|
|
141
143
|
]);
|
|
144
|
+
// The link's code alone does not confirm: the registration's password is required.
|
|
145
|
+
assert.deepEqual(Object.keys(confirmBody.create({ token: "code" }).errors), ["password"]);
|
|
146
|
+
assert.deepEqual(Object.keys(confirmBody.create({ token: "code", password: "" }).errors), ["password"]);
|
|
142
147
|
});
|
|
143
148
|
|
|
144
149
|
test("auth session and oauth start commands expose explicit nested response schemas", () => {
|