@voltro/plugin-auth-social 0.90.0 → 0.91.1

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/dist/signIn.js CHANGED
@@ -1,5 +1,5 @@
1
- import { SocialAccountLinkError as e } from "./errors.js";
2
- import { decideSocialLink as t } from "./linking.js";
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 = t({
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 t = c.email, r = yield* u.insert({
21
+ let e = c.email, r = yield* u.insert({
22
22
  id: i("user"),
23
- email: t,
23
+ email: e,
24
24
  passwordHash: null,
25
25
  tenantId: d.defaultTenantId
26
- }).pipe(n.catchTag("UserAlreadyExistsError", (t) => n.succeed(new e("account_exists_unlinked", `An account already exists for ${t.email}. Sign in with your existing method, then connect ${c.provider} from your account settings.`))));
27
- if (r instanceof e) return o(r);
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 e("account_exists_unlinked", "The account this login is linked to no longer exists.", 409));
31
- let t = d.subjectGuards ?? [];
32
- if (t.length > 0) {
33
- let e = yield* a(t, g);
34
- if (!e.ok) return {
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: e.code,
38
- message: e.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 t = yield* l.findByProviderAccount(c.provider, c.providerAccountId), n = t === null ? null : yield* u.findById(t.userId);
51
- if (n === null) return o(new e("account_exists_unlinked", "The account this login is linked to no longer exists.", 409));
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 { randomToken as e } from "./pkce.js";
2
- import { PlatformTicketError as t, SocialAuthError as n, SocialConfigError as r, SocialExchangeError as i, SocialStateMismatchError as a } from "./errors.js";
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 r("steam: invalid absolute callback URL");
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 r("steam: callback URL requires HTTP(S), without credentials or fragments");
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 = (t) => {
40
- let n = _(t.returnTo);
41
- if (n.searchParams.has("state")) throw new r("steam: state must be server minted");
42
- let i = _(t.realm ?? `${n.origin}/`);
43
- if (i.search || i.origin !== n.origin || !(n.pathname === i.pathname || n.pathname.startsWith(i.pathname.endsWith("/") ? i.pathname : `${i.pathname}/`))) throw new r("steam: callback is outside the configured realm");
44
- let a = e();
45
- return n.searchParams.set("state", a), {
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": n.href,
50
- "openid.realm": i.href,
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: a,
55
- returnTo: n.href,
56
- realm: i.href
54
+ state: i,
55
+ returnTo: t.href,
56
+ realm: r.href
57
57
  };
58
58
  }, y = (e) => o.gen(function* () {
59
- let t = yield* o.tryPromise({
59
+ let a = yield* o.tryPromise({
60
60
  try: async () => {
61
- let t = e.maxNonceAgeMs ?? 3e5, n = e.clockSkewMs ?? 3e4;
62
- if (!e.namespace || !Number.isSafeInteger(t) || t < 1 || t > 36e5 || !Number.isSafeInteger(n) || n < 0 || n > 3e5 || e.multiNode === !0 && !e.hotStore.capabilities.crossNode) throw new r("steam: invalid replay owner, lifetime or multi-node hot store");
63
- if (e.callbackUrl.length > 16384) throw new a("steam: callback exceeds the admission budget");
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 a("steam: duplicate callback parameter");
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 a("steam: state or callback location mismatch");
70
- for (let [e, t] of c.searchParams) if (d.get(e) !== t) throw new a("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 a("steam: invalid OpenID provider or return binding");
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 a("steam: invalid Steam claimed identity");
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 a("steam: assertion is missing required signed fields");
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 a("steam: malformed 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 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 + n || x < S - t) throw new a("steam: response nonce outside the admission lifetime");
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 i("exchange_failed", "steam: OpenID verification request failed");
100
+ throw new r("exchange_failed", "steam: OpenID verification request failed");
101
101
  }
102
- if (!w.ok) throw new i("exchange_failed", "steam: OpenID verification refused");
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 i("exchange_failed", "steam: malformed OpenID verification response");
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 i("exchange_failed", "steam: malformed OpenID verification response");
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 i("exchange_failed", "steam: OpenID assertion was not verified");
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 + n
116
+ ttlMs: t + a
117
117
  };
118
118
  },
119
- catch: (e) => e instanceof n ? e : new i("exchange_failed", "steam: OpenID verification failed")
120
- }), d = `${e.namespace}:steam:nonce:${c("sha256").update(JSON.stringify([u, t.value])).digest("hex")}`;
121
- return (yield* e.hotStore.setNx(d, "consumed", t.ttlMs).pipe(o.catch(() => o.fail(new i("exchange_failed", "steam: replay admission unavailable"))), o.catchDefect(() => o.fail(new i("exchange_failed", "steam: replay admission unavailable"))))) ? g(t.accountId) : yield* o.fail(new a("steam: assertion already consumed"));
122
- }), b = async (e) => {
123
- if (!Number.isSafeInteger(e.appId) || e.appId < 1 || e.appId > 4294967295 || !e.identity || e.identity.length > 255 || !e.publisherKey) throw new r("steam: appId, ticket identity and publisher key are required");
124
- if (!/^(?:[a-fA-F0-9]{2})+$/.test(e.ticket) || e.ticket.length > 16384) throw new t("steam: malformed Web API ticket");
125
- let a = new URL(e.verificationUrl ?? "https://partner.steam-api.com/ISteamUserAuth/AuthenticateUserTicket/v1/");
126
- a.searchParams.set("key", e.publisherKey), a.searchParams.set("appid", String(e.appId)), a.searchParams.set("ticket", e.ticket), a.searchParams.set("identity", e.identity);
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 (e.fetchImpl ?? fetch)(a.href, {
129
+ o = await (i.fetchImpl ?? fetch)(a.href, {
130
130
  redirect: "error",
131
131
  headers: { accept: "application/json" },
132
- signal: AbortSignal.timeout(e.timeoutMs ?? m)
132
+ signal: AbortSignal.timeout(i.timeoutMs ?? m)
133
133
  });
134
134
  } catch {
135
- throw new i("exchange_failed", "steam: ticket verification request failed");
135
+ throw new r("exchange_failed", "steam: ticket verification request failed");
136
136
  }
137
- if (!o.ok) throw new i("exchange_failed", "steam: ticket verification refused");
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 i("malformed_token_response", "steam: malformed ticket verification response");
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 t("steam: invalid Web API ticket");
148
- if (u.publisherbanned === !0 && e.allowPublisherBanned !== !0) throw new n(403, "guard_rejected", "steam: the publisher banned this account");
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.90.0",
3
+ "version": "0.91.1",
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.90.0",
42
- "@voltro/plugin-auth": "0.90.0",
43
- "@voltro/protocol": "0.90.0",
44
- "@voltro/kv": "0.90.0"
41
+ "@voltro/database": "0.91.1",
42
+ "@voltro/plugin-auth": "0.91.1",
43
+ "@voltro/protocol": "0.91.1",
44
+ "@voltro/kv": "0.91.1"
45
45
  },
46
46
  "peerDependencies": {
47
- "effect": "4.1.2"
47
+ "effect": "4.1.4"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"