@voltro/plugin-auth-social 0.90.0 → 0.91.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/CHANGELOG.md +121 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/guestHandoff.js +12 -12
- package/dist/index.js +16 -16
- package/dist/plugin.js +519 -519
- package/dist/signIn.js +16 -16
- package/dist/steam.js +49 -49
- package/package.json +6 -6
package/dist/signIn.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { decideSocialLink as e } from "./linking.js";
|
|
2
|
+
import { SocialAccountLinkError as t } from "./errors.js";
|
|
3
3
|
import { Effect as n } from "effect";
|
|
4
4
|
import { issueUserSession as r, newAuthId as i, runSubjectGuards as a } from "@voltro/plugin-auth";
|
|
5
5
|
// src/signIn.ts
|
|
@@ -9,7 +9,7 @@ var o = (e) => ({
|
|
|
9
9
|
code: e.code,
|
|
10
10
|
message: e.message
|
|
11
11
|
}), s = (s) => n.gen(function* () {
|
|
12
|
-
let { profile: c, identities: l, users: u, config: d } = s, f = s.policy ?? "never", p = yield* l.findByProviderAccount(c.provider, c.providerAccountId), m = c.email === null ? null : yield* u.findByEmail(c.email), h =
|
|
12
|
+
let { profile: c, identities: l, users: u, config: d } = s, f = s.policy ?? "never", p = yield* l.findByProviderAccount(c.provider, c.providerAccountId), m = c.email === null ? null : yield* u.findByEmail(c.email), h = e({
|
|
13
13
|
profile: c,
|
|
14
14
|
linkedUserId: p?.userId ?? null,
|
|
15
15
|
existingUserIdByEmail: m?.id ?? null,
|
|
@@ -18,24 +18,24 @@ var o = (e) => ({
|
|
|
18
18
|
if (h.kind === "refuse") return o(h.error);
|
|
19
19
|
let g = null, _ = !1, v = !1;
|
|
20
20
|
if (h.kind === "create-user") {
|
|
21
|
-
let
|
|
21
|
+
let e = c.email, r = yield* u.insert({
|
|
22
22
|
id: i("user"),
|
|
23
|
-
email:
|
|
23
|
+
email: e,
|
|
24
24
|
passwordHash: null,
|
|
25
25
|
tenantId: d.defaultTenantId
|
|
26
|
-
}).pipe(n.catchTag("UserAlreadyExistsError", (
|
|
27
|
-
if (r instanceof
|
|
26
|
+
}).pipe(n.catchTag("UserAlreadyExistsError", (e) => n.succeed(new t("account_exists_unlinked", `An account already exists for ${e.email}. Sign in with your existing method, then connect ${c.provider} from your account settings.`))));
|
|
27
|
+
if (r instanceof t) return o(r);
|
|
28
28
|
g = r, _ = !0;
|
|
29
29
|
} else {
|
|
30
|
-
if (v = h.kind === "link", g = yield* u.findById(h.userId), !g) return o(new
|
|
31
|
-
let
|
|
32
|
-
if (
|
|
33
|
-
let
|
|
34
|
-
if (!
|
|
30
|
+
if (v = h.kind === "link", g = yield* u.findById(h.userId), !g) return o(new t("account_exists_unlinked", "The account this login is linked to no longer exists.", 409));
|
|
31
|
+
let e = d.subjectGuards ?? [];
|
|
32
|
+
if (e.length > 0) {
|
|
33
|
+
let t = yield* a(e, g);
|
|
34
|
+
if (!t.ok) return {
|
|
35
35
|
kind: "refused",
|
|
36
36
|
status: 403,
|
|
37
|
-
code:
|
|
38
|
-
message:
|
|
37
|
+
code: t.code,
|
|
38
|
+
message: t.message
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -47,8 +47,8 @@ var o = (e) => ({
|
|
|
47
47
|
email: c.email,
|
|
48
48
|
emailVerified: c.emailVerified
|
|
49
49
|
}).pipe(n.as(!0), n.catchTag("SocialIdentityConflict", () => n.succeed(!1))))) {
|
|
50
|
-
let
|
|
51
|
-
if (n === null) return o(new
|
|
50
|
+
let e = yield* l.findByProviderAccount(c.provider, c.providerAccountId), n = e === null ? null : yield* u.findById(e.userId);
|
|
51
|
+
if (n === null) return o(new t("account_exists_unlinked", "The account this login is linked to no longer exists.", 409));
|
|
52
52
|
let r = yield* a(d.subjectGuards ?? [], n);
|
|
53
53
|
if (!r.ok) return {
|
|
54
54
|
kind: "refused",
|
package/dist/steam.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { PlatformTicketError as e, SocialAuthError as t, SocialConfigError as n, SocialExchangeError as r, SocialStateMismatchError as i } from "./errors.js";
|
|
2
|
+
import { randomToken as a } from "./pkce.js";
|
|
3
3
|
import { Effect as o } from "effect";
|
|
4
4
|
import { timingSafeStringEqual as s } from "@voltro/protocol/session";
|
|
5
5
|
import { createHash as c } from "node:crypto";
|
|
@@ -32,45 +32,45 @@ var l = "http://specs.openid.net/auth/2.0", u = "https://steamcommunity.com/open
|
|
|
32
32
|
try {
|
|
33
33
|
t = new URL(e);
|
|
34
34
|
} catch {
|
|
35
|
-
throw new
|
|
35
|
+
throw new n("steam: invalid absolute callback URL");
|
|
36
36
|
}
|
|
37
|
-
if (!["https:", "http:"].includes(t.protocol) || t.username || t.password || t.hash) throw new
|
|
37
|
+
if (!["https:", "http:"].includes(t.protocol) || t.username || t.password || t.hash) throw new n("steam: callback URL requires HTTP(S), without credentials or fragments");
|
|
38
38
|
return t;
|
|
39
|
-
}, v = (
|
|
40
|
-
let
|
|
41
|
-
if (
|
|
42
|
-
let
|
|
43
|
-
if (
|
|
44
|
-
let
|
|
45
|
-
return
|
|
39
|
+
}, v = (e) => {
|
|
40
|
+
let t = _(e.returnTo);
|
|
41
|
+
if (t.searchParams.has("state")) throw new n("steam: state must be server minted");
|
|
42
|
+
let r = _(e.realm ?? `${t.origin}/`);
|
|
43
|
+
if (r.search || r.origin !== t.origin || !(t.pathname === r.pathname || t.pathname.startsWith(r.pathname.endsWith("/") ? r.pathname : `${r.pathname}/`))) throw new n("steam: callback is outside the configured realm");
|
|
44
|
+
let i = a();
|
|
45
|
+
return t.searchParams.set("state", i), {
|
|
46
46
|
url: `${u}?${new URLSearchParams({
|
|
47
47
|
"openid.ns": l,
|
|
48
48
|
"openid.mode": "checkid_setup",
|
|
49
|
-
"openid.return_to":
|
|
50
|
-
"openid.realm":
|
|
49
|
+
"openid.return_to": t.href,
|
|
50
|
+
"openid.realm": r.href,
|
|
51
51
|
"openid.identity": d,
|
|
52
52
|
"openid.claimed_id": d
|
|
53
53
|
})}`,
|
|
54
|
-
state:
|
|
55
|
-
returnTo:
|
|
56
|
-
realm:
|
|
54
|
+
state: i,
|
|
55
|
+
returnTo: t.href,
|
|
56
|
+
realm: r.href
|
|
57
57
|
};
|
|
58
58
|
}, y = (e) => o.gen(function* () {
|
|
59
|
-
let
|
|
59
|
+
let a = yield* o.tryPromise({
|
|
60
60
|
try: async () => {
|
|
61
|
-
let t = e.maxNonceAgeMs ?? 3e5,
|
|
62
|
-
if (!e.namespace || !Number.isSafeInteger(t) || t < 1 || t > 36e5 || !Number.isSafeInteger(
|
|
63
|
-
if (e.callbackUrl.length > 16384) throw new
|
|
61
|
+
let t = e.maxNonceAgeMs ?? 3e5, a = e.clockSkewMs ?? 3e4;
|
|
62
|
+
if (!e.namespace || !Number.isSafeInteger(t) || t < 1 || t > 36e5 || !Number.isSafeInteger(a) || a < 0 || a > 3e5 || e.multiNode === !0 && !e.hotStore.capabilities.crossNode) throw new n("steam: invalid replay owner, lifetime or multi-node hot store");
|
|
63
|
+
if (e.callbackUrl.length > 16384) throw new i("steam: callback exceeds the admission budget");
|
|
64
64
|
let o = _(e.callbackUrl), c = _(e.expectedReturnTo), d = o.searchParams, p = /* @__PURE__ */ new Set();
|
|
65
65
|
for (let e of d.keys()) {
|
|
66
|
-
if (p.has(e)) throw new
|
|
66
|
+
if (p.has(e)) throw new i("steam: duplicate callback parameter");
|
|
67
67
|
p.add(e);
|
|
68
68
|
}
|
|
69
|
-
if (!e.expectedState || d.get("state") === null || !s(d.get("state"), e.expectedState) || c.searchParams.get("state") !== e.expectedState || o.origin !== c.origin || o.pathname !== c.pathname) throw new
|
|
70
|
-
for (let [e, t] of c.searchParams) if (d.get(e) !== t) throw new
|
|
71
|
-
if (d.get("openid.ns") !== l || d.get("openid.mode") !== "id_res" || d.get("openid.op_endpoint") !== u || d.get("openid.return_to") !== e.expectedReturnTo) throw new
|
|
69
|
+
if (!e.expectedState || d.get("state") === null || !s(d.get("state"), e.expectedState) || c.searchParams.get("state") !== e.expectedState || o.origin !== c.origin || o.pathname !== c.pathname) throw new i("steam: state or callback location mismatch");
|
|
70
|
+
for (let [e, t] of c.searchParams) if (d.get(e) !== t) throw new i("steam: callback query binding mismatch");
|
|
71
|
+
if (d.get("openid.ns") !== l || d.get("openid.mode") !== "id_res" || d.get("openid.op_endpoint") !== u || d.get("openid.return_to") !== e.expectedReturnTo) throw new i("steam: invalid OpenID provider or return binding");
|
|
72
72
|
let g = d.get("openid.claimed_id") ?? "", v = /^https?:\/\/steamcommunity\.com\/openid\/id\/([0-9]{17,20})$/.exec(g);
|
|
73
|
-
if (!v || !f(v[1]) || d.get("openid.identity") !== g) throw new
|
|
73
|
+
if (!v || !f(v[1]) || d.get("openid.identity") !== g) throw new i("steam: invalid Steam claimed identity");
|
|
74
74
|
let y = new Set((d.get("openid.signed") ?? "").split(","));
|
|
75
75
|
if ([
|
|
76
76
|
"op_endpoint",
|
|
@@ -79,11 +79,11 @@ var l = "http://specs.openid.net/auth/2.0", u = "https://steamcommunity.com/open
|
|
|
79
79
|
"assoc_handle",
|
|
80
80
|
"claimed_id",
|
|
81
81
|
"identity"
|
|
82
|
-
].some((e) => !y.has(e)) || !d.get("openid.assoc_handle") || !d.get("openid.sig")) throw new
|
|
82
|
+
].some((e) => !y.has(e)) || !d.get("openid.assoc_handle") || !d.get("openid.sig")) throw new i("steam: assertion is missing required signed fields");
|
|
83
83
|
let b = d.get("openid.response_nonce") ?? "";
|
|
84
|
-
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z.+$/.test(b) || b.length > 255) throw new
|
|
84
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z.+$/.test(b) || b.length > 255) throw new i("steam: malformed response nonce");
|
|
85
85
|
let x = Date.parse(b.slice(0, 20)), S = (e.now ?? Date.now)();
|
|
86
|
-
if (!Number.isFinite(S) || !Number.isFinite(x) || new Date(x).toISOString().replace(".000Z", "Z") !== b.slice(0, 20) || x > S +
|
|
86
|
+
if (!Number.isFinite(S) || !Number.isFinite(x) || new Date(x).toISOString().replace(".000Z", "Z") !== b.slice(0, 20) || x > S + a || x < S - t) throw new i("steam: response nonce outside the admission lifetime");
|
|
87
87
|
let C = new URLSearchParams();
|
|
88
88
|
for (let [e, t] of d) e.startsWith("openid.") && C.set(e, t);
|
|
89
89
|
C.set("openid.mode", "check_authentication");
|
|
@@ -97,55 +97,55 @@ var l = "http://specs.openid.net/auth/2.0", u = "https://steamcommunity.com/open
|
|
|
97
97
|
signal: AbortSignal.timeout(e.timeoutMs ?? m)
|
|
98
98
|
});
|
|
99
99
|
} catch {
|
|
100
|
-
throw new
|
|
100
|
+
throw new r("exchange_failed", "steam: OpenID verification request failed");
|
|
101
101
|
}
|
|
102
|
-
if (!w.ok) throw new
|
|
102
|
+
if (!w.ok) throw new r("exchange_failed", "steam: OpenID verification refused");
|
|
103
103
|
let T = await h(w).catch(() => null);
|
|
104
|
-
if (T === null || T.length > 8192) throw new
|
|
104
|
+
if (T === null || T.length > 8192) throw new r("exchange_failed", "steam: malformed OpenID verification response");
|
|
105
105
|
let E = /* @__PURE__ */ new Map();
|
|
106
106
|
for (let e of T.split("\n")) {
|
|
107
107
|
if (!e) continue;
|
|
108
108
|
let t = e.indexOf(":"), n = e.slice(0, t);
|
|
109
|
-
if (t < 1 || E.has(n)) throw new
|
|
109
|
+
if (t < 1 || E.has(n)) throw new r("exchange_failed", "steam: malformed OpenID verification response");
|
|
110
110
|
E.set(n, e.slice(t + 1).replace(/\r$/, ""));
|
|
111
111
|
}
|
|
112
|
-
if (E.get("ns") !== l || E.get("is_valid") !== "true") throw new
|
|
112
|
+
if (E.get("ns") !== l || E.get("is_valid") !== "true") throw new r("exchange_failed", "steam: OpenID assertion was not verified");
|
|
113
113
|
return {
|
|
114
114
|
value: b,
|
|
115
115
|
accountId: v[1],
|
|
116
|
-
ttlMs: t +
|
|
116
|
+
ttlMs: t + a
|
|
117
117
|
};
|
|
118
118
|
},
|
|
119
|
-
catch: (e) => e instanceof
|
|
120
|
-
}), d = `${e.namespace}:steam:nonce:${c("sha256").update(JSON.stringify([u,
|
|
121
|
-
return (yield* e.hotStore.setNx(d, "consumed",
|
|
122
|
-
}), b = async (
|
|
123
|
-
if (!Number.isSafeInteger(
|
|
124
|
-
if (!/^(?:[a-fA-F0-9]{2})+$/.test(
|
|
125
|
-
let a = new URL(
|
|
126
|
-
a.searchParams.set("key",
|
|
119
|
+
catch: (e) => e instanceof t ? e : new r("exchange_failed", "steam: OpenID verification failed")
|
|
120
|
+
}), d = `${e.namespace}:steam:nonce:${c("sha256").update(JSON.stringify([u, a.value])).digest("hex")}`;
|
|
121
|
+
return (yield* e.hotStore.setNx(d, "consumed", a.ttlMs).pipe(o.catch(() => o.fail(new r("exchange_failed", "steam: replay admission unavailable"))), o.catchDefect(() => o.fail(new r("exchange_failed", "steam: replay admission unavailable"))))) ? g(a.accountId) : yield* o.fail(new i("steam: assertion already consumed"));
|
|
122
|
+
}), b = async (i) => {
|
|
123
|
+
if (!Number.isSafeInteger(i.appId) || i.appId < 1 || i.appId > 4294967295 || !i.identity || i.identity.length > 255 || !i.publisherKey) throw new n("steam: appId, ticket identity and publisher key are required");
|
|
124
|
+
if (!/^(?:[a-fA-F0-9]{2})+$/.test(i.ticket) || i.ticket.length > 16384) throw new e("steam: malformed Web API ticket");
|
|
125
|
+
let a = new URL(i.verificationUrl ?? "https://partner.steam-api.com/ISteamUserAuth/AuthenticateUserTicket/v1/");
|
|
126
|
+
a.searchParams.set("key", i.publisherKey), a.searchParams.set("appid", String(i.appId)), a.searchParams.set("ticket", i.ticket), a.searchParams.set("identity", i.identity);
|
|
127
127
|
let o;
|
|
128
128
|
try {
|
|
129
|
-
o = await (
|
|
129
|
+
o = await (i.fetchImpl ?? fetch)(a.href, {
|
|
130
130
|
redirect: "error",
|
|
131
131
|
headers: { accept: "application/json" },
|
|
132
|
-
signal: AbortSignal.timeout(
|
|
132
|
+
signal: AbortSignal.timeout(i.timeoutMs ?? m)
|
|
133
133
|
});
|
|
134
134
|
} catch {
|
|
135
|
-
throw new
|
|
135
|
+
throw new r("exchange_failed", "steam: ticket verification request failed");
|
|
136
136
|
}
|
|
137
|
-
if (!o.ok) throw new
|
|
137
|
+
if (!o.ok) throw new r("exchange_failed", "steam: ticket verification refused");
|
|
138
138
|
let s;
|
|
139
139
|
try {
|
|
140
140
|
let e = await h(o);
|
|
141
141
|
if (e === null) throw Error("oversized");
|
|
142
142
|
s = JSON.parse(e);
|
|
143
143
|
} catch {
|
|
144
|
-
throw new
|
|
144
|
+
throw new r("malformed_token_response", "steam: malformed ticket verification response");
|
|
145
145
|
}
|
|
146
146
|
let c = typeof s == "object" && s ? s : {}, l = typeof c.response == "object" && c.response !== null ? c.response : {}, u = typeof l.params == "object" && l.params !== null ? l.params : {};
|
|
147
|
-
if (u.result !== "OK" || !f(u.steamid)) throw new
|
|
148
|
-
if (u.publisherbanned === !0 &&
|
|
147
|
+
if (u.result !== "OK" || !f(u.steamid)) throw new e("steam: invalid Web API ticket");
|
|
148
|
+
if (u.publisherbanned === !0 && i.allowPublisherBanned !== !0) throw new t(403, "guard_rejected", "steam: the publisher banned this account");
|
|
149
149
|
return g(u.steamid);
|
|
150
150
|
};
|
|
151
151
|
export { v as steamBeginOpenId, y as steamCompleteOpenId, b as verifySteamWebApiTicket };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/plugin-auth-social",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.91.0",
|
|
4
4
|
"description": "First-party social login with state, S256, provider identity verification, explicit account linking and shared Auth sessions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"node": ">=24.0.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@voltro/database": "0.
|
|
42
|
-
"@voltro/plugin-auth": "0.
|
|
43
|
-
"@voltro/protocol": "0.
|
|
44
|
-
"@voltro/kv": "0.
|
|
41
|
+
"@voltro/database": "0.91.0",
|
|
42
|
+
"@voltro/plugin-auth": "0.91.0",
|
|
43
|
+
"@voltro/protocol": "0.91.0",
|
|
44
|
+
"@voltro/kv": "0.91.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"effect": "4.1.
|
|
47
|
+
"effect": "4.1.4"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|