@voltro/plugin-auth-social 0.84.0 → 0.86.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 +1215 -0
- package/THIRD-PARTY-NOTICES.md +5 -89
- package/dist/apple.js +64 -0
- package/dist/callback.js +113 -0
- package/dist/errors.js +30 -0
- package/dist/github.js +34 -0
- package/dist/identityStore.js +104 -0
- package/dist/index.js +11 -721
- package/dist/linking.js +26 -0
- package/dist/login.js +27 -0
- package/dist/pkce.js +5 -0
- package/dist/plugin.js +244 -0
- package/dist/providers.js +70 -0
- package/dist/signIn.js +67 -0
- package/package.json +5 -5
package/THIRD-PARTY-NOTICES.md
CHANGED
|
@@ -1,70 +1,14 @@
|
|
|
1
1
|
# Third-Party Notices — @voltro/plugin-auth-social
|
|
2
2
|
|
|
3
|
-
This package
|
|
3
|
+
This package uses the open-source software listed below. Each is the
|
|
4
4
|
property of its respective copyright holders and is used under the terms of
|
|
5
5
|
its license. This file is provided for attribution; it grants no rights in
|
|
6
6
|
@voltro/plugin-auth-social itself, which is proprietary (see LICENSE).
|
|
7
7
|
|
|
8
|
-
Generated from the resolved runtime dependency closure (
|
|
8
|
+
Generated from the resolved runtime dependency closure (4 packages).
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
## @effect/experimental@0.61.1
|
|
13
|
-
|
|
14
|
-
License: MIT
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
MIT License
|
|
18
|
-
|
|
19
|
-
Copyright (c) 2023-present The Contributors
|
|
20
|
-
|
|
21
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
-
in the Software without restriction, including without limitation the rights
|
|
24
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
-
furnished to do so, subject to the following conditions:
|
|
27
|
-
|
|
28
|
-
The above copyright notice and this permission notice shall be included in all
|
|
29
|
-
copies or substantial portions of the Software.
|
|
30
|
-
|
|
31
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
-
SOFTWARE.
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## @effect/sql@0.52.1
|
|
41
|
-
|
|
42
|
-
License: MIT
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
MIT License
|
|
46
|
-
|
|
47
|
-
Copyright (c) 2023-present The Contributors
|
|
48
|
-
|
|
49
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
50
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
51
|
-
in the Software without restriction, including without limitation the rights
|
|
52
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
53
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
54
|
-
furnished to do so, subject to the following conditions:
|
|
55
|
-
|
|
56
|
-
The above copyright notice and this permission notice shall be included in all
|
|
57
|
-
copies or substantial portions of the Software.
|
|
58
|
-
|
|
59
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
60
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
61
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
62
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
63
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
64
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
65
|
-
SOFTWARE.
|
|
66
|
-
```
|
|
67
|
-
|
|
68
12
|
## jose@6.2.12
|
|
69
13
|
|
|
70
14
|
License: MIT
|
|
@@ -93,34 +37,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
93
37
|
SOFTWARE.
|
|
94
38
|
```
|
|
95
39
|
|
|
96
|
-
## layerr@3.0.0
|
|
97
|
-
|
|
98
|
-
License: MIT
|
|
99
|
-
|
|
100
|
-
```
|
|
101
|
-
MIT License
|
|
102
|
-
|
|
103
|
-
Copyright (c) 2020 Perry Mitchell
|
|
104
|
-
|
|
105
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
106
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
107
|
-
in the Software without restriction, including without limitation the rights
|
|
108
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
109
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
110
|
-
furnished to do so, subject to the following conditions:
|
|
111
|
-
|
|
112
|
-
The above copyright notice and this permission notice shall be included in all
|
|
113
|
-
copies or substantial portions of the Software.
|
|
114
|
-
|
|
115
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
116
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
117
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
118
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
119
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
120
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
121
|
-
SOFTWARE.
|
|
122
|
-
```
|
|
123
|
-
|
|
124
40
|
## typeid-js@1.2.0
|
|
125
41
|
|
|
126
42
|
License: Apache-2.0
|
|
@@ -329,14 +245,14 @@ Apache License
|
|
|
329
245
|
limitations under the License.
|
|
330
246
|
```
|
|
331
247
|
|
|
332
|
-
##
|
|
248
|
+
## ulid@3.0.2
|
|
333
249
|
|
|
334
250
|
License: MIT
|
|
335
251
|
|
|
336
252
|
```
|
|
337
|
-
MIT License
|
|
253
|
+
The MIT License (MIT)
|
|
338
254
|
|
|
339
|
-
Copyright (c)
|
|
255
|
+
Copyright (c) 2017 Alizain Feerasta
|
|
340
256
|
|
|
341
257
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
342
258
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/apple.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { SocialConfigError as e } from "./errors.js";
|
|
2
|
+
import { createPrivateKey as t, sign as n } from "node:crypto";
|
|
3
|
+
//#region src/apple.ts
|
|
4
|
+
var r = 15777e3, i = 900, a = "https://appleid.apple.com", o = (e) => (typeof e == "string" ? Buffer.from(e, "utf8") : e).toString("base64url"), s = /* @__PURE__ */ new Map(), c = (n) => {
|
|
5
|
+
let r = s.get(n);
|
|
6
|
+
if (r) return r;
|
|
7
|
+
let i;
|
|
8
|
+
try {
|
|
9
|
+
i = t({ key: n });
|
|
10
|
+
} catch (t) {
|
|
11
|
+
throw new e(`apple: could not parse the .p8 private key — ${t.message}`);
|
|
12
|
+
}
|
|
13
|
+
if (i.asymmetricKeyType !== "ec") throw new e(`apple: the .p8 key must be an EC (P-256) key, got '${String(i.asymmetricKeyType)}'`);
|
|
14
|
+
let a = i.asymmetricKeyDetails?.namedCurve;
|
|
15
|
+
if (a !== void 0 && a !== "prime256v1") throw new e(`apple: ES256 requires the P-256 curve (prime256v1), got '${a}'`);
|
|
16
|
+
return s.set(n, i), i;
|
|
17
|
+
}, l = /* @__PURE__ */ new Map(), u = () => {
|
|
18
|
+
s.clear(), l.clear();
|
|
19
|
+
}, d = (t, i, s = Date.now) => {
|
|
20
|
+
if (!t) throw new e("apple: `clientId` (Services ID) is required");
|
|
21
|
+
if (!i.teamId) throw new e("apple: `teamId` is required");
|
|
22
|
+
if (!i.keyId) throw new e("apple: `keyId` is required");
|
|
23
|
+
if (!i.privateKey) throw new e("apple: `privateKey` (.p8 contents) is required");
|
|
24
|
+
let u = i.ttlSeconds ?? 900;
|
|
25
|
+
if (!Number.isFinite(u) || u <= 0) throw new e("apple: `ttlSeconds` must be a positive number");
|
|
26
|
+
if (u > 15777e3) throw new e(`apple: \`ttlSeconds\` may not exceed ${r} (six months, Apple's cap) — got ${u}`);
|
|
27
|
+
let d = s(), f = `${i.teamId}\u0000${i.keyId}\u0000${t}\u0000${u}`, p = l.get(f);
|
|
28
|
+
if (p && p.expiresAtMs - d > 6e4) return p.secret;
|
|
29
|
+
let m = Math.floor(d / 1e3), h = m + u, g = `${o(JSON.stringify({
|
|
30
|
+
alg: "ES256",
|
|
31
|
+
kid: i.keyId,
|
|
32
|
+
typ: "JWT"
|
|
33
|
+
}))}.${o(JSON.stringify({
|
|
34
|
+
iss: i.teamId,
|
|
35
|
+
iat: m,
|
|
36
|
+
exp: h,
|
|
37
|
+
aud: a,
|
|
38
|
+
sub: t
|
|
39
|
+
}))}`, _ = `${g}.${n("sha256", Buffer.from(g, "ascii"), {
|
|
40
|
+
key: c(i.privateKey),
|
|
41
|
+
dsaEncoding: "ieee-p1363"
|
|
42
|
+
}).toString("base64url")}`;
|
|
43
|
+
return l.set(f, {
|
|
44
|
+
secret: _,
|
|
45
|
+
expiresAtMs: h * 1e3
|
|
46
|
+
}), _;
|
|
47
|
+
}, f = (e) => {
|
|
48
|
+
if (!e) return null;
|
|
49
|
+
let t;
|
|
50
|
+
try {
|
|
51
|
+
t = JSON.parse(e);
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (typeof t != "object" || !t) return null;
|
|
56
|
+
let n = t, r = typeof n.name == "object" && n.name !== null ? n.name : {}, i = (e) => typeof e == "string" && e.length > 0 ? e : null, a = {
|
|
57
|
+
firstName: i(r.firstName),
|
|
58
|
+
lastName: i(r.lastName),
|
|
59
|
+
email: i(n.email)
|
|
60
|
+
};
|
|
61
|
+
return a.firstName === null && a.lastName === null && a.email === null ? null : a;
|
|
62
|
+
}, p = (e) => e !== null && e.toLowerCase().endsWith("@privaterelay.appleid.com");
|
|
63
|
+
//#endregion
|
|
64
|
+
export { i as APPLE_CLIENT_SECRET_DEFAULT_TTL_S, r as APPLE_CLIENT_SECRET_MAX_TTL_S, u as _resetAppleSecretCache, d as appleClientSecret, p as isApplePrivateRelayEmail, f as parseAppleUserPayload };
|
package/dist/callback.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { SocialAuthError as e, SocialConfigError as t, SocialExchangeError as n, SocialIdTokenError as r, SocialStateMismatchError as i } from "./errors.js";
|
|
2
|
+
import { socialProvider as a } from "./providers.js";
|
|
3
|
+
import { appleClientSecret as o, isApplePrivateRelayEmail as s, parseAppleUserPayload as c } from "./apple.js";
|
|
4
|
+
import { fetchGithubIdentity as l } from "./github.js";
|
|
5
|
+
import { timingSafeStringEqual as u } from "@voltro/protocol/session";
|
|
6
|
+
import { JwtVerifyError as d, verifyJwt as f } from "@voltro/protocol/jwt";
|
|
7
|
+
//#region src/callback.ts
|
|
8
|
+
var p = (e) => e === !0 || e === "true", m = (e) => typeof e == "string" && e.length > 0 ? e : null, h = async (h) => {
|
|
9
|
+
let g = a(h.provider, h.endpoints ?? {});
|
|
10
|
+
if (!h.code) throw new e(400, "missing_code", "socialCompleteLogin: missing `code`");
|
|
11
|
+
if (!h.expectedState) throw new i("socialCompleteLogin: no `expectedState` — the login was never started by this server, or the state cookie expired. Refusing to exchange the code.");
|
|
12
|
+
if (!h.state || !u(h.state, h.expectedState)) throw new i("socialCompleteLogin: `state` does not match the value minted for this browser (possible login CSRF).");
|
|
13
|
+
if (!h.codeVerifier) throw new e(400, "missing_verifier", "socialCompleteLogin: missing `codeVerifier` (PKCE)");
|
|
14
|
+
if (g.kind === "oidc" && !h.expectedNonce) throw new t(`socialCompleteLogin: ${g.id} returns an ID token, so \`expectedNonce\` is required — without it a token captured from another login replays here.`);
|
|
15
|
+
let _ = g.id === "apple" ? o(h.clientId, h.appleKey ?? (() => {
|
|
16
|
+
throw new t("apple: `appleKey` (teamId + keyId + .p8) is required");
|
|
17
|
+
})(), h.now ?? Date.now) : h.clientSecret ?? (() => {
|
|
18
|
+
throw new t(`${g.id}: \`clientSecret\` is required`);
|
|
19
|
+
})(), v = h.fetchImpl ?? fetch, y = new URLSearchParams({
|
|
20
|
+
grant_type: "authorization_code",
|
|
21
|
+
client_id: h.clientId,
|
|
22
|
+
client_secret: _,
|
|
23
|
+
code: h.code,
|
|
24
|
+
redirect_uri: h.redirectUri,
|
|
25
|
+
code_verifier: h.codeVerifier
|
|
26
|
+
}), b = await v(g.tokenUrl, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: {
|
|
29
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
30
|
+
accept: "application/json"
|
|
31
|
+
},
|
|
32
|
+
body: y.toString()
|
|
33
|
+
});
|
|
34
|
+
if (!b.ok) {
|
|
35
|
+
let e = await b.text().catch(() => "");
|
|
36
|
+
throw new n("exchange_failed", `${g.id}: token exchange failed (${b.status}): ${e.slice(0, 200)}`);
|
|
37
|
+
}
|
|
38
|
+
let x;
|
|
39
|
+
try {
|
|
40
|
+
x = await b.json();
|
|
41
|
+
} catch {
|
|
42
|
+
throw new n("malformed_token_response", `${g.id}: token endpoint returned a body that is not JSON`);
|
|
43
|
+
}
|
|
44
|
+
if (x.error) throw new n("exchange_failed", `${g.id}: token exchange refused: ${x.error}${x.error_description ? ` (${x.error_description})` : ""}`);
|
|
45
|
+
if (g.kind === "oauth2") {
|
|
46
|
+
if (!x.access_token) throw new n("malformed_token_response", `${g.id}: token response carries no access_token`);
|
|
47
|
+
if (!g.apiBase) throw new t(`${g.id}: no apiBase configured`);
|
|
48
|
+
let e = await l(x.access_token, {
|
|
49
|
+
apiBase: g.apiBase,
|
|
50
|
+
...h.fetchImpl === void 0 ? {} : { fetchImpl: h.fetchImpl }
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
provider: g.id,
|
|
54
|
+
providerAccountId: e.accountId,
|
|
55
|
+
email: e.email,
|
|
56
|
+
emailVerified: e.emailVerified,
|
|
57
|
+
emailIsPrivateRelay: !1,
|
|
58
|
+
name: e.name ?? e.login,
|
|
59
|
+
firstName: null,
|
|
60
|
+
lastName: null,
|
|
61
|
+
avatarUrl: e.avatarUrl,
|
|
62
|
+
nameIsFirstAuthorizationOnly: !1,
|
|
63
|
+
raw: { ...e }
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (!x.id_token) throw new n("malformed_token_response", `${g.id}: token response carries no id_token`);
|
|
67
|
+
if (!g.jwksUrl || !g.issuer) throw new t(`${g.id}: no JWKS/issuer configured`);
|
|
68
|
+
let S;
|
|
69
|
+
try {
|
|
70
|
+
S = await f(x.id_token, g.jwksUrl, {
|
|
71
|
+
issuer: g.issuer,
|
|
72
|
+
audience: h.clientId
|
|
73
|
+
});
|
|
74
|
+
} catch (e) {
|
|
75
|
+
throw e instanceof d ? new r("id_token_invalid", `${g.id}: id_token ${e.code}: ${e.message}`) : new r("id_token_invalid", `${g.id}: id_token verification failed: ${e.message}`);
|
|
76
|
+
}
|
|
77
|
+
let C = m(S.nonce);
|
|
78
|
+
if (!C || !u(C, h.expectedNonce ?? "")) throw new r("nonce_mismatch", `${g.id}: id_token nonce does not match the value minted for this login (possible replay).`);
|
|
79
|
+
let w = m(S.sub);
|
|
80
|
+
if (!w) throw new r("id_token_invalid", `${g.id}: id_token has no sub claim`);
|
|
81
|
+
let T = m(S.email), E = p(S.email_verified);
|
|
82
|
+
if (g.id === "apple") {
|
|
83
|
+
let e = c(h.appleUserPayload), t = p(S.is_private_email) || s(T), n = e?.firstName ?? null, r = e?.lastName ?? null, i = [n, r].filter((e) => e !== null).join(" ");
|
|
84
|
+
return {
|
|
85
|
+
provider: "apple",
|
|
86
|
+
providerAccountId: w,
|
|
87
|
+
email: T ?? e?.email ?? null,
|
|
88
|
+
emailVerified: E,
|
|
89
|
+
emailIsPrivateRelay: t,
|
|
90
|
+
name: i.length > 0 ? i : null,
|
|
91
|
+
firstName: n,
|
|
92
|
+
lastName: r,
|
|
93
|
+
avatarUrl: null,
|
|
94
|
+
nameIsFirstAuthorizationOnly: e !== null,
|
|
95
|
+
raw: S
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
provider: g.id,
|
|
100
|
+
providerAccountId: w,
|
|
101
|
+
email: T,
|
|
102
|
+
emailVerified: E,
|
|
103
|
+
emailIsPrivateRelay: !1,
|
|
104
|
+
name: m(S.name),
|
|
105
|
+
firstName: m(S.given_name),
|
|
106
|
+
lastName: m(S.family_name),
|
|
107
|
+
avatarUrl: m(S.picture),
|
|
108
|
+
nameIsFirstAuthorizationOnly: !1,
|
|
109
|
+
raw: S
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
//#endregion
|
|
113
|
+
export { h as socialCompleteLogin };
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/errors.ts
|
|
2
|
+
var e = class extends Error {
|
|
3
|
+
status;
|
|
4
|
+
code;
|
|
5
|
+
constructor(e, t, n) {
|
|
6
|
+
super(n), this.status = e, this.code = t, this.name = "SocialAuthError";
|
|
7
|
+
}
|
|
8
|
+
}, t = class extends e {
|
|
9
|
+
constructor(e) {
|
|
10
|
+
super(400, "state_mismatch", e), this.name = "SocialStateMismatchError";
|
|
11
|
+
}
|
|
12
|
+
}, n = class extends e {
|
|
13
|
+
constructor(e, t, n = 502) {
|
|
14
|
+
super(n, e, t), this.name = "SocialExchangeError";
|
|
15
|
+
}
|
|
16
|
+
}, r = class extends e {
|
|
17
|
+
constructor(e, t) {
|
|
18
|
+
super(401, e, t), this.name = "SocialIdTokenError";
|
|
19
|
+
}
|
|
20
|
+
}, i = class extends e {
|
|
21
|
+
constructor(e) {
|
|
22
|
+
super(500, "config", e), this.name = "SocialConfigError";
|
|
23
|
+
}
|
|
24
|
+
}, a = class extends e {
|
|
25
|
+
constructor(e, t, n = 409) {
|
|
26
|
+
super(n, e, t), this.name = "SocialAccountLinkError";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { a as SocialAccountLinkError, e as SocialAuthError, i as SocialConfigError, n as SocialExchangeError, r as SocialIdTokenError, t as SocialStateMismatchError };
|
package/dist/github.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SocialExchangeError as e } from "./errors.js";
|
|
2
|
+
//#region src/github.ts
|
|
3
|
+
var t = (e) => ({
|
|
4
|
+
authorization: `Bearer ${e}`,
|
|
5
|
+
accept: "application/vnd.github+json",
|
|
6
|
+
"x-github-api-version": "2022-11-28",
|
|
7
|
+
"user-agent": "voltro-plugin-auth-social"
|
|
8
|
+
}), n = async (n, r) => {
|
|
9
|
+
let i = r.fetchImpl ?? fetch, a = await i(`${r.apiBase}/user`, { headers: t(n) });
|
|
10
|
+
if (!a.ok) {
|
|
11
|
+
let t = await a.text().catch(() => "");
|
|
12
|
+
throw new e("exchange_failed", `github: GET /user failed (${a.status}): ${t.slice(0, 200)}`);
|
|
13
|
+
}
|
|
14
|
+
let o = await a.json();
|
|
15
|
+
if (o.id === void 0 || o.id === null || !o.login) throw new e("malformed_token_response", "github: GET /user response is missing id/login");
|
|
16
|
+
let s = null, c = !1, l = await i(`${r.apiBase}/user/emails`, { headers: t(n) });
|
|
17
|
+
if (l.ok) {
|
|
18
|
+
let e = await l.json();
|
|
19
|
+
if (Array.isArray(e)) {
|
|
20
|
+
let t = e.find((e) => e.primary === !0 && typeof e.email == "string");
|
|
21
|
+
t?.email && (s = t.email, c = t.verified === !0);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
accountId: String(o.id),
|
|
26
|
+
login: o.login,
|
|
27
|
+
name: typeof o.name == "string" && o.name.length > 0 ? o.name : null,
|
|
28
|
+
avatarUrl: typeof o.avatar_url == "string" && o.avatar_url.length > 0 ? o.avatar_url : null,
|
|
29
|
+
email: s,
|
|
30
|
+
emailVerified: c
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { n as fetchGithubIdentity };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Effect as e } from "effect";
|
|
2
|
+
import { and as t, boolean as n, eq as r, generateId as i, id as a, table as o, text as s, timestamp as c } from "@voltro/database";
|
|
3
|
+
//#region src/identityStore.ts
|
|
4
|
+
var l = "_voltro_oauth_identities", u = o(l, {
|
|
5
|
+
id: a({ prefix: "oauthid" }),
|
|
6
|
+
userId: s(),
|
|
7
|
+
provider: s(),
|
|
8
|
+
providerAccountId: s(),
|
|
9
|
+
email: s().nullable(),
|
|
10
|
+
emailVerified: n().default(!1),
|
|
11
|
+
createdAt: c().default("now"),
|
|
12
|
+
lastLoginAt: c().nullable()
|
|
13
|
+
}).unique("byOauthProviderAccount", ["provider", "providerAccountId"]).index(["userId"]), d = [u], f = () => i({
|
|
14
|
+
kind: "typeid",
|
|
15
|
+
prefix: "oauthid"
|
|
16
|
+
}, "oauthid"), p = (t = []) => {
|
|
17
|
+
let n = [...t];
|
|
18
|
+
return {
|
|
19
|
+
findByProviderAccount: (t, r) => e.sync(() => n.find((e) => e.provider === t && e.providerAccountId === r) ?? null),
|
|
20
|
+
listForUser: (t) => e.sync(() => n.filter((e) => e.userId === t)),
|
|
21
|
+
insert: (t) => e.sync(() => {
|
|
22
|
+
let e = {
|
|
23
|
+
...t,
|
|
24
|
+
id: f(),
|
|
25
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
26
|
+
lastLoginAt: null
|
|
27
|
+
};
|
|
28
|
+
return n.push(e), e;
|
|
29
|
+
}),
|
|
30
|
+
touch: (t, r) => e.sync(() => {
|
|
31
|
+
let e = n.findIndex((e) => e.id === t);
|
|
32
|
+
e >= 0 && (n[e] = {
|
|
33
|
+
...n[e],
|
|
34
|
+
lastLoginAt: r
|
|
35
|
+
});
|
|
36
|
+
}),
|
|
37
|
+
remove: (t, r) => e.sync(() => {
|
|
38
|
+
let e = n.findIndex((e) => e.userId === t && e.provider === r);
|
|
39
|
+
return e < 0 ? !1 : (n.splice(e, 1), !0);
|
|
40
|
+
})
|
|
41
|
+
};
|
|
42
|
+
}, m = (e) => {
|
|
43
|
+
if (e instanceof Date) return e;
|
|
44
|
+
if (typeof e == "string" || typeof e == "number") {
|
|
45
|
+
let t = new Date(e);
|
|
46
|
+
return Number.isNaN(t.getTime()) ? null : t;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}, h = (e) => ({
|
|
50
|
+
id: String(e.id ?? ""),
|
|
51
|
+
userId: String(e.userId ?? ""),
|
|
52
|
+
provider: String(e.provider ?? ""),
|
|
53
|
+
providerAccountId: String(e.providerAccountId ?? ""),
|
|
54
|
+
email: typeof e.email == "string" && e.email.length > 0 ? e.email : null,
|
|
55
|
+
emailVerified: e.emailVerified === !0 || e.emailVerified === 1,
|
|
56
|
+
createdAt: m(e.createdAt) ?? /* @__PURE__ */ new Date(0),
|
|
57
|
+
lastLoginAt: m(e.lastLoginAt)
|
|
58
|
+
}), g = (n) => ({
|
|
59
|
+
findByProviderAccount: (i, a) => e.promise(async () => {
|
|
60
|
+
let e = (await n.query({
|
|
61
|
+
table: l,
|
|
62
|
+
predicate: t(r("provider", i), r("providerAccountId", a)),
|
|
63
|
+
limit: 1
|
|
64
|
+
}))[0];
|
|
65
|
+
return e ? h(e) : null;
|
|
66
|
+
}),
|
|
67
|
+
listForUser: (t) => e.promise(async () => (await n.query({
|
|
68
|
+
table: l,
|
|
69
|
+
predicate: r("userId", t),
|
|
70
|
+
order: [{
|
|
71
|
+
column: "createdAt",
|
|
72
|
+
direction: "asc"
|
|
73
|
+
}]
|
|
74
|
+
})).map(h)),
|
|
75
|
+
insert: (t) => e.promise(async () => h(await n.insert(l, {
|
|
76
|
+
id: f(),
|
|
77
|
+
userId: t.userId,
|
|
78
|
+
provider: t.provider,
|
|
79
|
+
providerAccountId: t.providerAccountId,
|
|
80
|
+
email: t.email,
|
|
81
|
+
emailVerified: t.emailVerified,
|
|
82
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
83
|
+
lastLoginAt: null
|
|
84
|
+
}))),
|
|
85
|
+
touch: (t, r) => e.promise(async () => {
|
|
86
|
+
await n.update(l, t, { lastLoginAt: r });
|
|
87
|
+
}),
|
|
88
|
+
remove: (i, a) => e.promise(async () => {
|
|
89
|
+
let e = (await n.query({
|
|
90
|
+
table: l,
|
|
91
|
+
predicate: t(r("userId", i), r("provider", a)),
|
|
92
|
+
limit: 1
|
|
93
|
+
}))[0];
|
|
94
|
+
return e ? n.delete(l, String(e.id ?? "")) : !1;
|
|
95
|
+
})
|
|
96
|
+
}), _ = (t, n, r) => e.gen(function* () {
|
|
97
|
+
let i = yield* t.findByProviderAccount(r.provider, r.providerAccountId);
|
|
98
|
+
return i ? i.userId === n ? i : yield* e.fail(/* @__PURE__ */ Error(`linkSocialIdentity: this ${r.provider} account is already linked to another user`)) : yield* t.insert({
|
|
99
|
+
...r,
|
|
100
|
+
userId: n
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
//#endregion
|
|
104
|
+
export { l as SOCIAL_IDENTITY_TABLE, g as dataStoreSocialIdentityStore, _ as linkSocialIdentity, p as memorySocialIdentityStore, d as socialAuthTables, u as socialIdentitiesTable };
|