@voltro/plugin-auth-social 0.86.0 → 0.88.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.
@@ -0,0 +1,114 @@
1
+ import { PlatformTicketError as e, SocialAuthError as t, SocialConfigError as n, SocialExchangeError as r } from "./errors.js";
2
+ import { isSocialProviderId as i } from "./providers.js";
3
+ import { verifySteamWebApiTicket as a } from "./steam.js";
4
+ import { JwtVerifyError as o, verifyJwt as s } from "@voltro/protocol/jwt";
5
+ // src/platform.ts
6
+ var c = /^[a-z][a-z0-9-]{1,31}$/, l = /^[\x21-\x7e]{1,255}$/, u = (e) => {
7
+ if (!c.test(e.id) || i(e.id)) throw new n("definePlatformLogin: id must be 2–32 lowercase letters, digits or hyphens and not a social provider id");
8
+ let t = e.verify;
9
+ return {
10
+ id: e.id,
11
+ declaredEnv: e.declaredEnv ?? [],
12
+ permissions: e.permissions ?? [],
13
+ check: e.check ?? (() => void 0),
14
+ verify: async (n) => {
15
+ let i = await t(n);
16
+ if (typeof i?.accountId != "string" || !l.test(i.accountId)) throw new r("malformed_token_response", `${e.id}: the verifier returned no usable account id`, 503);
17
+ return { accountId: i.accountId };
18
+ }
19
+ };
20
+ }, d = (e = {}) => {
21
+ let t = e.identity ?? "voltro";
22
+ if (!t || t.length > 255) throw new n("steamPlatformLogin: identity must be 1–255 characters");
23
+ let r = () => {
24
+ let t = e.appId ?? Number(process.env.VOLTRO_STEAM_APP_ID ?? ""), r = e.publisherKey ?? process.env.VOLTRO_STEAM_PUBLISHER_KEY ?? "";
25
+ if (!Number.isSafeInteger(t) || t < 1 || t > 4294967295) throw new n("steamPlatformLogin: no app id — pass `appId` or set VOLTRO_STEAM_APP_ID");
26
+ if (!r) throw new n("steamPlatformLogin: no publisher key — pass `publisherKey` or set VOLTRO_STEAM_PUBLISHER_KEY");
27
+ return {
28
+ appId: t,
29
+ publisherKey: r
30
+ };
31
+ };
32
+ return {
33
+ id: "steam",
34
+ declaredEnv: [{
35
+ name: "VOLTRO_STEAM_APP_ID",
36
+ required: e.appId === void 0,
37
+ secret: !1,
38
+ description: "Steam App ID the game runs as."
39
+ }, {
40
+ name: "VOLTRO_STEAM_PUBLISHER_KEY",
41
+ required: e.publisherKey === void 0,
42
+ secret: !0,
43
+ description: "Steamworks Web API publisher key; verifies game tickets on the server."
44
+ }],
45
+ permissions: ["network:outbound:partner.steam-api.com"],
46
+ check: () => {
47
+ r();
48
+ },
49
+ verify: async (n) => {
50
+ let { appId: i, publisherKey: o } = r();
51
+ return { accountId: (await a({
52
+ ticket: n,
53
+ appId: i,
54
+ identity: t,
55
+ publisherKey: o,
56
+ ...e.timeoutMs === void 0 ? {} : { timeoutMs: e.timeoutMs },
57
+ ...e.allowPublisherBanned === void 0 ? {} : { allowPublisherBanned: e.allowPublisherBanned },
58
+ ...e.verificationUrl === void 0 ? {} : { verificationUrl: e.verificationUrl },
59
+ ...e.fetchImpl === void 0 ? {} : { fetchImpl: e.fetchImpl }
60
+ })).providerAccountId };
61
+ }
62
+ };
63
+ }, f = "https://api.epicgames.dev/auth/v1/oauth/jwks", p = "https://api.epicgames.dev", m = /^[0-9a-fA-F]{32}$/, h = (t = {}) => {
64
+ let i = () => {
65
+ let e = t.clientId ?? process.env.VOLTRO_EOS_CLIENT_ID ?? "", r = t.deploymentId ?? process.env.VOLTRO_EOS_DEPLOYMENT_ID ?? "";
66
+ if (!e) throw new n("eosPlatformLogin: no client id — pass `clientId` or set VOLTRO_EOS_CLIENT_ID");
67
+ if (!r) throw new n("eosPlatformLogin: no deployment id — pass `deploymentId` or set VOLTRO_EOS_DEPLOYMENT_ID");
68
+ return {
69
+ clientId: e,
70
+ deploymentId: r
71
+ };
72
+ };
73
+ return {
74
+ id: "eos",
75
+ declaredEnv: [{
76
+ name: "VOLTRO_EOS_CLIENT_ID",
77
+ required: t.clientId === void 0,
78
+ secret: !1,
79
+ description: "EOS client id the game signs in with."
80
+ }, {
81
+ name: "VOLTRO_EOS_DEPLOYMENT_ID",
82
+ required: t.deploymentId === void 0,
83
+ secret: !1,
84
+ description: "EOS deployment id the game runs in."
85
+ }],
86
+ permissions: ["network:outbound:api.epicgames.dev"],
87
+ check: () => {
88
+ i();
89
+ },
90
+ verify: async (n) => {
91
+ let { clientId: a, deploymentId: c } = i();
92
+ if (n.length > 8192 || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(n)) throw new e("eos: malformed ID token");
93
+ let l;
94
+ try {
95
+ l = await s(n, t.jwksUrl ?? f, {
96
+ audience: a,
97
+ algorithms: ["RS256"]
98
+ });
99
+ } catch (t) {
100
+ throw t instanceof o && t.code === "jwks_unreachable" ? new r("exchange_failed", "eos: signing keys unavailable", 503) : new e("eos: ID token failed verification");
101
+ }
102
+ let u = l.iss, d = l.iat;
103
+ if (typeof u != "string" || !(u === p || u.startsWith(p + "/")) || typeof d != "number" || d * 1e3 > Date.now() + 6e4 || l.pfdid !== c || typeof l.sub != "string" || !m.test(l.sub)) throw new e("eos: ID token is for another issuer, deployment or player");
104
+ return { accountId: l.sub };
105
+ }
106
+ };
107
+ }, g = async (e, n) => {
108
+ try {
109
+ return await e.verify(n);
110
+ } catch (n) {
111
+ throw n instanceof t ? n : new r("exchange_failed", `${e.id}: ticket verification failed`, 503);
112
+ }
113
+ };
114
+ export { u as definePlatformLogin, h as eosPlatformLogin, d as steamPlatformLogin, g as verifyPlatformTicket };