@jskit-ai/auth-web 0.1.247 → 0.1.248
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 +5 -5
- package/src/client/composables/loginView/useLoginViewState.js +3 -5
- package/src/client/composables/loginView/validationHelpers.js +2 -8
- package/src/client/composables/useDefaultSignOutView.js +3 -5
- package/src/client/lib/returnToPath.js +2 -9
- package/src/client/runtime/authClient.js +5 -3
- package/src/client/runtime/authGuardRuntime.js +4 -4
- package/test/returnToPath.test.js +1 -37
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.248",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"@mdi/js": "^7.4.47"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@jskit-ai/auth-core": "0.1.
|
|
29
|
-
"@jskit-ai/http-runtime": "0.1.
|
|
30
|
-
"@jskit-ai/kernel": "0.1.
|
|
31
|
-
"@jskit-ai/shell-web": "0.1.
|
|
28
|
+
"@jskit-ai/auth-core": "0.1.244",
|
|
29
|
+
"@jskit-ai/http-runtime": "0.1.244",
|
|
30
|
+
"@jskit-ai/kernel": "0.1.246",
|
|
31
|
+
"@jskit-ai/shell-web": "0.1.252",
|
|
32
32
|
"@tanstack/vue-query": "^5.90.5",
|
|
33
33
|
"pinia": "^4.0.3",
|
|
34
34
|
"vue": "^3.5.44",
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { computed, ref } from "vue";
|
|
2
2
|
import { normalizeAuthCapabilities } from "@jskit-ai/auth-core/shared/authCapabilities";
|
|
3
3
|
import {
|
|
4
|
+
resolveAllowedOriginsFromPlacementContext,
|
|
4
5
|
resolveSurfaceIdFromPlacementPathname,
|
|
5
6
|
resolveSurfaceRootPathFromPlacementContext
|
|
6
7
|
} from "@jskit-ai/shell-web/client/placement";
|
|
7
|
-
import {
|
|
8
|
-
normalizeAuthReturnToPath,
|
|
9
|
-
resolveAllowedReturnToOriginsFromPlacementContext
|
|
10
|
-
} from "../../lib/returnToPath.js";
|
|
8
|
+
import { normalizeAuthReturnToPath } from "../../lib/returnToPath.js";
|
|
11
9
|
import {
|
|
12
10
|
LOGIN_MODE,
|
|
13
11
|
REGISTER_MODE,
|
|
@@ -100,7 +98,7 @@ export function useLoginViewState({ placementContext } = {}) {
|
|
|
100
98
|
});
|
|
101
99
|
const submitLabel = computed(() => SUBMIT_LABEL_BY_MODE[mode.value] || SUBMIT_LABEL_BY_MODE[LOGIN_MODE]);
|
|
102
100
|
const allowedReturnToOrigins = computed(() =>
|
|
103
|
-
|
|
101
|
+
resolveAllowedOriginsFromPlacementContext(placementContext?.value)
|
|
104
102
|
);
|
|
105
103
|
const requestedReturnTo = ref(
|
|
106
104
|
normalizeAuthReturnToPath(
|
|
@@ -4,8 +4,8 @@ function validateCommandSection(commandResource, section, payload) {
|
|
|
4
4
|
if (!commandResource || !commandResource.operation) {
|
|
5
5
|
return {
|
|
6
6
|
ok: true,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
value: payload,
|
|
8
|
+
fieldErrors: {}
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -29,12 +29,6 @@ function resolveValidationMessage(validationResult, fallbackMessage = "Validatio
|
|
|
29
29
|
return String(firstFieldError);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const globalErrors = Array.isArray(validationResult.globalErrors) ? validationResult.globalErrors : [];
|
|
33
|
-
const firstGlobalError = globalErrors.find((entry) => String(entry || "").trim().length > 0);
|
|
34
|
-
if (firstGlobalError) {
|
|
35
|
-
return String(firstGlobalError);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
32
|
return String(fallbackMessage || "Validation failed.");
|
|
39
33
|
}
|
|
40
34
|
|
|
@@ -2,14 +2,12 @@ import { computed, onMounted, ref } from "vue";
|
|
|
2
2
|
import { useShellWebErrorRuntime } from "@jskit-ai/shell-web/client/error";
|
|
3
3
|
import {
|
|
4
4
|
useWebPlacementContext,
|
|
5
|
+
resolveAllowedOriginsFromPlacementContext,
|
|
5
6
|
resolveSurfaceNavigationTargetFromPlacementContext
|
|
6
7
|
} from "@jskit-ai/shell-web/client/placement";
|
|
7
8
|
import { performSignOutRequest } from "../runtime/useSignOut.js";
|
|
8
9
|
import { useAuthGuardRuntime } from "../runtime/inject.js";
|
|
9
|
-
import {
|
|
10
|
-
normalizeAuthReturnToPath,
|
|
11
|
-
resolveAllowedReturnToOriginsFromPlacementContext
|
|
12
|
-
} from "../lib/returnToPath.js";
|
|
10
|
+
import { normalizeAuthReturnToPath } from "../lib/returnToPath.js";
|
|
13
11
|
|
|
14
12
|
function readReturnToPathFromLocation({ allowedOrigins = [] } = {}) {
|
|
15
13
|
if (typeof window !== "object" || !window.location) {
|
|
@@ -42,7 +40,7 @@ export function useDefaultSignOutView() {
|
|
|
42
40
|
const errorMessage = ref("");
|
|
43
41
|
const returnToPath = ref("/");
|
|
44
42
|
const allowedReturnToOrigins = computed(() =>
|
|
45
|
-
|
|
43
|
+
resolveAllowedOriginsFromPlacementContext(placementContext.value)
|
|
46
44
|
);
|
|
47
45
|
|
|
48
46
|
function setErrorMessage(message, dedupeKey = "") {
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
normalizeReturnToPath as normalizeSharedReturnToPath,
|
|
3
|
-
resolveAllowedOriginsFromPlacementContext
|
|
4
|
-
} from "@jskit-ai/kernel/shared/support";
|
|
1
|
+
import { normalizeReturnToPath as normalizeSharedReturnToPath } from "@jskit-ai/kernel/shared/support";
|
|
5
2
|
|
|
6
3
|
const AUTH_LOOP_PATHNAMES = Object.freeze(["/auth/login", "/auth/signout"]);
|
|
7
4
|
|
|
8
|
-
function resolveAllowedReturnToOriginsFromPlacementContext(contextValue = null) {
|
|
9
|
-
return resolveAllowedOriginsFromPlacementContext(contextValue);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
5
|
function normalizeAuthReturnToPath(value, fallback = "/", { allowedOrigins = [] } = {}) {
|
|
13
6
|
return normalizeSharedReturnToPath(value, {
|
|
14
7
|
fallback,
|
|
@@ -17,4 +10,4 @@ function normalizeAuthReturnToPath(value, fallback = "/", { allowedOrigins = []
|
|
|
17
10
|
});
|
|
18
11
|
}
|
|
19
12
|
|
|
20
|
-
export { normalizeAuthReturnToPath
|
|
13
|
+
export { normalizeAuthReturnToPath };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
resolveAllowedOriginsFromPlacementContext,
|
|
3
|
+
resolveSurfaceNavigationTargetFromPlacementContext
|
|
4
|
+
} from "@jskit-ai/shell-web/client/placement";
|
|
2
5
|
|
|
3
|
-
import { resolveAllowedReturnToOriginsFromPlacementContext } from "../lib/returnToPath.js";
|
|
4
6
|
import { createAuthGuardRuntime } from "./authGuardRuntime.js";
|
|
5
7
|
import { completeOAuthCallbackFromUrl } from "./oauthCallbackRuntime.js";
|
|
6
8
|
import { createPopupOAuthLaunchClient } from "./popupOAuthLaunchClient.js";
|
|
@@ -23,7 +25,7 @@ function createMobileCallbackCompleter() {
|
|
|
23
25
|
return completeOAuthCallbackFromUrl({
|
|
24
26
|
url,
|
|
25
27
|
fallbackReturnTo,
|
|
26
|
-
allowedReturnToOrigins:
|
|
28
|
+
allowedReturnToOrigins: resolveAllowedOriginsFromPlacementContext(placementContext),
|
|
27
29
|
defaultProvider,
|
|
28
30
|
...(typeof request === "function" ? { request } : {}),
|
|
29
31
|
refreshSession
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULT_GUARD_EVALUATOR_KEY } from "@jskit-ai/kernel/client";
|
|
1
2
|
import { isTransientQueryError } from "@jskit-ai/kernel/shared/support";
|
|
2
3
|
import { AUTH_PATHS } from "@jskit-ai/auth-core/shared/authPaths";
|
|
3
4
|
import { isExternalLinkTarget } from "@jskit-ai/kernel/shared/support/linkPath";
|
|
@@ -6,7 +7,6 @@ import { createListenerSubscription } from "@jskit-ai/kernel/shared/support/list
|
|
|
6
7
|
import { normalizePermissionList } from "@jskit-ai/kernel/shared/support/permissions";
|
|
7
8
|
import { normalizeAuthCapabilities } from "@jskit-ai/auth-core/shared/authCapabilities";
|
|
8
9
|
|
|
9
|
-
const GLOBAL_GUARD_EVALUATOR_KEY = "__JSKIT_WEB_SHELL_GUARD_EVALUATOR__";
|
|
10
10
|
const AUTH_POLICY_AUTHENTICATED = "authenticated";
|
|
11
11
|
const DEFAULT_SESSION_PATH = AUTH_PATHS.SESSION;
|
|
12
12
|
const DEFAULT_LOGIN_ROUTE = "/auth/login";
|
|
@@ -273,10 +273,10 @@ function installGuardEvaluator({ loginRoute = DEFAULT_LOGIN_ROUTE, getAuthState
|
|
|
273
273
|
authState: getAuthState()
|
|
274
274
|
});
|
|
275
275
|
};
|
|
276
|
-
root[
|
|
276
|
+
root[DEFAULT_GUARD_EVALUATOR_KEY] = evaluator;
|
|
277
277
|
return () => {
|
|
278
|
-
if (root[
|
|
279
|
-
delete root[
|
|
278
|
+
if (root[DEFAULT_GUARD_EVALUATOR_KEY] === evaluator) {
|
|
279
|
+
delete root[DEFAULT_GUARD_EVALUATOR_KEY];
|
|
280
280
|
}
|
|
281
281
|
};
|
|
282
282
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
normalizeAuthReturnToPath,
|
|
6
|
-
resolveAllowedReturnToOriginsFromPlacementContext
|
|
7
|
-
} from "../src/client/lib/returnToPath.js";
|
|
4
|
+
import { normalizeAuthReturnToPath } from "../src/client/lib/returnToPath.js";
|
|
8
5
|
|
|
9
6
|
test("normalizeAuthReturnToPath keeps valid internal paths", () => {
|
|
10
7
|
assert.equal(normalizeAuthReturnToPath("/dashboard"), "/dashboard");
|
|
@@ -37,36 +34,3 @@ test("normalizeAuthReturnToPath falls back for invalid or auth-loop paths", () =
|
|
|
37
34
|
"/"
|
|
38
35
|
);
|
|
39
36
|
});
|
|
40
|
-
|
|
41
|
-
test("resolveAllowedReturnToOriginsFromPlacementContext collects current + surface origins", () => {
|
|
42
|
-
const originalWindow = globalThis.window;
|
|
43
|
-
globalThis.window = {
|
|
44
|
-
location: {
|
|
45
|
-
origin: "https://current.example.com"
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
const origins = resolveAllowedReturnToOriginsFromPlacementContext({
|
|
51
|
-
surfaceConfig: {
|
|
52
|
-
surfacesById: {
|
|
53
|
-
home: { origin: "https://home.example.com" },
|
|
54
|
-
app: { origin: "https://app.example.com" },
|
|
55
|
-
auth: { origin: "https://home.example.com" }
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
assert.deepEqual(origins, [
|
|
61
|
-
"https://current.example.com",
|
|
62
|
-
"https://home.example.com",
|
|
63
|
-
"https://app.example.com"
|
|
64
|
-
]);
|
|
65
|
-
} finally {
|
|
66
|
-
if (typeof originalWindow === "undefined") {
|
|
67
|
-
delete globalThis.window;
|
|
68
|
-
} else {
|
|
69
|
-
globalThis.window = originalWindow;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
});
|