@voltro/plugin-auth-social 0.89.2 → 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 +1943 -0
- package/README.md +4 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/accountMerge.js +149 -0
- package/dist/guestHandoff.js +12 -12
- package/dist/guestUpgrade.js +26 -26
- package/dist/identityStore.js +27 -18
- package/dist/index.d.ts +164 -5
- package/dist/index.js +18 -16
- package/dist/platformServices.js +80 -0
- package/dist/plugin.js +661 -392
- package/dist/providers.js +2 -2
- package/dist/signIn.js +16 -16
- package/dist/steam.js +49 -49
- package/dist/web/guestUpgradeClient.js +63 -38
- package/dist/web/linksClient.js +74 -0
- package/dist/web.d.ts +64 -4
- package/dist/web.js +3 -1
- package/package.json +6 -6
package/dist/providers.js
CHANGED
|
@@ -115,7 +115,7 @@ var t = {
|
|
|
115
115
|
a,
|
|
116
116
|
o,
|
|
117
117
|
s
|
|
118
|
-
], u = l.map((e) => e.id), d = (e) => Object.hasOwn(c, e), f = (t, n = {}) => {
|
|
118
|
+
], u = l.map((e) => e.id), d = (e) => Object.hasOwn(c, e), f = (e) => e === "steam" || d(e), p = (t, n = {}) => {
|
|
119
119
|
if (!d(t)) throw new e(`unknown social provider '${t}' — expected one of ${u.join(", ")}`);
|
|
120
120
|
return {
|
|
121
121
|
...c[t],
|
|
@@ -126,4 +126,4 @@ var t = {
|
|
|
126
126
|
...n.apiBase === void 0 ? {} : { apiBase: n.apiBase }
|
|
127
127
|
};
|
|
128
128
|
};
|
|
129
|
-
export { l as SOCIAL_PROVIDERS, u as SOCIAL_PROVIDER_IDS, d as isSocialProviderId, f as socialProvider };
|
|
129
|
+
export { l as SOCIAL_PROVIDERS, u as SOCIAL_PROVIDER_IDS, d as isSocialProviderId, f as isSocialWebProviderId, p as socialProvider };
|
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 };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isSocialWebProviderId as e } from "../providers.js";
|
|
2
2
|
import { parseGuestCredential as t } from "@voltro/plugin-auth/guest";
|
|
3
3
|
// src/web/guestUpgradeClient.ts
|
|
4
4
|
var n = class extends Error {
|
|
@@ -7,69 +7,75 @@ var n = class extends Error {
|
|
|
7
7
|
constructor(e, t) {
|
|
8
8
|
super("Guest upgrade: " + e), this.code = e, this.status = t, this.name = "GuestUpgradeClientError";
|
|
9
9
|
}
|
|
10
|
-
}, r =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
}, r = [
|
|
11
|
+
"account_merge_unavailable",
|
|
12
|
+
"merge_coverage_missing",
|
|
13
|
+
"merge_failed",
|
|
14
|
+
"merge_conflict",
|
|
15
|
+
"merge_request_reused"
|
|
16
|
+
], i = (e) => typeof e == "object" && e && !Array.isArray(e) ? e : null, a = (a) => {
|
|
17
|
+
let o = new URL(a.apiBaseUrl), s = a.prefix ?? "/auth/social";
|
|
18
|
+
if (!/^https?:$/.test(o.protocol) || o.username || o.password || o.search || o.hash || !/^\/[A-Za-z0-9/_-]+$/.test(s) || s.endsWith("/")) throw new n("invalid_response");
|
|
19
|
+
let c = a.apiBaseUrl.replace(/\/+$/, "") + s + "/upgrade", l = a.fetch ?? globalThis.fetch, u = async (e, t) => {
|
|
14
20
|
try {
|
|
15
|
-
let
|
|
21
|
+
let a = {};
|
|
16
22
|
if (t !== void 0) {
|
|
17
|
-
let e = await c
|
|
23
|
+
let e = await l(c + "/csrf", {
|
|
18
24
|
credentials: "include",
|
|
19
25
|
cache: "no-store",
|
|
20
26
|
redirect: "error"
|
|
21
27
|
});
|
|
22
28
|
if (!e.ok) throw new n("transport_failed", e.status);
|
|
23
|
-
let t =
|
|
29
|
+
let t = i(await e.json());
|
|
24
30
|
if (typeof t?.token != "string" || !t.token) throw new n("invalid_response");
|
|
25
|
-
|
|
31
|
+
a["x-csrf-token"] = t.token, a["content-type"] = "application/json";
|
|
26
32
|
}
|
|
27
|
-
let
|
|
33
|
+
let o = await l(c + e, {
|
|
28
34
|
credentials: "include",
|
|
29
35
|
cache: "no-store",
|
|
30
36
|
redirect: "error",
|
|
31
37
|
...t === void 0 ? {} : {
|
|
32
38
|
method: "POST",
|
|
33
|
-
headers:
|
|
39
|
+
headers: a,
|
|
34
40
|
body: JSON.stringify(t)
|
|
35
41
|
}
|
|
36
|
-
}),
|
|
37
|
-
if (!
|
|
38
|
-
let e =
|
|
39
|
-
throw new n(e === "account_merge_required" || e === "credential_rejected" || e === "upgrade_handoff_rejected" ? e : "transport_failed",
|
|
42
|
+
}), s = i(await o.json());
|
|
43
|
+
if (!o.ok) {
|
|
44
|
+
let e = s?.error;
|
|
45
|
+
throw new n(e === "account_merge_required" || e === "credential_rejected" || e === "upgrade_handoff_rejected" ? e : r.find((t) => t === e) ?? "transport_failed", o.status);
|
|
40
46
|
}
|
|
41
|
-
if (!
|
|
42
|
-
return
|
|
47
|
+
if (!s) throw new n("invalid_response");
|
|
48
|
+
return s;
|
|
43
49
|
} catch (e) {
|
|
44
50
|
throw e instanceof n ? e : new n("transport_failed");
|
|
45
51
|
}
|
|
46
|
-
},
|
|
52
|
+
}, d = async (e) => {
|
|
47
53
|
try {
|
|
48
54
|
return await e();
|
|
49
55
|
} catch (e) {
|
|
50
56
|
throw e instanceof n ? e : new n("storage_unavailable");
|
|
51
57
|
}
|
|
52
|
-
},
|
|
53
|
-
let e = await
|
|
58
|
+
}, f = async () => {
|
|
59
|
+
let e = await d(() => a.storage.read());
|
|
54
60
|
if (e === null || !t(e)) throw new n("credential_rejected");
|
|
55
61
|
return e;
|
|
56
|
-
},
|
|
57
|
-
let
|
|
58
|
-
if (e.upgraded !== !0 ||
|
|
62
|
+
}, p = (e, t) => {
|
|
63
|
+
let r = i(e.subject);
|
|
64
|
+
if (e.upgraded !== !0 || r?.type !== "user" || r.kind === "guest" || r.id !== t || typeof r.tenantId != "string" || !r.tenantId.trim()) throw new n("invalid_response");
|
|
59
65
|
return {
|
|
60
66
|
upgraded: !0,
|
|
61
67
|
subject: {
|
|
62
68
|
type: "user",
|
|
63
69
|
id: t,
|
|
64
|
-
tenantId:
|
|
70
|
+
tenantId: r.tenantId
|
|
65
71
|
}
|
|
66
72
|
};
|
|
67
73
|
};
|
|
68
74
|
return {
|
|
69
|
-
begin: (t) =>
|
|
75
|
+
begin: (t) => d(() => a.storage.exclusive(async () => {
|
|
70
76
|
if (!e(t)) throw new n("invalid_response");
|
|
71
|
-
await
|
|
72
|
-
let r = await
|
|
77
|
+
await f();
|
|
78
|
+
let r = await u("/" + t, {});
|
|
73
79
|
if (typeof r.authorizationUrl != "string") throw new n("invalid_response");
|
|
74
80
|
let i;
|
|
75
81
|
try {
|
|
@@ -81,28 +87,47 @@ var n = class extends Error {
|
|
|
81
87
|
return i.toString();
|
|
82
88
|
})),
|
|
83
89
|
pending: async () => {
|
|
84
|
-
let t = await
|
|
85
|
-
if (typeof t.guestId != "string" || !/^guest_[A-Za-z0-9_-]+$/.test(t.guestId) || typeof t.provider != "string" || !e(t.provider) || t.email !== null && typeof t.email != "string" || typeof t.emailVerified != "boolean" || typeof t.expiresAt != "number" || !Number.isSafeInteger(t.expiresAt) || t.expiresAt <= Date.now()) throw new n("invalid_response");
|
|
90
|
+
let t = await u("/pending");
|
|
91
|
+
if (typeof t.guestId != "string" || !/^guest_[A-Za-z0-9_-]+$/.test(t.guestId) || typeof t.provider != "string" || !e(t.provider) || t.email !== null && typeof t.email != "string" || typeof t.emailVerified != "boolean" || typeof t.expiresAt != "number" || !Number.isSafeInteger(t.expiresAt) || t.expiresAt <= Date.now() || t.conflict !== null && t.conflict !== void 0 && t.conflict !== "provider" && t.conflict !== "email") throw new n("invalid_response");
|
|
86
92
|
return {
|
|
87
93
|
guestId: t.guestId,
|
|
88
94
|
provider: t.provider,
|
|
89
95
|
email: t.email,
|
|
90
96
|
emailVerified: t.emailVerified,
|
|
91
|
-
expiresAt: t.expiresAt
|
|
97
|
+
expiresAt: t.expiresAt,
|
|
98
|
+
conflict: t.conflict ?? null
|
|
92
99
|
};
|
|
93
100
|
},
|
|
94
|
-
confirm: (e) =>
|
|
101
|
+
confirm: (e) => d(() => a.storage.exclusive(async () => {
|
|
95
102
|
if (e.confirmed !== !0) throw new n("credential_rejected");
|
|
96
|
-
let r = await
|
|
103
|
+
let r = await f(), i = t(r), o = await u("/complete", {
|
|
97
104
|
credential: r,
|
|
98
105
|
confirmed: !0
|
|
99
|
-
}), s =
|
|
100
|
-
return await
|
|
106
|
+
}), s = p(o, i.guestId);
|
|
107
|
+
return await d(() => a.storage.remove()), s;
|
|
101
108
|
})),
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
109
|
+
merge: (e) => d(() => a.storage.exclusive(async () => {
|
|
110
|
+
if (e.confirmed !== !0) throw new n("credential_rejected");
|
|
111
|
+
let r = await f(), o = t(r), s = ("merge_" + o.guestId.replace(/[^A-Za-z0-9_-]/g, "")).slice(0, 128), c = await u("/merge", {
|
|
112
|
+
credential: r,
|
|
113
|
+
confirmed: !0,
|
|
114
|
+
requestId: s
|
|
115
|
+
}), l = i(c.subject);
|
|
116
|
+
if (c.merged !== !0 || typeof c.replayed != "boolean" || l?.type !== "user" || l.kind === "guest" || typeof l.id != "string" || l.id === o.guestId || typeof l.tenantId != "string" || !l.tenantId.trim()) throw new n("invalid_response");
|
|
117
|
+
return await d(() => a.storage.remove()), {
|
|
118
|
+
merged: !0,
|
|
119
|
+
replayed: c.replayed,
|
|
120
|
+
subject: {
|
|
121
|
+
type: "user",
|
|
122
|
+
id: l.id,
|
|
123
|
+
tenantId: l.tenantId
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
})),
|
|
127
|
+
recover: () => d(() => a.storage.exclusive(async () => {
|
|
128
|
+
let e = await f(), n = p(await u("/receipt"), t(e).guestId);
|
|
129
|
+
return await d(() => a.storage.remove()), n;
|
|
105
130
|
}))
|
|
106
131
|
};
|
|
107
132
|
};
|
|
108
|
-
export { n as GuestUpgradeClientError,
|
|
133
|
+
export { n as GuestUpgradeClientError, a as createGuestUpgradeClient };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { isSocialWebProviderId as e } from "../providers.js";
|
|
2
|
+
// src/web/linksClient.ts
|
|
3
|
+
var t = class extends Error {
|
|
4
|
+
code;
|
|
5
|
+
status;
|
|
6
|
+
constructor(e, t) {
|
|
7
|
+
super("Social links: " + e), this.code = e, this.status = t, this.name = "SocialLinksClientError";
|
|
8
|
+
}
|
|
9
|
+
}, n = (e) => typeof e == "object" && e && !Array.isArray(e) ? e : null, r = [
|
|
10
|
+
"credential_rejected",
|
|
11
|
+
"last_sign_in_method",
|
|
12
|
+
"not_found",
|
|
13
|
+
"csrf_rejected"
|
|
14
|
+
], i = (i) => {
|
|
15
|
+
let a = new URL(i.apiBaseUrl), o = i.prefix ?? "/auth/social";
|
|
16
|
+
if (!/^https?:$/.test(a.protocol) || a.username || a.password || a.search || a.hash || !/^\/[A-Za-z0-9/_-]+$/.test(o) || o.endsWith("/")) throw new t("invalid_response");
|
|
17
|
+
let s = i.apiBaseUrl.replace(/\/+$/, "") + o, c = i.fetch ?? globalThis.fetch, l = async (e, i = !1) => {
|
|
18
|
+
let a;
|
|
19
|
+
try {
|
|
20
|
+
let r = {};
|
|
21
|
+
if (i) {
|
|
22
|
+
let e = await c(s + "/links/csrf", {
|
|
23
|
+
credentials: "include",
|
|
24
|
+
cache: "no-store",
|
|
25
|
+
redirect: "error"
|
|
26
|
+
}), i = n(await e.json().catch(() => null))?.token;
|
|
27
|
+
if (!e.ok || typeof i != "string") throw new t("transport_failed", e.status);
|
|
28
|
+
r["x-csrf-token"] = i, r["content-type"] = "application/json";
|
|
29
|
+
}
|
|
30
|
+
a = await c(s + e, {
|
|
31
|
+
method: i ? "POST" : "GET",
|
|
32
|
+
credentials: "include",
|
|
33
|
+
cache: "no-store",
|
|
34
|
+
redirect: "error",
|
|
35
|
+
headers: r,
|
|
36
|
+
...i ? { body: "{}" } : {}
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
throw e instanceof t ? e : new t("transport_failed");
|
|
40
|
+
}
|
|
41
|
+
let o = n(await a.json().catch(() => null));
|
|
42
|
+
if (!a.ok) throw new t(r.find((e) => e === o?.error) ?? "transport_failed", a.status);
|
|
43
|
+
if (!o) throw new t("invalid_response", a.status);
|
|
44
|
+
return o;
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
providers: async () => {
|
|
48
|
+
let n = (await l("/providers")).providers;
|
|
49
|
+
if (!Array.isArray(n)) throw new t("invalid_response");
|
|
50
|
+
return n.filter((t) => typeof t == "string" && e(t));
|
|
51
|
+
},
|
|
52
|
+
links: async () => {
|
|
53
|
+
let r = (await l("/links")).links;
|
|
54
|
+
if (!Array.isArray(r)) throw new t("invalid_response");
|
|
55
|
+
return r.flatMap((t) => {
|
|
56
|
+
let r = n(t);
|
|
57
|
+
return !r || typeof r.provider != "string" || !e(r.provider) || typeof r.connectedAt != "number" || r.lastUsedAt !== null && typeof r.lastUsedAt != "number" ? [] : [{
|
|
58
|
+
provider: r.provider,
|
|
59
|
+
connectedAt: r.connectedAt,
|
|
60
|
+
lastUsedAt: r.lastUsedAt
|
|
61
|
+
}];
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
connect: async (e) => {
|
|
65
|
+
let n = (await l("/links/" + e, !0)).authorizationUrl;
|
|
66
|
+
if (typeof n != "string" || !/^https?:\/\//.test(n)) throw new t("invalid_response");
|
|
67
|
+
return n;
|
|
68
|
+
},
|
|
69
|
+
disconnect: async (e) => {
|
|
70
|
+
await l("/links/" + e + "/remove", !0);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
export { t as SocialLinksClientError, i as createSocialLinksClient };
|
package/dist/web.d.ts
CHANGED
|
@@ -5,23 +5,57 @@ import { GuestCredentialStore } from '@voltro/plugin-auth/guest';
|
|
|
5
5
|
export declare const createGuestUpgradeClient: (options: GuestUpgradeClientOptions) => {
|
|
6
6
|
/** Call after an authenticated guest session exists, then navigate to the
|
|
7
7
|
* returned authorization URL in this browser. Does not send device proof. */
|
|
8
|
-
begin: (provider:
|
|
8
|
+
begin: (provider: SocialWebProviderId) => Promise<string>;
|
|
9
9
|
pending: () => Promise<GuestUpgradePending>;
|
|
10
10
|
/** Call only after explicit confirmation. Storage remains untouched on an
|
|
11
11
|
* uncertain/refused response; no replacement guest identity is created. */
|
|
12
12
|
confirm: (confirmation: {
|
|
13
13
|
readonly confirmed: true;
|
|
14
14
|
}) => Promise<GuestUpgradeCompletion>;
|
|
15
|
+
/** Call only after the player confirmed merging this guest into the account the provider
|
|
16
|
+
* opens (`pending().conflict === 'provider'`). The request ID derives from the guest, so a retry
|
|
17
|
+
* after a lost reply reaches the same receipt; the stored proof goes once the merge answers. */
|
|
18
|
+
merge: (confirmation: {
|
|
19
|
+
readonly confirmed: true;
|
|
20
|
+
}) => Promise<GuestMergeCompletion>;
|
|
15
21
|
/** After uncertain delivery, prove a live registered session for the exact
|
|
16
22
|
* stored guest ID. If its cookie was lost too, sign in with the linked
|
|
17
23
|
* provider first. Refusal never erases storage or creates another guest. */
|
|
18
24
|
recover: () => Promise<GuestUpgradeCompletion>;
|
|
19
25
|
};
|
|
20
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Account settings for social sign-in, over the session cookie: which providers this app offers,
|
|
29
|
+
* which the signed-in account is connected to, connecting another (navigate to the returned URL;
|
|
30
|
+
* the provider returns to `linkRedirect`) and disconnecting one. The server refuses to remove the
|
|
31
|
+
* account's last way to sign in (`last_sign_in_method`).
|
|
32
|
+
*/
|
|
33
|
+
export declare const createSocialLinksClient: (options: SocialLinksClientOptions) => {
|
|
34
|
+
/** The providers this app offers (configured on the server). */
|
|
35
|
+
providers: () => Promise<ReadonlyArray<SocialWebProviderId>>;
|
|
36
|
+
/** The signed-in account's connected providers. */
|
|
37
|
+
links: () => Promise<ReadonlyArray<SocialLink>>;
|
|
38
|
+
/** Start connecting a provider; navigate the browser to the returned URL. */
|
|
39
|
+
connect: (provider: SocialWebProviderId) => Promise<string>;
|
|
40
|
+
disconnect: (provider: SocialWebProviderId) => Promise<void>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export declare interface GuestMergeCompletion {
|
|
44
|
+
readonly merged: true;
|
|
45
|
+
readonly replayed: boolean;
|
|
46
|
+
readonly subject: {
|
|
47
|
+
readonly type: 'user';
|
|
48
|
+
readonly id: string;
|
|
49
|
+
readonly tenantId: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export declare type GuestMergeRefusal = typeof MERGE_REFUSALS[number];
|
|
54
|
+
|
|
21
55
|
export declare class GuestUpgradeClientError extends Error {
|
|
22
|
-
readonly code: 'storage_unavailable' | 'credential_rejected' | 'account_merge_required' | 'transport_failed' | 'invalid_response' | 'upgrade_handoff_rejected';
|
|
56
|
+
readonly code: 'storage_unavailable' | 'credential_rejected' | 'account_merge_required' | 'transport_failed' | 'invalid_response' | 'upgrade_handoff_rejected' | GuestMergeRefusal;
|
|
23
57
|
readonly status?: number | undefined;
|
|
24
|
-
constructor(code: 'storage_unavailable' | 'credential_rejected' | 'account_merge_required' | 'transport_failed' | 'invalid_response' | 'upgrade_handoff_rejected', status?: number | undefined);
|
|
58
|
+
constructor(code: 'storage_unavailable' | 'credential_rejected' | 'account_merge_required' | 'transport_failed' | 'invalid_response' | 'upgrade_handoff_rejected' | GuestMergeRefusal, status?: number | undefined);
|
|
25
59
|
}
|
|
26
60
|
|
|
27
61
|
export declare interface GuestUpgradeClientOptions {
|
|
@@ -42,13 +76,39 @@ export declare interface GuestUpgradeCompletion {
|
|
|
42
76
|
|
|
43
77
|
export declare interface GuestUpgradePending {
|
|
44
78
|
readonly guestId: string;
|
|
45
|
-
readonly provider:
|
|
79
|
+
readonly provider: SocialWebProviderId;
|
|
46
80
|
readonly email: string | null;
|
|
47
81
|
readonly emailVerified: boolean;
|
|
48
82
|
readonly expiresAt: number;
|
|
83
|
+
/** Completing would conflict: `provider` — that provider account opens another account, which
|
|
84
|
+
* `merge` can merge this guest into; `email` — only the address matches, which cannot merge. */
|
|
85
|
+
readonly conflict: 'provider' | 'email' | null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
declare const MERGE_REFUSALS: readonly ["account_merge_unavailable", "merge_coverage_missing", "merge_failed", "merge_conflict", "merge_request_reused"];
|
|
89
|
+
|
|
90
|
+
export declare interface SocialLink {
|
|
91
|
+
readonly provider: SocialWebProviderId;
|
|
92
|
+
readonly connectedAt: number;
|
|
93
|
+
readonly lastUsedAt: number | null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export declare class SocialLinksClientError extends Error {
|
|
97
|
+
readonly code: 'credential_rejected' | 'last_sign_in_method' | 'not_found' | 'csrf_rejected' | 'transport_failed' | 'invalid_response';
|
|
98
|
+
readonly status?: number | undefined;
|
|
99
|
+
constructor(code: 'credential_rejected' | 'last_sign_in_method' | 'not_found' | 'csrf_rejected' | 'transport_failed' | 'invalid_response', status?: number | undefined);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export declare interface SocialLinksClientOptions {
|
|
103
|
+
readonly apiBaseUrl: string;
|
|
104
|
+
readonly prefix?: string;
|
|
105
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
49
106
|
}
|
|
50
107
|
|
|
51
108
|
/** The providers this package ships. */
|
|
52
109
|
declare type SocialProviderId = 'google' | 'github' | 'apple' | 'discord' | 'twitch' | 'microsoft' | 'epic';
|
|
53
110
|
|
|
111
|
+
/** A provider a browser can sign in with: the OAuth providers plus Steam (OpenID 2.0, `steam` in `socialAuthPlugin`). */
|
|
112
|
+
declare type SocialWebProviderId = SocialProviderId | 'steam';
|
|
113
|
+
|
|
54
114
|
export { }
|
package/dist/web.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { GuestUpgradeClientError as e, createGuestUpgradeClient as t } from "./web/guestUpgradeClient.js";
|
|
2
|
+
import { SocialLinksClientError as n, createSocialLinksClient as r } from "./web/linksClient.js";
|
|
3
|
+
export { e as GuestUpgradeClientError, n as SocialLinksClientError, t as createGuestUpgradeClient, r as createSocialLinksClient };
|
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"
|