@agimon-ai/po-auth-server 0.0.2-alpha.0 → 0.0.2-alpha.10
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/README.md +7 -34
- package/dist/extensions/server.cjs +54 -31
- package/dist/extensions/server.mjs +49 -26
- package/dist/index.cjs +6 -2
- package/dist/index.d.mts +4 -1
- package/dist/index.mjs +3 -1
- package/dist/services/authWebPages/index.cjs +154 -0
- package/dist/services/authWebPages/index.d.mts +31 -0
- package/dist/services/authWebPages/index.mjs +154 -0
- package/dist/services/authWebPages/type.d.mts +22 -0
- package/dist/services/identityConfiguration/index.cjs +7 -0
- package/dist/services/identityConfiguration/index.d.mts +6 -0
- package/dist/services/identityConfiguration/index.mjs +7 -0
- package/dist/services/identityHome/index.cjs +18 -1
- package/dist/services/identityHome/index.d.mts +2 -0
- package/dist/services/identityHome/index.mjs +18 -1
- package/dist/services/identityPairing/index.cjs +90 -0
- package/dist/services/identityPairing/index.d.mts +10 -0
- package/dist/services/identityPairing/index.mjs +90 -0
- package/dist/services/identityWebRoutes/index.cjs +88 -0
- package/dist/services/identityWebRoutes/index.mjs +87 -0
- package/package.json +6 -6
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { AuthWebPages } from "../authWebPages/index.mjs";
|
|
2
|
+
//#region src/services/identityWebRoutes/index.ts
|
|
3
|
+
/** Account pages, not a workspace bridge. A signed-in browser still pairs with the computer. */
|
|
4
|
+
const IDENTITY_WEB_ROUTES = {
|
|
5
|
+
signIn: "/api/auth/browser/sign-in",
|
|
6
|
+
ownerSession: "/api/auth/browser/session",
|
|
7
|
+
org: "/api/auth/browser/team",
|
|
8
|
+
device: "/api/auth/browser/device",
|
|
9
|
+
invitations: "/api/auth/browser/invitations/",
|
|
10
|
+
authBase: "/api/auth",
|
|
11
|
+
csrfHeader: "x-po-csrf"
|
|
12
|
+
};
|
|
13
|
+
const pages = new AuthWebPages(IDENTITY_WEB_ROUTES);
|
|
14
|
+
const invitation = /^\/api\/auth\/browser\/invitations\/([A-Za-z0-9_-]{1,128})$/u;
|
|
15
|
+
const device = /^\/api\/auth\/browser\/device(?:\?user_code=[A-Za-z0-9-]{1,16})?$/u;
|
|
16
|
+
const noStore = { "cache-control": "no-store" };
|
|
17
|
+
const redirect = (location) => new Response(null, {
|
|
18
|
+
status: 302,
|
|
19
|
+
headers: {
|
|
20
|
+
...noStore,
|
|
21
|
+
location
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
/** Only these account pages and the pairing page can follow sign-in. Never a caller's URL. */
|
|
25
|
+
function nextPage(value, fallback) {
|
|
26
|
+
return value && (value === "/pair" || value === IDENTITY_WEB_ROUTES.org || invitation.test(value) || device.test(value)) ? value : fallback;
|
|
27
|
+
}
|
|
28
|
+
/** Node mounts these beside the same auth API Cloud uses. This function never admits a computer session. */
|
|
29
|
+
async function identityWebResponse(request, home) {
|
|
30
|
+
const url = new URL(request.url);
|
|
31
|
+
const path = url.pathname;
|
|
32
|
+
const invite = invitation.exec(path);
|
|
33
|
+
if (path !== IDENTITY_WEB_ROUTES.signIn && path !== IDENTITY_WEB_ROUTES.ownerSession && path !== IDENTITY_WEB_ROUTES.org && path !== IDENTITY_WEB_ROUTES.device && !invite) return void 0;
|
|
34
|
+
if (path === IDENTITY_WEB_ROUTES.ownerSession) {
|
|
35
|
+
if (request.method !== "DELETE") return new Response(null, {
|
|
36
|
+
status: 405,
|
|
37
|
+
headers: noStore
|
|
38
|
+
});
|
|
39
|
+
const { issuer } = await home.bootstrap(request.headers);
|
|
40
|
+
if (request.headers.get("origin") !== issuer || request.headers.get(IDENTITY_WEB_ROUTES.csrfHeader) !== "1") return new Response("Invalid origin", {
|
|
41
|
+
status: 403,
|
|
42
|
+
headers: noStore
|
|
43
|
+
});
|
|
44
|
+
const headers = new Headers(request.headers);
|
|
45
|
+
headers.set("content-type", "application/json");
|
|
46
|
+
return home.fetch(new Request(new URL("/api/auth/sign-out", request.url), {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers,
|
|
49
|
+
body: "{}"
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
if (request.method !== "GET") return new Response(null, {
|
|
53
|
+
status: 405,
|
|
54
|
+
headers: noStore
|
|
55
|
+
});
|
|
56
|
+
if (path === IDENTITY_WEB_ROUTES.signIn) {
|
|
57
|
+
const { methods } = await home.bootstrap(request.headers);
|
|
58
|
+
return pages.signIn({
|
|
59
|
+
emailPassword: methods.emailPassword,
|
|
60
|
+
magicLink: methods.magicLink,
|
|
61
|
+
google: methods.providers.includes("google"),
|
|
62
|
+
github: methods.providers.includes("github")
|
|
63
|
+
}, nextPage(url.searchParams.get("next"), IDENTITY_WEB_ROUTES.org));
|
|
64
|
+
}
|
|
65
|
+
const code = url.searchParams.get("user_code") ?? "";
|
|
66
|
+
if (path === IDENTITY_WEB_ROUTES.device && code && !/^[A-Za-z0-9-]{1,16}$/u.test(code)) return new Response("Invalid device code", {
|
|
67
|
+
status: 400,
|
|
68
|
+
headers: noStore
|
|
69
|
+
});
|
|
70
|
+
const next = path === IDENTITY_WEB_ROUTES.device ? `${path}${code ? `?user_code=${encodeURIComponent(code)}` : ""}` : invite ? path : nextPage(url.searchParams.get("next"), "/pair");
|
|
71
|
+
const session = await home.signedIn(request.headers);
|
|
72
|
+
if (!session) {
|
|
73
|
+
const afterSignIn = path === IDENTITY_WEB_ROUTES.org ? IDENTITY_WEB_ROUTES.org : next;
|
|
74
|
+
return redirect(`${IDENTITY_WEB_ROUTES.signIn}?next=${encodeURIComponent(afterSignIn)}`);
|
|
75
|
+
}
|
|
76
|
+
if (invite) return pages.invitation(invite[1]);
|
|
77
|
+
if (path === IDENTITY_WEB_ROUTES.device) {
|
|
78
|
+
if (session.needsOrg === "create") return pages.org("create", session.orgs, next);
|
|
79
|
+
return pages.device(code, session.email, session.orgs.length > 1 ? {
|
|
80
|
+
orgs: session.orgs,
|
|
81
|
+
active: session.org
|
|
82
|
+
} : void 0);
|
|
83
|
+
}
|
|
84
|
+
return session.needsOrg ? pages.org(session.needsOrg, session.orgs, next) : redirect(next);
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
export { IDENTITY_WEB_ROUTES, identityWebResponse };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agimon-ai/po-auth-server",
|
|
3
|
-
"version": "0.0.2-alpha.
|
|
3
|
+
"version": "0.0.2-alpha.10",
|
|
4
4
|
"description": "Po auth server: sign-in, teams, device trust, recovery, rosters and delegated tokens for Node and Cloudflare hosts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
23
|
"url": "git+https://github.com/AgiFlow/po.git",
|
|
24
|
-
"directory": "layers/
|
|
24
|
+
"directory": "layers/platform/po-auth-server"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
27
|
"dist",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@agimon-ai/po-core": "0.0.0-alpha.
|
|
52
|
-
"@agimon-ai/po-web-security": "0.0.0-alpha.
|
|
51
|
+
"@agimon-ai/po-core": "0.0.0-alpha.168",
|
|
52
|
+
"@agimon-ai/po-web-security": "0.0.0-alpha.168",
|
|
53
53
|
"@better-auth/expo": "1.7.12",
|
|
54
54
|
"@better-auth/passkey": "1.7.12",
|
|
55
55
|
"@better-auth/sso": "1.7.12",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"jose": "6.2.2"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@agimon-ai/po-network": "0.0.2-alpha.
|
|
63
|
-
"@agimon-ai/vibe-lint-plugin-po-core": "0.0.0-alpha.
|
|
62
|
+
"@agimon-ai/po-network": "0.0.2-alpha.115",
|
|
63
|
+
"@agimon-ai/vibe-lint-plugin-po-core": "0.0.0-alpha.168",
|
|
64
64
|
"@types/node": "26.4.1",
|
|
65
65
|
"tsdown": "0.23.0",
|
|
66
66
|
"typescript": "7.0.2",
|