@hogsend/engine 0.63.0 → 0.65.0
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 +13 -12
- package/src/account-links/__fixtures__/fake-fetch.test.ts +57 -0
- package/src/account-links/__fixtures__/fake-fetch.ts +114 -0
- package/src/account-links/__fixtures__/steam.json +21 -0
- package/src/account-links/__fixtures__/twitch.json +22 -0
- package/src/account-links/index.ts +8 -0
- package/src/account-links/steam.test.ts +243 -0
- package/src/account-links/steam.ts +48 -0
- package/src/account-links/twitch.test.ts +157 -0
- package/src/account-links/twitch.ts +99 -0
- package/src/container.account-links.env.test.ts +65 -0
- package/src/container.account-links.halfenv.test.ts +48 -0
- package/src/container.account-links.test.ts +185 -0
- package/src/container.ts +120 -0
- package/src/env.ts +60 -0
- package/src/index.ts +104 -1
- package/src/journeys/journey-boundary.ts +8 -0
- package/src/lib/account-link-emit.ts +126 -0
- package/src/lib/account-link-events.ts +180 -0
- package/src/lib/account-link-hooks.test.ts +158 -0
- package/src/lib/account-link-hooks.ts +73 -0
- package/src/lib/account-link-ingest.ts +364 -0
- package/src/lib/account-link-nonce.test.ts +52 -0
- package/src/lib/account-link-nonce.ts +57 -0
- package/src/lib/account-link-origins.test.ts +72 -0
- package/src/lib/account-link-origins.ts +87 -0
- package/src/lib/account-link-pkce.test.ts +91 -0
- package/src/lib/account-link-pkce.ts +106 -0
- package/src/lib/account-link-provider-registry.test.ts +52 -0
- package/src/lib/account-link-provider-registry.ts +61 -0
- package/src/lib/account-link-throttle.test.ts +178 -0
- package/src/lib/account-link-throttle.ts +130 -0
- package/src/lib/account-link-url.ts +85 -0
- package/src/lib/account-links-emit.test.ts +525 -0
- package/src/lib/account-links-env.test.ts +40 -0
- package/src/lib/account-links-from-env.test.ts +187 -0
- package/src/lib/account-links-from-env.ts +126 -0
- package/src/lib/account-links.ts +1300 -0
- package/src/lib/app-secret.ts +34 -0
- package/src/lib/attachments.ts +81 -0
- package/src/lib/connector-actions.test.ts +13 -4
- package/src/lib/connector-state.account-link.test.ts +114 -0
- package/src/lib/connector-state.ts +48 -3
- package/src/lib/contacts.ts +320 -6
- package/src/lib/domain-status.return-path.test.ts +68 -0
- package/src/lib/domain-status.ts +19 -0
- package/src/lib/email-provider-boot.hogsend.test.ts +48 -0
- package/src/lib/email-provider-boot.test.ts +33 -0
- package/src/lib/email-providers-from-env.hogsend.test.ts +110 -0
- package/src/lib/email-providers-from-env.test.ts +52 -0
- package/src/lib/email-providers-from-env.ts +67 -0
- package/src/lib/email-service-types.ts +11 -0
- package/src/lib/email.ts +17 -0
- package/src/lib/mailer-bounce-idempotency.test.ts +469 -0
- package/src/lib/mailer-rejected.test.ts +229 -0
- package/src/lib/mailer-replied.test.ts +379 -0
- package/src/lib/mailer.ts +359 -24
- package/src/lib/outbound-account-payloads.test.ts +137 -0
- package/src/lib/outbound.ts +126 -0
- package/src/lib/provider-credentials.ts +19 -5
- package/src/lib/sending-domain-guidance.test.ts +99 -0
- package/src/lib/sending-domain-guidance.ts +84 -0
- package/src/lib/tracked-attachments.test.ts +376 -0
- package/src/lib/tracked-idempotency-header.test.ts +437 -0
- package/src/lib/tracked.ts +116 -4
- package/src/lib/tracking-event-names.ts +9 -0
- package/src/lib/webhook-catalog-sync.test.ts +24 -0
- package/src/lib/webhook-signing.ts +25 -1
- package/src/routes/accounts/callback.ts +597 -0
- package/src/routes/accounts/emit.ts +231 -0
- package/src/routes/accounts/import-links.ts +210 -0
- package/src/routes/accounts/index.ts +75 -0
- package/src/routes/accounts/lookup.ts +177 -0
- package/src/routes/accounts/me.ts +215 -0
- package/src/routes/accounts/mint.ts +279 -0
- package/src/routes/accounts/pages.ts +62 -0
- package/src/routes/accounts/resolve.ts +61 -0
- package/src/routes/accounts/serialize.ts +96 -0
- package/src/routes/accounts/shared.ts +107 -0
- package/src/routes/accounts/start.ts +229 -0
- package/src/routes/accounts/unlink.ts +98 -0
- package/src/routes/admin/agent.ts +2 -0
- package/src/routes/admin/api-keys.ts +7 -0
- package/src/routes/admin/contacts.ts +38 -2
- package/src/routes/admin/domain-conflict.test.ts +188 -0
- package/src/routes/admin/domain-return-path.test.ts +274 -0
- package/src/routes/admin/domain.ts +214 -1
- package/src/routes/connectors/index.ts +17 -0
- package/src/routes/contacts/index.ts +8 -0
- package/src/routes/index.ts +75 -0
- package/src/testing-barrel.test.ts +74 -0
- package/src/testing.ts +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hogsend/engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.65.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@hatchet-dev/typescript-sdk": "^1.22.3",
|
|
34
34
|
"@hono/node-server": "^2.0.4",
|
|
35
|
-
"@hono/zod-openapi": "
|
|
35
|
+
"@hono/zod-openapi": "1.4.0",
|
|
36
36
|
"@openrouter/ai-sdk-provider": "^2.9.1",
|
|
37
37
|
"@scalar/hono-api-reference": "^0.10.19",
|
|
38
38
|
"@t3-oss/env-core": "^0.13.11",
|
|
@@ -53,18 +53,19 @@
|
|
|
53
53
|
"svix": "^1.95.1",
|
|
54
54
|
"winston": "^3.19.0",
|
|
55
55
|
"zod": "^4.4.3",
|
|
56
|
-
"@hogsend/attribution": "^0.
|
|
57
|
-
"@hogsend/core": "^0.
|
|
58
|
-
"@hogsend/db": "^0.
|
|
59
|
-
"@hogsend/email": "^0.
|
|
60
|
-
"@hogsend/plugin-posthog": "^0.
|
|
61
|
-
"@hogsend/plugin-resend": "^0.
|
|
62
|
-
"@hogsend/sms": "^0.
|
|
56
|
+
"@hogsend/attribution": "^0.65.0",
|
|
57
|
+
"@hogsend/core": "^0.65.0",
|
|
58
|
+
"@hogsend/db": "^0.65.0",
|
|
59
|
+
"@hogsend/email": "^0.65.0",
|
|
60
|
+
"@hogsend/plugin-posthog": "^0.65.0",
|
|
61
|
+
"@hogsend/plugin-resend": "^0.65.0",
|
|
62
|
+
"@hogsend/sms": "^0.65.0"
|
|
63
63
|
},
|
|
64
64
|
"optionalDependencies": {
|
|
65
|
-
"@hogsend/plugin-apollo": "^0.
|
|
66
|
-
"@hogsend/plugin-
|
|
67
|
-
"@hogsend/plugin-
|
|
65
|
+
"@hogsend/plugin-apollo": "^0.65.0",
|
|
66
|
+
"@hogsend/plugin-hogsend": "^0.65.0",
|
|
67
|
+
"@hogsend/plugin-postmark": "^0.65.0",
|
|
68
|
+
"@hogsend/plugin-twilio": "^0.65.0"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
71
|
"@types/node": "^22.15.3",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { fakeFetch } from "./fake-fetch.js";
|
|
4
|
+
import steamFixtures from "./steam.json" with { type: "json" };
|
|
5
|
+
|
|
6
|
+
test("records calls with method, headers and body", async () => {
|
|
7
|
+
const { fetchImpl, calls } = fakeFetch({
|
|
8
|
+
"POST https://id.twitch.tv/oauth2/token": {
|
|
9
|
+
body: { access_token: "fixture-token" },
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const response = await fetchImpl("https://id.twitch.tv/oauth2/token?x=1", {
|
|
14
|
+
method: "POST",
|
|
15
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
16
|
+
body: new URLSearchParams({ grant_type: "authorization_code" }).toString(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
assert.equal(response.status, 200);
|
|
20
|
+
assert.deepEqual(await response.json(), { access_token: "fixture-token" });
|
|
21
|
+
assert.equal(calls.length, 1);
|
|
22
|
+
assert.equal(calls[0]?.method, "POST");
|
|
23
|
+
// The full URL (query included) is recorded even though the route key
|
|
24
|
+
// strips the query — tests assert params off `calls`.
|
|
25
|
+
assert.equal(calls[0]?.url, "https://id.twitch.tv/oauth2/token?x=1");
|
|
26
|
+
assert.equal(
|
|
27
|
+
calls[0]?.headers["content-type"],
|
|
28
|
+
"application/x-www-form-urlencoded",
|
|
29
|
+
);
|
|
30
|
+
assert.equal(calls[0]?.body, "grant_type=authorization_code");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("throws on an unmatched route", async () => {
|
|
34
|
+
const { fetchImpl, calls } = fakeFetch({});
|
|
35
|
+
await assert.rejects(
|
|
36
|
+
() =>
|
|
37
|
+
fetchImpl("https://evil.example.com/openid/login", { method: "POST" }),
|
|
38
|
+
/no route registered for "POST https:\/\/evil\.example\.com\/openid\/login"/,
|
|
39
|
+
);
|
|
40
|
+
// The call is still recorded, so a test can see WHAT reached out.
|
|
41
|
+
assert.equal(calls.length, 1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("serves a text body for the steam check_authentication route", async () => {
|
|
45
|
+
const { fetchImpl } = fakeFetch({
|
|
46
|
+
"POST https://steamcommunity.com/openid/login": {
|
|
47
|
+
text: steamFixtures.checkAuthenticationValid,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
const response = await fetchImpl("https://steamcommunity.com/openid/login", {
|
|
51
|
+
method: "POST",
|
|
52
|
+
body: "openid.mode=check_authentication",
|
|
53
|
+
});
|
|
54
|
+
assert.equal(response.status, 200);
|
|
55
|
+
assert.match(response.headers.get("content-type") ?? "", /text\/plain/);
|
|
56
|
+
assert.match(await response.text(), /^is_valid:true$/m);
|
|
57
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic in-process `fetch` for the account-link test suites.
|
|
3
|
+
*
|
|
4
|
+
* The injection point is PRD 01's `HandleCallbackArgs.fetchImpl` (resolved as
|
|
5
|
+
* `fetchImpl ?? globalThis.fetch` inside the presets) — the same pattern
|
|
6
|
+
* `plugin-apollo` proved (`packages/plugin-apollo/src/index.ts:46-47`, "the
|
|
7
|
+
* whole suite runs offline through this"). The engine providers therefore need
|
|
8
|
+
* no `fetch` field of their own, and PRD 07's route tests thread the same
|
|
9
|
+
* `fetchImpl` through.
|
|
10
|
+
*
|
|
11
|
+
* Routes key on `method + " " + url-without-query`, so a test asserts query
|
|
12
|
+
* params off `calls` rather than baking them into the key. An unmatched call
|
|
13
|
+
* THROWS with the full URL, so a provider that quietly reaches an unexpected
|
|
14
|
+
* endpoint fails loudly instead of hanging on a real network call.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export interface FakeFetchRoute {
|
|
18
|
+
/** Response status. Default 200. */
|
|
19
|
+
status?: number;
|
|
20
|
+
/** JSON body — serialized with `JSON.stringify`, `content-type: application/json`. */
|
|
21
|
+
body?: unknown;
|
|
22
|
+
/**
|
|
23
|
+
* Plain-text body (`content-type: text/plain`) — Steam's
|
|
24
|
+
* `check_authentication` answers key-value text, not JSON. Wins over `body`
|
|
25
|
+
* when both are set.
|
|
26
|
+
*/
|
|
27
|
+
text?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface FakeFetchCall {
|
|
31
|
+
url: string;
|
|
32
|
+
method: string;
|
|
33
|
+
headers: Record<string, string>;
|
|
34
|
+
body: string | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function normalizeHeaders(
|
|
38
|
+
headers: HeadersInit | undefined,
|
|
39
|
+
): Record<string, string> {
|
|
40
|
+
const out: Record<string, string> = {};
|
|
41
|
+
if (!headers) return out;
|
|
42
|
+
// Headers lower-cases names on iteration; mirror that for the other shapes
|
|
43
|
+
// so a test never has to guess the casing.
|
|
44
|
+
if (headers instanceof Headers) {
|
|
45
|
+
headers.forEach((value, key) => {
|
|
46
|
+
out[key.toLowerCase()] = value;
|
|
47
|
+
});
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(headers)) {
|
|
51
|
+
for (const [key, value] of headers) out[key.toLowerCase()] = value;
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
55
|
+
out[key.toLowerCase()] = value;
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function fakeFetch(routes: Record<string, FakeFetchRoute>): {
|
|
61
|
+
fetchImpl: typeof fetch;
|
|
62
|
+
calls: FakeFetchCall[];
|
|
63
|
+
} {
|
|
64
|
+
const calls: FakeFetchCall[] = [];
|
|
65
|
+
|
|
66
|
+
const fetchImpl = (async (
|
|
67
|
+
input: RequestInfo | URL,
|
|
68
|
+
init?: RequestInit,
|
|
69
|
+
): Promise<Response> => {
|
|
70
|
+
const url =
|
|
71
|
+
typeof input === "string"
|
|
72
|
+
? input
|
|
73
|
+
: input instanceof URL
|
|
74
|
+
? input.toString()
|
|
75
|
+
: input.url;
|
|
76
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
77
|
+
const parsed = new URL(url);
|
|
78
|
+
const key = `${method} ${parsed.origin}${parsed.pathname}`;
|
|
79
|
+
|
|
80
|
+
const rawBody = init?.body;
|
|
81
|
+
calls.push({
|
|
82
|
+
url,
|
|
83
|
+
method,
|
|
84
|
+
headers: normalizeHeaders(init?.headers),
|
|
85
|
+
body: rawBody === undefined || rawBody === null ? null : String(rawBody),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const route = routes[key];
|
|
89
|
+
if (!route) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`fakeFetch: no route registered for "${key}" (full url: ${url}). ` +
|
|
92
|
+
`Registered: ${Object.keys(routes).join(", ") || "<none>"}`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const status = route.status ?? 200;
|
|
97
|
+
const isText = route.text !== undefined;
|
|
98
|
+
const bodyText = isText
|
|
99
|
+
? (route.text as string)
|
|
100
|
+
: route.body !== undefined
|
|
101
|
+
? JSON.stringify(route.body)
|
|
102
|
+
: "";
|
|
103
|
+
return new Response(bodyText, {
|
|
104
|
+
status,
|
|
105
|
+
headers: {
|
|
106
|
+
"content-type": isText
|
|
107
|
+
? "text/plain; charset=utf-8"
|
|
108
|
+
: "application/json",
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
}) as typeof fetch;
|
|
112
|
+
|
|
113
|
+
return { fetchImpl, calls };
|
|
114
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"checkAuthenticationValid": "ns:http://specs.openid.net/auth/2.0\nis_valid:true\n",
|
|
3
|
+
"checkAuthenticationInvalid": "ns:http://specs.openid.net/auth/2.0\nis_valid:false\n",
|
|
4
|
+
"playerSummaries": {
|
|
5
|
+
"response": {
|
|
6
|
+
"players": [
|
|
7
|
+
{
|
|
8
|
+
"steamid": "76561197960435530",
|
|
9
|
+
"communityvisibilitystate": 3,
|
|
10
|
+
"profilestate": 1,
|
|
11
|
+
"personaname": "Robin",
|
|
12
|
+
"profileurl": "https://steamcommunity.com/id/robinwalker/",
|
|
13
|
+
"avatar": "https://avatars.steamstatic.com/small.jpg",
|
|
14
|
+
"avatarmedium": "https://avatars.steamstatic.com/medium.jpg",
|
|
15
|
+
"avatarfull": "https://avatars.steamstatic.com/full.jpg",
|
|
16
|
+
"personastate": 0
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"users": {
|
|
3
|
+
"data": [
|
|
4
|
+
{
|
|
5
|
+
"id": "141981764",
|
|
6
|
+
"login": "twitchdev",
|
|
7
|
+
"display_name": "TwitchDev",
|
|
8
|
+
"type": "",
|
|
9
|
+
"broadcaster_type": "partner",
|
|
10
|
+
"description": "Supporting third-party developers building Twitch integrations.",
|
|
11
|
+
"profile_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/8a6381c7-d0c0-4576-b179-38bd5ce1d6af-profile_image-300x300.png",
|
|
12
|
+
"offline_image_url": "",
|
|
13
|
+
"view_count": 5980557,
|
|
14
|
+
"email": "not-real@email.com",
|
|
15
|
+
"created_at": "2016-12-14T20:32:28Z"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"usersEmpty": {
|
|
20
|
+
"data": []
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The two built-in account-link providers. Config over the `@hogsend/core`
|
|
2
|
+
// presets, NOT plugin packages (DECISIONS §3.1): a provider here is a URL, one
|
|
3
|
+
// `fetch` and a field mapping — zero dependencies, no runtime. Steam and
|
|
4
|
+
// Twitch are deliberately the ONLY first-party providers here (DECISIONS
|
|
5
|
+
// §12): a platform whose linking already ships elsewhere in this repo must
|
|
6
|
+
// keep its single writer, so it gets no second definition in this directory.
|
|
7
|
+
export { type SteamAccountLinkConfig, steamAccountLink } from "./steam.js";
|
|
8
|
+
export { type TwitchAccountLinkConfig, twitchAccountLink } from "./twitch.js";
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
AccountLinkCallbackError,
|
|
5
|
+
hours,
|
|
6
|
+
STEAM_OPENID_ENDPOINT,
|
|
7
|
+
steamReturnTo,
|
|
8
|
+
} from "@hogsend/core";
|
|
9
|
+
import { fakeFetch } from "./__fixtures__/fake-fetch.js";
|
|
10
|
+
import steamFixtures from "./__fixtures__/steam.json" with { type: "json" };
|
|
11
|
+
import { steamAccountLink } from "./steam.js";
|
|
12
|
+
|
|
13
|
+
const REALM = "https://api.example.com";
|
|
14
|
+
const CALLBACK = "https://api.example.com/v1/accounts/steam/callback";
|
|
15
|
+
const STATE = "signed-state-token";
|
|
16
|
+
// The redirectUri the callback route presents = the return_to it minted
|
|
17
|
+
// (state included) — handleCallback compares the echo byte-for-byte.
|
|
18
|
+
const RETURN_TO = steamReturnTo(CALLBACK, STATE);
|
|
19
|
+
const STEAM_ID = "76561197960435530";
|
|
20
|
+
|
|
21
|
+
/** A well-formed positive assertion; tests override fields to break it. */
|
|
22
|
+
function provenQuery(
|
|
23
|
+
overrides: Record<string, string> = {},
|
|
24
|
+
): Record<string, string> {
|
|
25
|
+
return {
|
|
26
|
+
"openid.ns": "http://specs.openid.net/auth/2.0",
|
|
27
|
+
"openid.mode": "id_res",
|
|
28
|
+
"openid.op_endpoint": STEAM_OPENID_ENDPOINT,
|
|
29
|
+
"openid.claimed_id": `https://steamcommunity.com/openid/id/${STEAM_ID}`,
|
|
30
|
+
"openid.identity": `https://steamcommunity.com/openid/id/${STEAM_ID}`,
|
|
31
|
+
"openid.return_to": RETURN_TO,
|
|
32
|
+
"openid.response_nonce": "2026-08-13T00:00:00Znonce",
|
|
33
|
+
"openid.assoc_handle": "1234567890",
|
|
34
|
+
"openid.signed":
|
|
35
|
+
"signed,op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle",
|
|
36
|
+
"openid.sig": "fixture-signature",
|
|
37
|
+
state: STATE,
|
|
38
|
+
...overrides,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const CHECK_AUTH_ROUTE = `POST ${STEAM_OPENID_ENDPOINT}`;
|
|
43
|
+
const SUMMARIES_ROUTE =
|
|
44
|
+
"GET https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/";
|
|
45
|
+
|
|
46
|
+
test("authorizeUrl carries identifier_select, the configured realm and a return_to containing the state", async () => {
|
|
47
|
+
const url = new URL(
|
|
48
|
+
await steamAccountLink({ realm: REALM }).authorizeUrl({
|
|
49
|
+
state: STATE,
|
|
50
|
+
redirectUri: CALLBACK,
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
assert.equal(url.origin + url.pathname, STEAM_OPENID_ENDPOINT);
|
|
54
|
+
assert.equal(url.searchParams.get("openid.mode"), "checkid_setup");
|
|
55
|
+
assert.equal(
|
|
56
|
+
url.searchParams.get("openid.claimed_id"),
|
|
57
|
+
"http://specs.openid.net/auth/2.0/identifier_select",
|
|
58
|
+
);
|
|
59
|
+
assert.equal(
|
|
60
|
+
url.searchParams.get("openid.identity"),
|
|
61
|
+
"http://specs.openid.net/auth/2.0/identifier_select",
|
|
62
|
+
);
|
|
63
|
+
assert.equal(url.searchParams.get("openid.realm"), REALM);
|
|
64
|
+
const returnTo = url.searchParams.get("openid.return_to");
|
|
65
|
+
assert.ok(returnTo);
|
|
66
|
+
assert.equal(new URL(returnTo).searchParams.get("state"), STATE);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("a proven callback yields a 17-digit providerUserId, no verifiedEmail and no tokens", async () => {
|
|
70
|
+
const { fetchImpl, calls } = fakeFetch({
|
|
71
|
+
[CHECK_AUTH_ROUTE]: { text: steamFixtures.checkAuthenticationValid },
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const identity = await steamAccountLink({ realm: REALM }).handleCallback({
|
|
75
|
+
query: provenQuery(),
|
|
76
|
+
redirectUri: RETURN_TO,
|
|
77
|
+
fetchImpl,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
assert.match(identity.providerUserId, /^\d{17}$/);
|
|
81
|
+
assert.equal(identity.providerUserId, STEAM_ID);
|
|
82
|
+
assert.equal(identity.verifiedEmail, undefined);
|
|
83
|
+
assert.equal(identity.tokens, undefined);
|
|
84
|
+
|
|
85
|
+
// The proof round-trip went to Steam's HARDCODED endpoint (never a
|
|
86
|
+
// callback-supplied op_endpoint) with the mode rewritten.
|
|
87
|
+
assert.equal(calls.length, 1);
|
|
88
|
+
assert.equal(calls[0]?.url, STEAM_OPENID_ENDPOINT);
|
|
89
|
+
const body = new URLSearchParams(calls[0]?.body ?? "");
|
|
90
|
+
assert.equal(body.get("openid.mode"), "check_authentication");
|
|
91
|
+
assert.equal(body.get("openid.sig"), "fixture-signature");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("an is_valid:false answer is exchange_failed, not a link", async () => {
|
|
95
|
+
const { fetchImpl } = fakeFetch({
|
|
96
|
+
[CHECK_AUTH_ROUTE]: { text: steamFixtures.checkAuthenticationInvalid },
|
|
97
|
+
});
|
|
98
|
+
await assert.rejects(
|
|
99
|
+
() =>
|
|
100
|
+
steamAccountLink({ realm: REALM }).handleCallback({
|
|
101
|
+
query: provenQuery(),
|
|
102
|
+
redirectUri: RETURN_TO,
|
|
103
|
+
fetchImpl,
|
|
104
|
+
}),
|
|
105
|
+
(err: unknown) =>
|
|
106
|
+
err instanceof AccountLinkCallbackError &&
|
|
107
|
+
err.reason === "exchange_failed",
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("a web api key adds the GetPlayerSummaries profile pull", async () => {
|
|
112
|
+
const { fetchImpl, calls } = fakeFetch({
|
|
113
|
+
[CHECK_AUTH_ROUTE]: { text: steamFixtures.checkAuthenticationValid },
|
|
114
|
+
[SUMMARIES_ROUTE]: { body: steamFixtures.playerSummaries },
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const identity = await steamAccountLink({
|
|
118
|
+
realm: REALM,
|
|
119
|
+
webApiKey: "fixture-web-api-key",
|
|
120
|
+
}).handleCallback({
|
|
121
|
+
query: provenQuery(),
|
|
122
|
+
redirectUri: RETURN_TO,
|
|
123
|
+
fetchImpl,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
assert.equal(identity.providerUserId, STEAM_ID);
|
|
127
|
+
assert.equal(identity.username, "Robin");
|
|
128
|
+
assert.equal(identity.avatarUrl, "https://avatars.steamstatic.com/full.jpg");
|
|
129
|
+
const summaries = calls.find((c) => c.url.includes("GetPlayerSummaries"));
|
|
130
|
+
assert.ok(summaries);
|
|
131
|
+
const url = new URL(summaries.url);
|
|
132
|
+
assert.equal(url.searchParams.get("steamids"), STEAM_ID);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("a failing GetPlayerSummaries still yields a proven identity with no username", async () => {
|
|
136
|
+
const { fetchImpl } = fakeFetch({
|
|
137
|
+
[CHECK_AUTH_ROUTE]: { text: steamFixtures.checkAuthenticationValid },
|
|
138
|
+
[SUMMARIES_ROUTE]: { status: 500, body: { error: "upstream down" } },
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const identity = await steamAccountLink({
|
|
142
|
+
realm: REALM,
|
|
143
|
+
webApiKey: "fixture-web-api-key",
|
|
144
|
+
}).handleCallback({
|
|
145
|
+
query: provenQuery(),
|
|
146
|
+
redirectUri: RETURN_TO,
|
|
147
|
+
fetchImpl,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// A cosmetic pull must never fail a proven link.
|
|
151
|
+
assert.equal(identity.providerUserId, STEAM_ID);
|
|
152
|
+
assert.equal(identity.username, undefined);
|
|
153
|
+
assert.equal(identity.avatarUrl, undefined);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("sync is present because a web api key is configured, and its every is hours(24)", () => {
|
|
157
|
+
const withKey = steamAccountLink({ realm: REALM, webApiKey: "k" });
|
|
158
|
+
assert.equal(typeof withKey.sync?.read, "function");
|
|
159
|
+
assert.deepEqual(withKey.sync?.every, hours(24));
|
|
160
|
+
// The widen-not-enable proof from the provider side: no key, no sync — but
|
|
161
|
+
// the provider itself still exists and links.
|
|
162
|
+
const withoutKey = steamAccountLink({ realm: REALM });
|
|
163
|
+
assert.equal(withoutKey.sync, undefined);
|
|
164
|
+
assert.equal(withoutKey.capabilities?.tokens, undefined);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("the security assertions hold end to end", async () => {
|
|
168
|
+
const provider = steamAccountLink({ realm: REALM });
|
|
169
|
+
|
|
170
|
+
// Foreign op_endpoint: refused BEFORE any network call — the round-trip is
|
|
171
|
+
// never posted to a verifier the attacker names.
|
|
172
|
+
{
|
|
173
|
+
const { fetchImpl, calls } = fakeFetch({});
|
|
174
|
+
await assert.rejects(
|
|
175
|
+
() =>
|
|
176
|
+
provider.handleCallback({
|
|
177
|
+
query: provenQuery({
|
|
178
|
+
"openid.op_endpoint": "https://evil.example.com/openid/login",
|
|
179
|
+
}),
|
|
180
|
+
redirectUri: RETURN_TO,
|
|
181
|
+
fetchImpl,
|
|
182
|
+
}),
|
|
183
|
+
(err: unknown) =>
|
|
184
|
+
err instanceof AccountLinkCallbackError &&
|
|
185
|
+
err.reason === "state_invalid",
|
|
186
|
+
);
|
|
187
|
+
assert.equal(calls.length, 0);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Mismatched return_to: a cross-flow replay, refused before any network.
|
|
191
|
+
{
|
|
192
|
+
const { fetchImpl, calls } = fakeFetch({});
|
|
193
|
+
await assert.rejects(
|
|
194
|
+
() =>
|
|
195
|
+
provider.handleCallback({
|
|
196
|
+
query: provenQuery({
|
|
197
|
+
"openid.return_to": steamReturnTo(CALLBACK, "other-state"),
|
|
198
|
+
}),
|
|
199
|
+
redirectUri: RETURN_TO,
|
|
200
|
+
fetchImpl,
|
|
201
|
+
}),
|
|
202
|
+
(err: unknown) =>
|
|
203
|
+
err instanceof AccountLinkCallbackError &&
|
|
204
|
+
err.reason === "state_invalid",
|
|
205
|
+
);
|
|
206
|
+
assert.equal(calls.length, 0);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// mode=cancel: the player's own "no" is denied, never state_invalid.
|
|
210
|
+
{
|
|
211
|
+
const { fetchImpl, calls } = fakeFetch({});
|
|
212
|
+
await assert.rejects(
|
|
213
|
+
() =>
|
|
214
|
+
provider.handleCallback({
|
|
215
|
+
query: { "openid.mode": "cancel", state: STATE },
|
|
216
|
+
redirectUri: RETURN_TO,
|
|
217
|
+
fetchImpl,
|
|
218
|
+
}),
|
|
219
|
+
(err: unknown) =>
|
|
220
|
+
err instanceof AccountLinkCallbackError && err.reason === "denied",
|
|
221
|
+
);
|
|
222
|
+
assert.equal(calls.length, 0);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Malformed claimed_id (prefix smuggling): parsed and refused pre-network.
|
|
226
|
+
{
|
|
227
|
+
const { fetchImpl, calls } = fakeFetch({});
|
|
228
|
+
await assert.rejects(
|
|
229
|
+
() =>
|
|
230
|
+
provider.handleCallback({
|
|
231
|
+
query: provenQuery({
|
|
232
|
+
"openid.claimed_id": `https://evil.example/?x=https://steamcommunity.com/openid/id/${STEAM_ID}`,
|
|
233
|
+
}),
|
|
234
|
+
redirectUri: RETURN_TO,
|
|
235
|
+
fetchImpl,
|
|
236
|
+
}),
|
|
237
|
+
(err: unknown) =>
|
|
238
|
+
err instanceof AccountLinkCallbackError &&
|
|
239
|
+
err.reason === "state_invalid",
|
|
240
|
+
);
|
|
241
|
+
assert.equal(calls.length, 0);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type AccountLinkProvider, steamOpenIdLink } from "@hogsend/core";
|
|
2
|
+
|
|
3
|
+
export interface SteamAccountLinkConfig {
|
|
4
|
+
/**
|
|
5
|
+
* Steam Web API key (`https://steamcommunity.com/dev/apikey`). OPTIONAL —
|
|
6
|
+
* it never gates the link itself. Absent: linking works and the identity is
|
|
7
|
+
* the bare 17-digit steamid64. Present: the best-effort
|
|
8
|
+
* `GetPlayerSummaries` pull fills `username`/`avatarUrl` and the
|
|
9
|
+
* `steam_playtime_2wk` property sync attaches.
|
|
10
|
+
*/
|
|
11
|
+
webApiKey?: string;
|
|
12
|
+
/** The `openid.realm` this deployment presents. `API_PUBLIC_URL`, trailing slash stripped. */
|
|
13
|
+
realm: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The Steam account-link provider: pure CONFIG over the `steamOpenIdLink()`
|
|
18
|
+
* preset. "Sign in through Steam" is OpenID 2.0 `checkid_setup`, so three
|
|
19
|
+
* things a reader will come looking for are structurally absent:
|
|
20
|
+
*
|
|
21
|
+
* - There is NO `code` and NO PKCE — OpenID 2.0 has neither, so PRD 07 skips
|
|
22
|
+
* its PKCE mint for this provider (`capabilities.pkce` absent).
|
|
23
|
+
* - There is NO token — OpenID 2.0 issues nothing to store, so
|
|
24
|
+
* `capabilities.tokens` is absent and PRD 03 writes a null
|
|
25
|
+
* `linked_accounts.tokens`.
|
|
26
|
+
* - The relying party presents NO credential: no app registration, no client
|
|
27
|
+
* id, no secret. The entire security model is the preset's server-side
|
|
28
|
+
* `check_authentication` round-trip against Steam's HARDCODED endpoint
|
|
29
|
+
* (`STEAM_OPENID_ENDPOINT`), never the callback-echoed `openid.op_endpoint`.
|
|
30
|
+
*
|
|
31
|
+
* All protocol mechanics — the `checkid_setup` URL, the round-trip, the strict
|
|
32
|
+
* `parseSteamClaimedId` anchor, the `return_to` echo check, the `mode=cancel`
|
|
33
|
+
* mapping, the playtime sync reader — live in the preset
|
|
34
|
+
* (`@hogsend/core`, `providers/account-link-presets.ts`), not here.
|
|
35
|
+
*/
|
|
36
|
+
export function steamAccountLink(
|
|
37
|
+
config: SteamAccountLinkConfig,
|
|
38
|
+
): AccountLinkProvider {
|
|
39
|
+
return steamOpenIdLink({
|
|
40
|
+
meta: {
|
|
41
|
+
id: "steam",
|
|
42
|
+
name: "Steam",
|
|
43
|
+
description: "Sign in through Steam (OpenID 2.0)",
|
|
44
|
+
},
|
|
45
|
+
realm: config.realm,
|
|
46
|
+
...(config.webApiKey ? { webApiKey: config.webApiKey } : {}),
|
|
47
|
+
});
|
|
48
|
+
}
|