@jskit-ai/users-core 0.2.0 → 0.2.2
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/package.json +10 -10
- package/patterns/user-administration-server/example/packages/users/package.json +2 -2
- package/patterns/user-administration-server/example/packages/users-workspace/package.json +3 -3
- package/src/server/accountSecurity/accountSecurityService.js +6 -2
- package/src/server/accountSecurity/bootAccountSecurityRoutes.js +4 -0
- package/test/accountSecurityService.test.js +34 -0
- package/test/usersRouteRequestInputValidator.test.js +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/users-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"./locales/en.json": "./locales/en.json"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
19
|
-
"@jskit-ai/json-rest-api-core": "0.2.
|
|
20
|
-
"@jskit-ai/resource-core": "0.1.
|
|
21
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
22
|
-
"@jskit-ai/storage-runtime": "0.1.
|
|
23
|
-
"@jskit-ai/uploads-runtime": "0.2.
|
|
18
|
+
"@jskit-ai/database-runtime": "0.1.250",
|
|
19
|
+
"@jskit-ai/json-rest-api-core": "0.2.1",
|
|
20
|
+
"@jskit-ai/resource-core": "0.1.192",
|
|
21
|
+
"@jskit-ai/resource-crud-core": "0.1.192",
|
|
22
|
+
"@jskit-ai/storage-runtime": "0.1.247",
|
|
23
|
+
"@jskit-ai/uploads-runtime": "0.2.1",
|
|
24
24
|
"json-rest-schema": "^1.0.17"
|
|
25
25
|
},
|
|
26
26
|
"description": "Users/account runtime plus HTTP routes for account features.",
|
|
@@ -168,8 +168,8 @@
|
|
|
168
168
|
}
|
|
169
169
|
},
|
|
170
170
|
"peerDependencies": {
|
|
171
|
-
"@jskit-ai/auth-core": "0.2.
|
|
172
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
173
|
-
"@jskit-ai/kernel": "0.2.
|
|
171
|
+
"@jskit-ai/auth-core": "0.2.1",
|
|
172
|
+
"@jskit-ai/http-runtime": "0.2.1",
|
|
173
|
+
"@jskit-ai/kernel": "0.2.1"
|
|
174
174
|
}
|
|
175
175
|
}
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"./shared": "./src/shared/index.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@jskit-ai/crud-core": "0.2.
|
|
13
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
12
|
+
"@jskit-ai/crud-core": "0.2.1",
|
|
13
|
+
"@jskit-ai/resource-crud-core": "0.1.192"
|
|
14
14
|
},
|
|
15
15
|
"jskit": {
|
|
16
16
|
"kind": "runtime",
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"./shared": "./src/shared/index.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@jskit-ai/crud-core": "0.2.
|
|
13
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
14
|
-
"@jskit-ai/workspaces-core": "0.2.
|
|
12
|
+
"@jskit-ai/crud-core": "0.2.1",
|
|
13
|
+
"@jskit-ai/resource-crud-core": "0.1.192",
|
|
14
|
+
"@jskit-ai/workspaces-core": "0.2.2"
|
|
15
15
|
},
|
|
16
16
|
"jskit": {
|
|
17
17
|
"kind": "runtime",
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
accountSettingsResponseFormatter
|
|
10
10
|
} from "../common/formatters/accountSettingsResponseFormatter.js";
|
|
11
|
+
import { accountSecurityStatusFormatter } from "../common/formatters/accountSecurityStatusFormatter.js";
|
|
11
12
|
|
|
12
13
|
function createService({
|
|
13
14
|
userSettingsRepository,
|
|
@@ -99,9 +100,12 @@ function createService({
|
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
|
|
103
|
+
const result = await authService.unlinkProvider(request, {
|
|
103
104
|
provider: payload.provider
|
|
104
|
-
})
|
|
105
|
+
});
|
|
106
|
+
return returnJsonApiData({
|
|
107
|
+
securityStatus: accountSecurityStatusFormatter(result?.securityStatus)
|
|
108
|
+
});
|
|
105
109
|
}
|
|
106
110
|
|
|
107
111
|
async function logoutOtherSessions(request, _user, options = {}) {
|
|
@@ -132,6 +132,10 @@ function registerAccountSecurityRoutes(router, { authService } = {}) {
|
|
|
132
132
|
}
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
+
// As at sign-in, a provider that binds the attempt to this browser sets its cookie.
|
|
136
|
+
if (typeof authService?.writeOAuthStartCookies === "function") {
|
|
137
|
+
authService.writeOAuthStartCookies(reply, result);
|
|
138
|
+
}
|
|
135
139
|
reply.redirect(result.url);
|
|
136
140
|
}
|
|
137
141
|
);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import test from "node:test";
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
|
+
import { buildSecurityStatusFromAuthMethodsStatus } from "@jskit-ai/auth-core/shared/authSecurityStatus";
|
|
4
|
+
import { validateOperationSection } from "@jskit-ai/http-runtime/shared/validators/operationValidation";
|
|
3
5
|
import { createService } from "../src/server/accountSecurity/accountSecurityService.js";
|
|
6
|
+
import { userSettingsResource } from "../src/shared/resources/userSettingsResource.js";
|
|
4
7
|
|
|
5
8
|
test("account security service returns no content result for other sessions", async () => {
|
|
6
9
|
const calls = [];
|
|
@@ -30,3 +33,34 @@ test("account security service returns no content result for other sessions", as
|
|
|
30
33
|
assert.equal(result, null);
|
|
31
34
|
assert.deepEqual(calls, [request]);
|
|
32
35
|
});
|
|
36
|
+
|
|
37
|
+
test("unlinking returns the security status in the settings output contract", async () => {
|
|
38
|
+
// What an auth provider returns: auth-core's status, without settings-only fields.
|
|
39
|
+
const securityStatus = buildSecurityStatusFromAuthMethodsStatus({
|
|
40
|
+
methods: [
|
|
41
|
+
{ id: "password", kind: "password", provider: "email", label: "Password", configured: true, enabled: true },
|
|
42
|
+
{ id: "oauth:github", kind: "oauth", provider: "github", label: "GitHub", configured: false, enabled: false, canEnable: true }
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
const outputOf = (value) => validateOperationSection({
|
|
46
|
+
operation: userSettingsResource.operations.oauthUnlink,
|
|
47
|
+
section: "output",
|
|
48
|
+
value
|
|
49
|
+
});
|
|
50
|
+
assert.equal(outputOf({ securityStatus }).ok, false);
|
|
51
|
+
|
|
52
|
+
const service = createService({
|
|
53
|
+
userSettingsRepository: {},
|
|
54
|
+
userProfilesRepository: {},
|
|
55
|
+
authService: {
|
|
56
|
+
async unlinkProvider(_request, { provider }) {
|
|
57
|
+
assert.equal(provider, "github");
|
|
58
|
+
return { securityStatus };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const result = await service.unlinkOAuthProvider({}, { id: "user-1" }, { provider: "github" });
|
|
63
|
+
const output = outputOf(result.value);
|
|
64
|
+
assert.equal(output.ok, true, JSON.stringify(output.fieldErrors));
|
|
65
|
+
assert.equal(result.value.securityStatus.authMethods[1].canEnable, true);
|
|
66
|
+
});
|
|
@@ -204,6 +204,28 @@ test("account route handlers build action input from request.input", async () =>
|
|
|
204
204
|
assert.equal(calls[7].actionId, "settings.security.sessions.logout_others");
|
|
205
205
|
});
|
|
206
206
|
|
|
207
|
+
test("starting a provider link lets the auth service bind the attempt to the browser", async () => {
|
|
208
|
+
const written = [];
|
|
209
|
+
const routes = await registerRoutes({
|
|
210
|
+
authService: {
|
|
211
|
+
writeOAuthStartCookies(reply, result) {
|
|
212
|
+
written.push({ reply, result });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
const reply = createReplyDouble();
|
|
217
|
+
const result = { url: "https://github.test/authorize", attempt: "browser-key" };
|
|
218
|
+
await findRoute(routes, { method: "GET", path: "/api/settings/security/oauth/:provider/start" }).handler(
|
|
219
|
+
createActionRequest({
|
|
220
|
+
input: { params: { provider: "github" }, query: {} },
|
|
221
|
+
executeAction: async () => result
|
|
222
|
+
}),
|
|
223
|
+
reply
|
|
224
|
+
);
|
|
225
|
+
assert.deepEqual(written, [{ reply, result }]);
|
|
226
|
+
assert.equal(reply.redirectedTo, "https://github.test/authorize");
|
|
227
|
+
});
|
|
228
|
+
|
|
207
229
|
test("account route handlers preserve omitted optional action fields", async () => {
|
|
208
230
|
const routes = await registerRoutes();
|
|
209
231
|
const calls = [];
|