@jskit-ai/auth-web 0.1.4
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.descriptor.mjs +290 -0
- package/package.json +29 -0
- package/src/client/composables/useDefaultLoginView.js +935 -0
- package/src/client/composables/useDefaultSignOutView.js +113 -0
- package/src/client/index.js +19 -0
- package/src/client/lib/returnToPath.js +20 -0
- package/src/client/lib/surfaceLinkTarget.js +19 -0
- package/src/client/providers/AuthWebClientProvider.js +72 -0
- package/src/client/runtime/authGuardRuntime.js +499 -0
- package/src/client/runtime/authHttpClient.js +19 -0
- package/src/client/runtime/inject.js +43 -0
- package/src/client/runtime/tokens.js +7 -0
- package/src/client/runtime/useLoginView.js +7 -0
- package/src/client/runtime/useSignOut.js +121 -0
- package/src/client/views/AuthProfileMenuLinkItem.vue +83 -0
- package/src/client/views/AuthProfileWidget.vue +100 -0
- package/src/client/views/DefaultLoginView.vue +291 -0
- package/src/client/views/DefaultSignOutView.vue +58 -0
- package/src/server/constants/authActionIds.js +15 -0
- package/src/server/controllers/AuthController.js +183 -0
- package/src/server/providers/AuthRouteServiceProvider.js +31 -0
- package/src/server/providers/AuthWebServiceProvider.js +23 -0
- package/src/server/routes/authRoutes.js +244 -0
- package/src/server/services/AuthWebService.js +126 -0
- package/templates/src/pages/auth/login.vue +17 -0
- package/templates/src/pages/auth/signout.vue +17 -0
- package/templates/src/runtime/authGuardRuntime.js +7 -0
- package/templates/src/runtime/authHttpClient.js +1 -0
- package/templates/src/runtime/useSignOut.js +1 -0
- package/templates/src/views/auth/LoginView.vue +7 -0
- package/templates/src/views/auth/SignOutView.vue +7 -0
- package/test/authGuardRuntime.test.js +361 -0
- package/test/clientBoot.test.js +16 -0
- package/test/clientSurface.test.js +89 -0
- package/test/index.test.js +21 -0
- package/test/logoutFallback.test.js +50 -0
- package/test/providerRuntime.test.js +100 -0
- package/test/returnToPath.test.js +72 -0
- package/test/surfaceLinkTarget.test.js +80 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
normalizeAuthReturnToPath,
|
|
6
|
+
resolveAllowedReturnToOriginsFromPlacementContext
|
|
7
|
+
} from "../src/client/lib/returnToPath.js";
|
|
8
|
+
|
|
9
|
+
test("normalizeAuthReturnToPath keeps valid internal paths", () => {
|
|
10
|
+
assert.equal(normalizeAuthReturnToPath("/dashboard"), "/dashboard");
|
|
11
|
+
assert.equal(normalizeAuthReturnToPath("/w/acme/projects?tab=active"), "/w/acme/projects?tab=active");
|
|
12
|
+
assert.equal(
|
|
13
|
+
normalizeAuthReturnToPath("https://app.example.com/w/acme", "/", {
|
|
14
|
+
allowedOrigins: ["https://app.example.com", "https://auth.example.com"]
|
|
15
|
+
}),
|
|
16
|
+
"https://app.example.com/w/acme"
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("normalizeAuthReturnToPath falls back for invalid or auth-loop paths", () => {
|
|
21
|
+
assert.equal(normalizeAuthReturnToPath("", "/"), "/");
|
|
22
|
+
assert.equal(
|
|
23
|
+
normalizeAuthReturnToPath("https://example.com", "/", {
|
|
24
|
+
allowedOrigins: ["https://app.example.com"]
|
|
25
|
+
}),
|
|
26
|
+
"/"
|
|
27
|
+
);
|
|
28
|
+
assert.equal(normalizeAuthReturnToPath("//evil.com", "/"), "/");
|
|
29
|
+
assert.equal(normalizeAuthReturnToPath("/auth/login", "/"), "/");
|
|
30
|
+
assert.equal(normalizeAuthReturnToPath("/auth/login?returnTo=%2F", "/"), "/");
|
|
31
|
+
assert.equal(normalizeAuthReturnToPath("/auth/signout", "/"), "/");
|
|
32
|
+
assert.equal(normalizeAuthReturnToPath("/auth/signout?returnTo=%2F", "/"), "/");
|
|
33
|
+
assert.equal(
|
|
34
|
+
normalizeAuthReturnToPath("https://auth.example.com/auth/login", "/", {
|
|
35
|
+
allowedOrigins: ["https://auth.example.com"]
|
|
36
|
+
}),
|
|
37
|
+
"/"
|
|
38
|
+
);
|
|
39
|
+
});
|
|
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
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { resolveSurfaceLinkTarget } from "../src/client/lib/surfaceLinkTarget.js";
|
|
4
|
+
|
|
5
|
+
function createPlacementContext() {
|
|
6
|
+
return {
|
|
7
|
+
surfaceConfig: {
|
|
8
|
+
tenancyMode: "workspace",
|
|
9
|
+
defaultSurfaceId: "app",
|
|
10
|
+
enabledSurfaceIds: ["app", "admin", "console"],
|
|
11
|
+
surfacesById: {
|
|
12
|
+
app: {
|
|
13
|
+
id: "app",
|
|
14
|
+
pagesRoot: "app",
|
|
15
|
+
routeBase: "/app",
|
|
16
|
+
enabled: true,
|
|
17
|
+
requiresWorkspace: true
|
|
18
|
+
},
|
|
19
|
+
admin: {
|
|
20
|
+
id: "admin",
|
|
21
|
+
pagesRoot: "admin",
|
|
22
|
+
routeBase: "/admin",
|
|
23
|
+
enabled: true,
|
|
24
|
+
requiresWorkspace: true
|
|
25
|
+
},
|
|
26
|
+
console: {
|
|
27
|
+
id: "console",
|
|
28
|
+
pagesRoot: "console",
|
|
29
|
+
routeBase: "/console",
|
|
30
|
+
enabled: true,
|
|
31
|
+
requiresWorkspace: false
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
test("resolveSurfaceLinkTarget builds surface-scoped path for target surfaces", () => {
|
|
39
|
+
const to = resolveSurfaceLinkTarget({
|
|
40
|
+
context: createPlacementContext(),
|
|
41
|
+
surface: "admin",
|
|
42
|
+
workspaceSuffix: "/projects",
|
|
43
|
+
nonWorkspaceSuffix: "/projects"
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
assert.equal(to, "/admin/projects");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("resolveSurfaceLinkTarget builds non-workspace path for non-workspace surfaces", () => {
|
|
50
|
+
const to = resolveSurfaceLinkTarget({
|
|
51
|
+
context: createPlacementContext(),
|
|
52
|
+
surface: "console",
|
|
53
|
+
workspaceSuffix: "/projects",
|
|
54
|
+
nonWorkspaceSuffix: "/projects"
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
assert.equal(to, "/console/projects");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("resolveSurfaceLinkTarget returns explicit target unchanged", () => {
|
|
61
|
+
const to = resolveSurfaceLinkTarget({
|
|
62
|
+
context: createPlacementContext(),
|
|
63
|
+
surface: "admin",
|
|
64
|
+
explicitTo: "/custom/target"
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
assert.equal(to, "/custom/target");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("resolveSurfaceLinkTarget no longer requires workspace slug for surface links", () => {
|
|
71
|
+
const to = resolveSurfaceLinkTarget({
|
|
72
|
+
context: {
|
|
73
|
+
surfaceConfig: createPlacementContext().surfaceConfig
|
|
74
|
+
},
|
|
75
|
+
surface: "admin",
|
|
76
|
+
workspaceSuffix: "/projects"
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
assert.equal(to, "/admin/projects");
|
|
80
|
+
});
|