@shware/security 2.5.3 → 3.0.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/dist/auth/index.cjs +519 -561
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +104 -106
- package/dist/auth/index.d.cts.map +1 -0
- package/dist/auth/index.d.mts +109 -0
- package/dist/auth/index.d.mts.map +1 -0
- package/dist/auth/index.mjs +512 -536
- package/dist/auth/index.mjs.map +1 -1
- package/dist/auth/types.cjs +0 -19
- package/dist/auth/types.d.cts +44 -44
- package/dist/auth/types.d.cts.map +1 -0
- package/dist/auth/types.d.mts +50 -0
- package/dist/auth/types.d.mts.map +1 -0
- package/dist/auth/types.mjs +1 -1
- package/dist/core/index.cjs +18 -59
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +13 -24
- package/dist/core/index.d.cts.map +1 -0
- package/dist/core/index.d.mts +21 -0
- package/dist/core/index.d.mts.map +1 -0
- package/dist/core/index.mjs +17 -33
- package/dist/core/index.mjs.map +1 -1
- package/dist/email/schema.cjs +13 -38
- package/dist/email/schema.cjs.map +1 -1
- package/dist/email/schema.d.cts +11 -12
- package/dist/email/schema.d.cts.map +1 -0
- package/dist/email/schema.d.mts +12 -0
- package/dist/email/schema.d.mts.map +1 -0
- package/dist/email/schema.mjs +10 -11
- package/dist/email/schema.mjs.map +1 -1
- package/dist/index.cjs +18 -54
- package/dist/index.d.cts +10 -15
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +5 -17
- package/dist/oauth2/client.cjs +109 -145
- package/dist/oauth2/client.cjs.map +1 -1
- package/dist/oauth2/client.d.cts +55 -56
- package/dist/oauth2/client.d.cts.map +1 -0
- package/dist/oauth2/client.d.mts +58 -0
- package/dist/oauth2/client.d.mts.map +1 -0
- package/dist/oauth2/client.mjs +104 -116
- package/dist/oauth2/client.mjs.map +1 -1
- package/dist/oauth2/error.cjs +19 -44
- package/dist/oauth2/error.cjs.map +1 -1
- package/dist/oauth2/error.d.cts +8 -6
- package/dist/oauth2/error.d.cts.map +1 -0
- package/dist/oauth2/{error.d.ts → error.d.mts} +8 -6
- package/dist/oauth2/error.d.mts.map +1 -0
- package/dist/oauth2/error.mjs +18 -19
- package/dist/oauth2/error.mjs.map +1 -1
- package/dist/oauth2/provider/apple.cjs +75 -88
- package/dist/oauth2/provider/apple.cjs.map +1 -1
- package/dist/oauth2/provider/apple.d.cts +31 -30
- package/dist/oauth2/provider/apple.d.cts.map +1 -0
- package/dist/oauth2/provider/apple.d.mts +42 -0
- package/dist/oauth2/provider/apple.d.mts.map +1 -0
- package/dist/oauth2/provider/apple.mjs +71 -60
- package/dist/oauth2/provider/apple.mjs.map +1 -1
- package/dist/oauth2/provider/common.cjs +86 -109
- package/dist/oauth2/provider/common.cjs.map +1 -1
- package/dist/oauth2/provider/common.d.cts +19 -18
- package/dist/oauth2/provider/common.d.cts.map +1 -0
- package/dist/oauth2/provider/common.d.mts +30 -0
- package/dist/oauth2/provider/common.d.mts.map +1 -0
- package/dist/oauth2/provider/common.mjs +80 -79
- package/dist/oauth2/provider/common.mjs.map +1 -1
- package/dist/oauth2/provider/facebook.cjs +93 -109
- package/dist/oauth2/provider/facebook.cjs.map +1 -1
- package/dist/oauth2/provider/facebook.d.cts +29 -28
- package/dist/oauth2/provider/facebook.d.cts.map +1 -0
- package/dist/oauth2/provider/facebook.d.mts +45 -0
- package/dist/oauth2/provider/facebook.d.mts.map +1 -0
- package/dist/oauth2/provider/facebook.mjs +89 -81
- package/dist/oauth2/provider/facebook.mjs.map +1 -1
- package/dist/oauth2/provider/github.cjs +64 -91
- package/dist/oauth2/provider/github.cjs.map +1 -1
- package/dist/oauth2/provider/github.d.cts +52 -51
- package/dist/oauth2/provider/github.d.cts.map +1 -0
- package/dist/oauth2/provider/github.d.mts +60 -0
- package/dist/oauth2/provider/github.d.mts.map +1 -0
- package/dist/oauth2/provider/github.mjs +60 -63
- package/dist/oauth2/provider/github.mjs.map +1 -1
- package/dist/oauth2/provider/google.cjs +105 -122
- package/dist/oauth2/provider/google.cjs.map +1 -1
- package/dist/oauth2/provider/google.d.cts +34 -33
- package/dist/oauth2/provider/google.d.cts.map +1 -0
- package/dist/oauth2/provider/google.d.mts +44 -0
- package/dist/oauth2/provider/google.d.mts.map +1 -0
- package/dist/oauth2/provider/google.mjs +101 -94
- package/dist/oauth2/provider/google.mjs.map +1 -1
- package/dist/oauth2/provider/index.cjs +13 -46
- package/dist/oauth2/provider/index.d.cts +7 -7
- package/dist/oauth2/provider/index.d.mts +7 -0
- package/dist/oauth2/provider/index.mjs +1 -10
- package/dist/oauth2/provider/wechat.cjs +77 -99
- package/dist/oauth2/provider/wechat.cjs.map +1 -1
- package/dist/oauth2/provider/wechat.d.cts +28 -27
- package/dist/oauth2/provider/wechat.d.cts.map +1 -0
- package/dist/oauth2/provider/wechat.d.mts +39 -0
- package/dist/oauth2/provider/wechat.d.mts.map +1 -0
- package/dist/oauth2/provider/wechat.mjs +74 -72
- package/dist/oauth2/provider/wechat.mjs.map +1 -1
- package/dist/oauth2/provider/x.cjs +102 -125
- package/dist/oauth2/provider/x.cjs.map +1 -1
- package/dist/oauth2/provider/x.d.cts +51 -50
- package/dist/oauth2/provider/x.d.cts.map +1 -0
- package/dist/oauth2/provider/x.d.mts +69 -0
- package/dist/oauth2/provider/x.d.mts.map +1 -0
- package/dist/oauth2/provider/x.mjs +99 -103
- package/dist/oauth2/provider/x.mjs.map +1 -1
- package/dist/oauth2/types.cjs +12 -37
- package/dist/oauth2/types.cjs.map +1 -1
- package/dist/oauth2/types.d.cts +176 -180
- package/dist/oauth2/types.d.cts.map +1 -0
- package/dist/oauth2/types.d.mts +207 -0
- package/dist/oauth2/types.d.mts.map +1 -0
- package/dist/oauth2/types.mjs +12 -13
- package/dist/oauth2/types.mjs.map +1 -1
- package/dist/session/common.cjs +17 -43
- package/dist/session/common.cjs.map +1 -1
- package/dist/session/common.d.cts +4 -4
- package/dist/session/common.d.cts.map +1 -0
- package/dist/session/{common.d.ts → common.d.mts} +4 -4
- package/dist/session/common.d.mts.map +1 -0
- package/dist/session/common.mjs +14 -16
- package/dist/session/common.mjs.map +1 -1
- package/dist/session/db.cjs +88 -123
- package/dist/session/db.cjs.map +1 -1
- package/dist/session/db.d.cts +36 -36
- package/dist/session/db.d.cts.map +1 -0
- package/dist/session/db.d.mts +44 -0
- package/dist/session/db.d.mts.map +1 -0
- package/dist/session/db.mjs +84 -95
- package/dist/session/db.mjs.map +1 -1
- package/dist/session/map-session.cjs +71 -103
- package/dist/session/map-session.cjs.map +1 -1
- package/dist/session/map-session.d.cts +24 -24
- package/dist/session/map-session.d.cts.map +1 -0
- package/dist/session/map-session.d.mts +27 -0
- package/dist/session/map-session.d.mts.map +1 -0
- package/dist/session/map-session.mjs +70 -78
- package/dist/session/map-session.mjs.map +1 -1
- package/dist/session/redis.cjs +270 -319
- package/dist/session/redis.cjs.map +1 -1
- package/dist/session/redis.d.cts +51 -51
- package/dist/session/redis.d.cts.map +1 -0
- package/dist/session/redis.d.mts +58 -0
- package/dist/session/redis.d.mts.map +1 -0
- package/dist/session/redis.mjs +266 -291
- package/dist/session/redis.mjs.map +1 -1
- package/dist/session/types.cjs +0 -19
- package/dist/session/types.d.cts +34 -33
- package/dist/session/types.d.cts.map +1 -0
- package/dist/session/types.d.mts +45 -0
- package/dist/session/types.d.mts.map +1 -0
- package/dist/session/types.mjs +1 -1
- package/dist/utils/http.cjs +31 -55
- package/dist/utils/http.cjs.map +1 -1
- package/dist/utils/http.d.cts +7 -10
- package/dist/utils/http.d.cts.map +1 -0
- package/dist/utils/{http.d.ts → http.d.mts} +7 -10
- package/dist/utils/http.d.mts.map +1 -0
- package/dist/utils/http.mjs +24 -24
- package/dist/utils/http.mjs.map +1 -1
- package/dist/utils/oauth2.cjs +6 -30
- package/dist/utils/oauth2.cjs.map +1 -1
- package/dist/utils/oauth2.d.cts +3 -1
- package/dist/utils/oauth2.d.cts.map +1 -0
- package/dist/utils/oauth2.d.mts +5 -0
- package/dist/utils/oauth2.d.mts.map +1 -0
- package/dist/utils/oauth2.mjs +5 -5
- package/dist/utils/oauth2.mjs.map +1 -1
- package/dist/utils/timing.cjs +49 -70
- package/dist/utils/timing.cjs.map +1 -1
- package/dist/utils/timing.d.cts +10 -8
- package/dist/utils/timing.d.cts.map +1 -0
- package/dist/utils/timing.d.mts +15 -0
- package/dist/utils/timing.d.mts.map +1 -0
- package/dist/utils/timing.mjs +48 -45
- package/dist/utils/timing.mjs.map +1 -1
- package/dist/utils/valid.cjs +50 -71
- package/dist/utils/valid.cjs.map +1 -1
- package/dist/utils/valid.d.cts +17 -16
- package/dist/utils/valid.d.cts.map +1 -0
- package/dist/utils/valid.d.mts +28 -0
- package/dist/utils/valid.d.mts.map +1 -0
- package/dist/utils/valid.mjs +47 -44
- package/dist/utils/valid.mjs.map +1 -1
- package/package.json +22 -12
- package/dist/auth/index.d.ts +0 -111
- package/dist/auth/types.cjs.map +0 -1
- package/dist/auth/types.d.ts +0 -50
- package/dist/auth/types.mjs.map +0 -1
- package/dist/core/index.d.ts +0 -32
- package/dist/email/schema.d.ts +0 -13
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/index.mjs.map +0 -1
- package/dist/oauth2/client.d.ts +0 -59
- package/dist/oauth2/provider/apple.d.ts +0 -41
- package/dist/oauth2/provider/common.d.ts +0 -29
- package/dist/oauth2/provider/facebook.d.ts +0 -44
- package/dist/oauth2/provider/github.d.ts +0 -59
- package/dist/oauth2/provider/google.d.ts +0 -43
- package/dist/oauth2/provider/index.cjs.map +0 -1
- package/dist/oauth2/provider/index.d.ts +0 -7
- package/dist/oauth2/provider/index.mjs.map +0 -1
- package/dist/oauth2/provider/wechat.d.ts +0 -38
- package/dist/oauth2/provider/x.d.ts +0 -68
- package/dist/oauth2/types.d.ts +0 -211
- package/dist/session/__tests__/redis.test.cjs +0 -247
- package/dist/session/__tests__/redis.test.cjs.map +0 -1
- package/dist/session/__tests__/redis.test.d.cts +0 -2
- package/dist/session/__tests__/redis.test.d.ts +0 -2
- package/dist/session/__tests__/redis.test.mjs +0 -252
- package/dist/session/__tests__/redis.test.mjs.map +0 -1
- package/dist/session/db.d.ts +0 -44
- package/dist/session/map-session.d.ts +0 -27
- package/dist/session/redis.d.ts +0 -58
- package/dist/session/types.cjs.map +0 -1
- package/dist/session/types.d.ts +0 -44
- package/dist/session/types.mjs.map +0 -1
- package/dist/utils/oauth2.d.ts +0 -3
- package/dist/utils/timing.d.ts +0 -13
- package/dist/utils/valid.d.ts +0 -27
package/dist/utils/valid.mjs
CHANGED
|
@@ -1,51 +1,54 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/utils/valid.ts
|
|
2
2
|
function invalidArgument(reason) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
return { error: {
|
|
4
|
+
code: 400,
|
|
5
|
+
status: "INVALID_ARGUMENT",
|
|
6
|
+
message: "Invalid verification code",
|
|
7
|
+
details: [{
|
|
8
|
+
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
|
|
9
|
+
reason
|
|
10
|
+
}]
|
|
11
|
+
} };
|
|
11
12
|
}
|
|
12
13
|
function valid(schema, json) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
14
|
+
const result = schema.safeParse(json);
|
|
15
|
+
if (result.success) return {
|
|
16
|
+
error: null,
|
|
17
|
+
data: result.data
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
error: { error: {
|
|
21
|
+
code: 400,
|
|
22
|
+
status: "INVALID_ARGUMENT",
|
|
23
|
+
message: "Invalid request",
|
|
24
|
+
details: [{
|
|
25
|
+
"@type": "type.googleapis.com/google.rpc.BadRequest",
|
|
26
|
+
fieldViolations: result.error.issues.map(({ code, path, message }) => ({
|
|
27
|
+
field: path.join("."),
|
|
28
|
+
description: message,
|
|
29
|
+
reason: code?.toUpperCase() ?? "INVALID_ARGUMENT",
|
|
30
|
+
localizedMessage: {
|
|
31
|
+
locale: "en-US",
|
|
32
|
+
message
|
|
33
|
+
}
|
|
34
|
+
}))
|
|
35
|
+
}]
|
|
36
|
+
} },
|
|
37
|
+
data: null
|
|
38
|
+
};
|
|
35
39
|
}
|
|
36
40
|
async function verifyTurnstileToken(secret, token) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
if ((await (await fetch("https://challenges.cloudflare.com/turnstile/v0/siteverify", {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
44
|
+
body: new URLSearchParams({
|
|
45
|
+
secret,
|
|
46
|
+
response: token
|
|
47
|
+
})
|
|
48
|
+
})).json()).success) return { error: null };
|
|
49
|
+
return { error: invalidArgument("TURNSTILE_VERIFICATION_FAILED") };
|
|
45
50
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
verifyTurnstileToken
|
|
50
|
-
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { invalidArgument, valid, verifyTurnstileToken };
|
|
53
|
+
|
|
51
54
|
//# sourceMappingURL=valid.mjs.map
|
package/dist/utils/valid.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/valid.ts"],"sourcesContent":["import type { ZodType, output } from 'zod';\nimport type { ZodMiniType, output as outputMini } from 'zod/mini';\n\ntype ErrorBody = {\n error: {\n code: number;\n status: string;\n message: string;\n details: unknown[];\n };\n};\n\nexport function invalidArgument(reason: string): ErrorBody {\n return {\n error: {\n code: 400,\n status: 'INVALID_ARGUMENT',\n message: 'Invalid verification code',\n details: [{ '@type': 'type.googleapis.com/google.rpc.ErrorInfo', reason }],\n },\n };\n}\n\ntype Result<S extends ZodType | ZodMiniType> =\n | { error: null; data: S extends ZodType ? output<S> : outputMini<S> }\n | { error: ErrorBody; data: null };\n\nexport function valid<S extends ZodType | ZodMiniType>(schema: S, json: unknown): Result<S> {\n const result = schema.safeParse(json);\n if (result.success) {\n return {\n error: null,\n data: result.data as S extends ZodType ? output<S> : outputMini<S>,\n };\n }\n\n const fieldViolations = result.error.issues.map(({ code, path, message }) => ({\n field: path.join('.'),\n description: message,\n reason: code?.toUpperCase() ?? 'INVALID_ARGUMENT',\n localizedMessage: { locale: 'en-US', message: message },\n }));\n\n const error = {\n error: {\n code: 400,\n status: 'INVALID_ARGUMENT',\n message: 'Invalid request',\n details: [{ '@type': 'type.googleapis.com/google.rpc.BadRequest', fieldViolations }],\n },\n };\n\n return { error, data: null };\n}\n\nexport async function verifyTurnstileToken(secret: string, token: string) {\n const response = await fetch('https://challenges.cloudflare.com/turnstile/v0/siteverify', {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({ secret, response: token }),\n });\n\n const data = (await response.json()) as { success: boolean };\n if (data.success) return { error: null };\n return { error: invalidArgument('TURNSTILE_VERIFICATION_FAILED') };\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"valid.mjs","names":[],"sources":["../../src/utils/valid.ts"],"sourcesContent":["import type { ZodType, output } from 'zod';\nimport type { ZodMiniType, output as outputMini } from 'zod/mini';\n\ntype ErrorBody = {\n error: {\n code: number;\n status: string;\n message: string;\n details: unknown[];\n };\n};\n\nexport function invalidArgument(reason: string): ErrorBody {\n return {\n error: {\n code: 400,\n status: 'INVALID_ARGUMENT',\n message: 'Invalid verification code',\n details: [{ '@type': 'type.googleapis.com/google.rpc.ErrorInfo', reason }],\n },\n };\n}\n\ntype Result<S extends ZodType | ZodMiniType> =\n | { error: null; data: S extends ZodType ? output<S> : outputMini<S> }\n | { error: ErrorBody; data: null };\n\nexport function valid<S extends ZodType | ZodMiniType>(schema: S, json: unknown): Result<S> {\n const result = schema.safeParse(json);\n if (result.success) {\n return {\n error: null,\n data: result.data as S extends ZodType ? output<S> : outputMini<S>,\n };\n }\n\n const fieldViolations = result.error.issues.map(({ code, path, message }) => ({\n field: path.join('.'),\n description: message,\n reason: code?.toUpperCase() ?? 'INVALID_ARGUMENT',\n localizedMessage: { locale: 'en-US', message: message },\n }));\n\n const error = {\n error: {\n code: 400,\n status: 'INVALID_ARGUMENT',\n message: 'Invalid request',\n details: [{ '@type': 'type.googleapis.com/google.rpc.BadRequest', fieldViolations }],\n },\n };\n\n return { error, data: null };\n}\n\nexport async function verifyTurnstileToken(secret: string, token: string) {\n const response = await fetch('https://challenges.cloudflare.com/turnstile/v0/siteverify', {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({ secret, response: token }),\n });\n\n const data = (await response.json()) as { success: boolean };\n if (data.success) return { error: null };\n return { error: invalidArgument('TURNSTILE_VERIFICATION_FAILED') };\n}\n"],"mappings":";AAYA,SAAgB,gBAAgB,QAA2B;CACzD,OAAO,EACL,OAAO;EACL,MAAM;EACN,QAAQ;EACR,SAAS;EACT,SAAS,CAAC;GAAE,SAAS;GAA4C;EAAO,CAAC;CAC3E,EACF;AACF;AAMA,SAAgB,MAAuC,QAAW,MAA0B;CAC1F,MAAM,SAAS,OAAO,UAAU,IAAI;CACpC,IAAI,OAAO,SACT,OAAO;EACL,OAAO;EACP,MAAM,OAAO;CACf;CAmBF,OAAO;EAAE,OAAA,EARP,OAAO;GACL,MAAM;GACN,QAAQ;GACR,SAAS;GACT,SAAS,CAAC;IAAE,SAAS;IAA6C,iBAZ9C,OAAO,MAAM,OAAO,KAAK,EAAE,MAAM,MAAM,eAAe;KAC5E,OAAO,KAAK,KAAK,GAAG;KACpB,aAAa;KACb,QAAQ,MAAM,YAAY,KAAK;KAC/B,kBAAkB;MAAE,QAAQ;MAAkB;KAAQ;IACxD,EAOoF;GAAE,CAAC;EACrF,EAGW;EAAG,MAAM;CAAK;AAC7B;AAEA,eAAsB,qBAAqB,QAAgB,OAAe;CAQxE,KAAI,OADgB,MANG,MAAM,6DAA6D;EACxF,QAAQ;EACR,SAAS,EAAE,gBAAgB,oCAAoC;EAC/D,MAAM,IAAI,gBAAgB;GAAE;GAAQ,UAAU;EAAM,CAAC;CACvD,CAAC,EAAA,CAE4B,KAAK,EAAA,CACzB,SAAS,OAAO,EAAE,OAAO,KAAK;CACvC,OAAO,EAAE,OAAO,gBAAgB,+BAA+B,EAAE;AACnE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shware/security",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,14 +12,24 @@
|
|
|
12
12
|
"type": "module",
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.mts",
|
|
17
|
+
"default": "./dist/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/index.d.cts",
|
|
21
|
+
"default": "./dist/index.cjs"
|
|
22
|
+
}
|
|
18
23
|
},
|
|
19
24
|
"./oauth2/provider": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/oauth2/provider/index.d.mts",
|
|
27
|
+
"default": "./dist/oauth2/provider/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/oauth2/provider/index.d.cts",
|
|
31
|
+
"default": "./dist/oauth2/provider/index.cjs"
|
|
32
|
+
}
|
|
23
33
|
}
|
|
24
34
|
},
|
|
25
35
|
"publishConfig": {
|
|
@@ -32,18 +42,18 @@
|
|
|
32
42
|
"path-to-regexp": "^8.4.2",
|
|
33
43
|
"uuid": "^14.0.1",
|
|
34
44
|
"zod": "^4.4.3",
|
|
35
|
-
"@shware/utils": "^1.
|
|
45
|
+
"@shware/utils": "^1.5.0"
|
|
36
46
|
},
|
|
37
47
|
"devDependencies": {
|
|
38
|
-
"@types/node": "^26.1.
|
|
48
|
+
"@types/node": "^26.1.1",
|
|
39
49
|
"ts-node": "^10.9.2",
|
|
40
|
-
"typescript": "
|
|
41
|
-
"vitest": "^4.1.
|
|
50
|
+
"typescript": "7.0.2",
|
|
51
|
+
"vitest": "^4.1.10",
|
|
42
52
|
"@repo/typescript-config": "0.0.0"
|
|
43
53
|
},
|
|
44
54
|
"scripts": {
|
|
45
55
|
"dev": "tsc --watch",
|
|
46
|
-
"build": "
|
|
56
|
+
"build": "tsdown",
|
|
47
57
|
"test": "vitest run",
|
|
48
58
|
"check-types": "tsc --noEmit",
|
|
49
59
|
"lint": "oxlint --type-aware src --fix"
|
package/dist/auth/index.d.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { Principal } from '../core/index.js';
|
|
2
|
-
import { Session } from '../session/types.js';
|
|
3
|
-
import { AuthService, AuthConfig, LoggedHandler, AuthorizedHandler } from './types.js';
|
|
4
|
-
import '../oauth2/types.js';
|
|
5
|
-
import '../utils/http.js';
|
|
6
|
-
import 'cookie';
|
|
7
|
-
|
|
8
|
-
declare const PATH: {
|
|
9
|
-
readonly CSRF: "/csrf";
|
|
10
|
-
readonly LOGOUT: "/logout";
|
|
11
|
-
readonly LOGGED: "/logged";
|
|
12
|
-
readonly OAUTH2_STATE: "/oauth2/state/:registrationId";
|
|
13
|
-
readonly OAUTH2_NONCE: "/oauth2/nonce/:registrationId";
|
|
14
|
-
readonly OAUTH2_AUTHORIZATION: "/oauth2/authorization/:registrationId";
|
|
15
|
-
readonly LOGIN_OAUTH2_CODE: "/login/oauth2/code/:registrationId";
|
|
16
|
-
readonly LOGIN_OAUTH2_NATIVE: "/login/oauth2/native/:registrationId";
|
|
17
|
-
readonly LOGIN_OAUTH2_ONETAP: "/login/oauth2/onetap/google";
|
|
18
|
-
readonly LOGIN_EMAIL: "/login/email";
|
|
19
|
-
readonly LOGIN_PHONE: "/login/phone";
|
|
20
|
-
readonly SEND_EMAIL_VERIFICATION_CODE: "/auth/sendEmailVerificationCode";
|
|
21
|
-
readonly SEND_PHONE_VERIFICATION_CODE: "/auth/sendPhoneVerificationCode";
|
|
22
|
-
readonly DESKTOP_AUTHORIZE: "/auth/desktop/authorize";
|
|
23
|
-
readonly DESKTOP_EXCHANGE: "/auth/desktop/exchange";
|
|
24
|
-
readonly CLEANUP_EXPIRED_SESSIONS: "/sessions/expired/cleanup";
|
|
25
|
-
};
|
|
26
|
-
declare class Auth implements AuthService {
|
|
27
|
-
private readonly timing;
|
|
28
|
-
private readonly cookieName;
|
|
29
|
-
private readonly cookieOptions;
|
|
30
|
-
private readonly kv;
|
|
31
|
-
private readonly repository;
|
|
32
|
-
private readonly turnstileSecretKey?;
|
|
33
|
-
private readonly oauth2Client;
|
|
34
|
-
private readonly ATTR_OAUTH2_AUTHORIZATION_REQUEST;
|
|
35
|
-
constructor({ sessionRepository, kvRepository, turnstileSecretKey, oauth2, cookie, timing, }: AuthConfig);
|
|
36
|
-
private getSessionId;
|
|
37
|
-
csrf: (_request: Request) => Promise<Response>;
|
|
38
|
-
logout: (request: Request) => Promise<Response>;
|
|
39
|
-
logged: (request: Request, onLogged?: LoggedHandler) => Promise<Response>;
|
|
40
|
-
private createPkceParameters;
|
|
41
|
-
private getOauth2StateKey;
|
|
42
|
-
private getOauth2NonceKey;
|
|
43
|
-
private getEmailVerificationCodeKey;
|
|
44
|
-
private getPhoneVerificationCodeKey;
|
|
45
|
-
private getDesktopCodeKey;
|
|
46
|
-
oauth2State: (request: Request) => Promise<Response>;
|
|
47
|
-
oauth2Nonce: (request: Request) => Promise<Response>;
|
|
48
|
-
oauth2Authorization: (request: Request) => Promise<Response>;
|
|
49
|
-
private redirect;
|
|
50
|
-
loginOAuth2Code: (request: Request, handler: AuthorizedHandler) => Promise<Response>;
|
|
51
|
-
loginOAuth2Native: (request: Request, handler: AuthorizedHandler) => Promise<Response>;
|
|
52
|
-
loginOAuth2Onetap: (request: Request, handler: AuthorizedHandler, registrationId?: string) => Promise<Response>;
|
|
53
|
-
sendEmailVerificationCode: (request: Request, sender: (data: {
|
|
54
|
-
email: string;
|
|
55
|
-
verificationCode: string;
|
|
56
|
-
}) => Promise<void>) => Promise<Response>;
|
|
57
|
-
loginEmail: (request: Request, handler: AuthorizedHandler) => Promise<Response>;
|
|
58
|
-
/**
|
|
59
|
-
* Step 1 of the desktop / native app sign-in handshake. The caller already
|
|
60
|
-
* completed normal sign-in on the web (so a cookie session exists); this
|
|
61
|
-
* issues a 5-minute single-use code that the web page hands off to the
|
|
62
|
-
* desktop client via a loopback redirect.
|
|
63
|
-
*
|
|
64
|
-
* PKCE (RFC 7636, S256 only): the desktop generates a random `code_verifier`
|
|
65
|
-
* before opening the browser, derives `code_challenge = base64url(sha256(verifier))`,
|
|
66
|
-
* and threads the challenge through the URL → web page → here. We pin
|
|
67
|
-
* the challenge to the code in KV; `desktopExchange` enforces that the
|
|
68
|
-
* caller knows the matching verifier. This blocks an attacker who only
|
|
69
|
-
* intercepts the auth code (browser history, malicious extension, packet
|
|
70
|
-
* capture on loopback) from exchanging it.
|
|
71
|
-
*
|
|
72
|
-
* Requires an authenticated cookie session — anonymous callers get 401.
|
|
73
|
-
* Throttling / abuse protection on this endpoint is the API layer's job
|
|
74
|
-
* (rate-limit per principal); the SDK doesn't gate it because the
|
|
75
|
-
* upstream sign-in flow already passed CAPTCHA / OAuth / verification.
|
|
76
|
-
*/
|
|
77
|
-
desktopAuthorize: (request: Request) => Promise<Response>;
|
|
78
|
-
/**
|
|
79
|
-
* Step 2 of the desktop / native app sign-in handshake. The desktop
|
|
80
|
-
* client hands back the auth code it received via the loopback callback,
|
|
81
|
-
* and we mint a fresh session for it — independent of the web cookie
|
|
82
|
-
* session that originally `authorize`'d the code, so logging out on
|
|
83
|
-
* either side doesn't cascade to the other.
|
|
84
|
-
*
|
|
85
|
-
* Cookie attributes: defaults to `SameSite=None; Secure` so the cookie
|
|
86
|
-
* survives cross-site fetches from the desktop renderer's `file://` /
|
|
87
|
-
* `app://` origin. The configured base `cookieOptions` provide
|
|
88
|
-
* everything else (`domain`, `path`, `httpOnly`, `maxAge`); the override
|
|
89
|
-
* is targeted at the SameSite/Secure pair only. In a non-HTTPS dev
|
|
90
|
-
* backend this combination is rejected by Chromium — see the desktop
|
|
91
|
-
* sign-in PRD for workarounds.
|
|
92
|
-
*
|
|
93
|
-
* No CSRF check needed — the request carries no cookie, the auth code
|
|
94
|
-
* itself is the credential, and KV's single-use removal blocks replay.
|
|
95
|
-
*/
|
|
96
|
-
desktopExchange: (request: Request) => Promise<Response>;
|
|
97
|
-
sendPhoneVerificationCode: (_request: Request, _sender: (data: {
|
|
98
|
-
phone: string;
|
|
99
|
-
verificationCode: string;
|
|
100
|
-
}) => Promise<void>) => Promise<Response>;
|
|
101
|
-
loginPhone: (_request: Request, _handler: AuthorizedHandler) => Promise<Response>;
|
|
102
|
-
kick: (principal: Principal) => Promise<void>;
|
|
103
|
-
isAuthenticated: (request: Request) => Promise<boolean>;
|
|
104
|
-
getSession: <T extends boolean>(request: Request, create: T) => Promise<T extends true ? Session : Session | null>;
|
|
105
|
-
deleteSession: (sessionId: string) => Promise<void>;
|
|
106
|
-
getPrincipal: (request: Request) => Promise<Principal | null>;
|
|
107
|
-
listSessions: (principal: Principal) => Promise<Session[]>;
|
|
108
|
-
cleanupExpiredSessions: (cleanupCount?: number) => Promise<Response>;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export { Auth, PATH };
|
package/dist/auth/types.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/types.ts"],"sourcesContent":["import type { Principal } from '../core';\nimport type { OAuth2ClientConfig, OAuth2Token, UserInfo } from '../oauth2/types';\nimport type { KVRepository, Session, SessionRepository } from '../session/types';\nimport type { CookieOptions } from '../utils/http';\n\nexport type LoggedHandler = (principal: Principal) => Promise<void>;\nexport type AuthorizedHandler = (\n request: Request,\n registrationId: string,\n userInfo: UserInfo,\n token?: OAuth2Token\n) => Promise<Principal>;\n\nexport interface AuthConfig {\n timing?: boolean;\n kvRepository: KVRepository;\n sessionRepository: SessionRepository;\n cookie?: CookieOptions & { name?: string };\n turnstileSecretKey?: string;\n oauth2?: {\n client?: OAuth2ClientConfig;\n };\n}\n\nexport interface AuthService {\n // basic\n csrf: (request: Request) => Promise<Response>;\n logout: (request: Request) => Promise<Response>;\n logged: (request: Request, onLogged?: LoggedHandler) => Promise<Response>;\n\n // oauth2\n oauth2State: (request: Request) => Promise<Response>;\n oauth2Nonce: (request: Request) => Promise<Response>;\n oauth2Authorization: (request: Request) => Promise<Response>;\n loginOAuth2Code: (request: Request, onAuthorized: AuthorizedHandler) => Promise<Response>;\n loginOAuth2Native: (request: Request, onAuthorized: AuthorizedHandler) => Promise<Response>;\n loginOAuth2Onetap: (\n request: Request,\n onAuthorized: AuthorizedHandler,\n registrationId?: string\n ) => Promise<Response>;\n\n // email & phone\n sendEmailVerificationCode: (\n request: Request,\n sender: (data: { email: string; verificationCode: string }) => Promise<void>\n ) => Promise<Response>;\n sendPhoneVerificationCode: (\n request: Request,\n sender: (data: { phone: string; verificationCode: string }) => Promise<void>\n ) => Promise<Response>;\n\n loginEmail: (request: Request, onAuthorized: AuthorizedHandler) => Promise<Response>;\n loginPhone: (request: Request, onAuthorized: AuthorizedHandler) => Promise<Response>;\n\n // session management\n kick: (principal: Principal) => Promise<void>;\n isAuthenticated: (request: Request) => Promise<boolean>;\n getSession: <T extends boolean>(\n request: Request,\n create: T\n ) => Promise<T extends true ? Session : Session | null>;\n deleteSession: (sessionId: string) => Promise<void>;\n getPrincipal: (request: Request) => Promise<Principal | null>;\n listSessions: (principal: Principal) => Promise<Session[]>;\n cleanupExpiredSessions: (cleanupCount?: number) => Promise<Response>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/auth/types.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Principal } from '../core/index.js';
|
|
2
|
-
import { UserInfo, OAuth2Token, OAuth2ClientConfig } from '../oauth2/types.js';
|
|
3
|
-
import { Session, KVRepository, SessionRepository } from '../session/types.js';
|
|
4
|
-
import { CookieOptions } from '../utils/http.js';
|
|
5
|
-
import 'cookie';
|
|
6
|
-
|
|
7
|
-
type LoggedHandler = (principal: Principal) => Promise<void>;
|
|
8
|
-
type AuthorizedHandler = (request: Request, registrationId: string, userInfo: UserInfo, token?: OAuth2Token) => Promise<Principal>;
|
|
9
|
-
interface AuthConfig {
|
|
10
|
-
timing?: boolean;
|
|
11
|
-
kvRepository: KVRepository;
|
|
12
|
-
sessionRepository: SessionRepository;
|
|
13
|
-
cookie?: CookieOptions & {
|
|
14
|
-
name?: string;
|
|
15
|
-
};
|
|
16
|
-
turnstileSecretKey?: string;
|
|
17
|
-
oauth2?: {
|
|
18
|
-
client?: OAuth2ClientConfig;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
interface AuthService {
|
|
22
|
-
csrf: (request: Request) => Promise<Response>;
|
|
23
|
-
logout: (request: Request) => Promise<Response>;
|
|
24
|
-
logged: (request: Request, onLogged?: LoggedHandler) => Promise<Response>;
|
|
25
|
-
oauth2State: (request: Request) => Promise<Response>;
|
|
26
|
-
oauth2Nonce: (request: Request) => Promise<Response>;
|
|
27
|
-
oauth2Authorization: (request: Request) => Promise<Response>;
|
|
28
|
-
loginOAuth2Code: (request: Request, onAuthorized: AuthorizedHandler) => Promise<Response>;
|
|
29
|
-
loginOAuth2Native: (request: Request, onAuthorized: AuthorizedHandler) => Promise<Response>;
|
|
30
|
-
loginOAuth2Onetap: (request: Request, onAuthorized: AuthorizedHandler, registrationId?: string) => Promise<Response>;
|
|
31
|
-
sendEmailVerificationCode: (request: Request, sender: (data: {
|
|
32
|
-
email: string;
|
|
33
|
-
verificationCode: string;
|
|
34
|
-
}) => Promise<void>) => Promise<Response>;
|
|
35
|
-
sendPhoneVerificationCode: (request: Request, sender: (data: {
|
|
36
|
-
phone: string;
|
|
37
|
-
verificationCode: string;
|
|
38
|
-
}) => Promise<void>) => Promise<Response>;
|
|
39
|
-
loginEmail: (request: Request, onAuthorized: AuthorizedHandler) => Promise<Response>;
|
|
40
|
-
loginPhone: (request: Request, onAuthorized: AuthorizedHandler) => Promise<Response>;
|
|
41
|
-
kick: (principal: Principal) => Promise<void>;
|
|
42
|
-
isAuthenticated: (request: Request) => Promise<boolean>;
|
|
43
|
-
getSession: <T extends boolean>(request: Request, create: T) => Promise<T extends true ? Session : Session | null>;
|
|
44
|
-
deleteSession: (sessionId: string) => Promise<void>;
|
|
45
|
-
getPrincipal: (request: Request) => Promise<Principal | null>;
|
|
46
|
-
listSessions: (principal: Principal) => Promise<Session[]>;
|
|
47
|
-
cleanupExpiredSessions: (cleanupCount?: number) => Promise<Response>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export type { AuthConfig, AuthService, AuthorizedHandler, LoggedHandler };
|
package/dist/auth/types.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/core/index.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
type JSONValue = null | string | number | boolean | {
|
|
2
|
-
[value: string]: JSONValue;
|
|
3
|
-
} | Array<JSONValue>;
|
|
4
|
-
interface Principal {
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
7
|
-
interface Authentication extends Principal {
|
|
8
|
-
authorities: string[];
|
|
9
|
-
authenticated: boolean;
|
|
10
|
-
}
|
|
11
|
-
interface CsrfToken {
|
|
12
|
-
token: string;
|
|
13
|
-
headerName: string;
|
|
14
|
-
parameterName: string;
|
|
15
|
-
}
|
|
16
|
-
declare enum Provider {
|
|
17
|
-
APPLE = "APPLE",
|
|
18
|
-
DISCORD = "DISCORD",
|
|
19
|
-
FACEBOOK = "FACEBOOK",
|
|
20
|
-
GITHUB = "GITHUB",
|
|
21
|
-
GOOGLE = "GOOGLE",
|
|
22
|
-
LINKEDIN = "LINKEDIN",
|
|
23
|
-
MICROSOFT = "MICROSOFT",
|
|
24
|
-
SLACK = "SLACK",
|
|
25
|
-
WECHAT = "WECHAT",
|
|
26
|
-
X = "X",
|
|
27
|
-
EMAIL = "EMAIL",
|
|
28
|
-
PHONE = "PHONE"
|
|
29
|
-
}
|
|
30
|
-
declare const ALL_PROVIDERS: readonly [Provider.APPLE, Provider.DISCORD, Provider.FACEBOOK, Provider.GITHUB, Provider.GOOGLE, Provider.LINKEDIN, Provider.MICROSOFT, Provider.SLACK, Provider.WECHAT, Provider.X, Provider.EMAIL, Provider.PHONE];
|
|
31
|
-
|
|
32
|
-
export { ALL_PROVIDERS, type Authentication, type CsrfToken, type JSONValue, type Principal, Provider };
|
package/dist/email/schema.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as zod_v4_core from 'zod/v4/core';
|
|
2
|
-
import * as zod_mini from 'zod/mini';
|
|
3
|
-
|
|
4
|
-
declare const sendEmailVerificationCodeSchema: zod_mini.ZodMiniObject<{
|
|
5
|
-
email: zod_mini.ZodMiniEmail;
|
|
6
|
-
turnstileToken: zod_mini.ZodMiniString<string>;
|
|
7
|
-
}, zod_v4_core.$strip>;
|
|
8
|
-
declare const loginEmailSchema: zod_mini.ZodMiniObject<{
|
|
9
|
-
email: zod_mini.ZodMiniEmail;
|
|
10
|
-
verificationCode: zod_mini.ZodMiniString<string>;
|
|
11
|
-
}, zod_v4_core.$strip>;
|
|
12
|
-
|
|
13
|
-
export { loginEmailSchema, sendEmailVerificationCodeSchema };
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { Auth, PATH } from './auth/index';\nexport { OAuth2Client, oauth2RedirectQuerySchema } from './oauth2/client';\nexport { RedisIndexedSessionRepository, RedisKVRepository } from './session/redis';\nexport { DBIndexedSessionRepository } from './session/db';\nexport { PRINCIPAL_NAME_INDEX_NAME } from './session/common';\nexport { Provider, ALL_PROVIDERS } from './core/index';\n\nexport type { Principal, CsrfToken } from './core/index';\nexport type { DBAdapter } from './session/db';\nexport type { Namespace, SessionRepository, Session, KVRepository } from './session/types';\nexport type {\n NativeCredential,\n OAuth2Token,\n OidcToken,\n OidcScopes,\n StandardClaims,\n UserInfo,\n} from './oauth2/types';\nexport type { AuthConfig, AuthService } from './auth/types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2B;AAC3B,oBAAwD;AACxD,mBAAiE;AACjE,gBAA2C;AAC3C,oBAA0C;AAC1C,kBAAwC;","names":[]}
|
package/dist/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export { Auth, PATH } from './auth/index.js';
|
|
2
|
-
export { OAuth2Client, oauth2RedirectQuerySchema } from './oauth2/client.js';
|
|
3
|
-
export { RedisIndexedSessionRepository, RedisKVRepository } from './session/redis.js';
|
|
4
|
-
export { DBAdapter, DBIndexedSessionRepository } from './session/db.js';
|
|
5
|
-
export { PRINCIPAL_NAME_INDEX_NAME } from './session/common.js';
|
|
6
|
-
export { ALL_PROVIDERS, CsrfToken, Principal, Provider } from './core/index.js';
|
|
7
|
-
export { KVRepository, Namespace, Session, SessionRepository } from './session/types.js';
|
|
8
|
-
export { NativeCredential, OAuth2Token, OidcScopes, OidcToken, StandardClaims, UserInfo } from './oauth2/types.js';
|
|
9
|
-
export { AuthConfig, AuthService } from './auth/types.js';
|
|
10
|
-
import 'zod/v4/core';
|
|
11
|
-
import 'zod/mini';
|
|
12
|
-
import 'ioredis';
|
|
13
|
-
import './session/map-session.js';
|
|
14
|
-
import './utils/http.js';
|
|
15
|
-
import 'cookie';
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { Auth, PATH } from './auth/index';\nexport { OAuth2Client, oauth2RedirectQuerySchema } from './oauth2/client';\nexport { RedisIndexedSessionRepository, RedisKVRepository } from './session/redis';\nexport { DBIndexedSessionRepository } from './session/db';\nexport { PRINCIPAL_NAME_INDEX_NAME } from './session/common';\nexport { Provider, ALL_PROVIDERS } from './core/index';\n\nexport type { Principal, CsrfToken } from './core/index';\nexport type { DBAdapter } from './session/db';\nexport type { Namespace, SessionRepository, Session, KVRepository } from './session/types';\nexport type {\n NativeCredential,\n OAuth2Token,\n OidcToken,\n OidcScopes,\n StandardClaims,\n UserInfo,\n} from './oauth2/types';\nexport type { AuthConfig, AuthService } from './auth/types';\n"],"mappings":";AAAA,SAAS,MAAM,YAAY;AAC3B,SAAS,cAAc,iCAAiC;AACxD,SAAS,+BAA+B,yBAAyB;AACjE,SAAS,kCAAkC;AAC3C,SAAS,iCAAiC;AAC1C,SAAS,UAAU,qBAAqB;","names":[]}
|
package/dist/oauth2/client.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { OAuth2ClientConfig, PkceParameters, OAuth2Token, OidcToken, UserInfo, NativeCredential } from './types.js';
|
|
2
|
-
import * as zod_v4_core from 'zod/v4/core';
|
|
3
|
-
import * as zod_mini from 'zod/mini';
|
|
4
|
-
|
|
5
|
-
declare const oauth2RedirectQuerySchema: zod_mini.ZodMiniObject<{
|
|
6
|
-
code: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
7
|
-
state: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
8
|
-
error: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
9
|
-
error_description: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
10
|
-
error_uri: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
11
|
-
}, zod_v4_core.$strip>;
|
|
12
|
-
declare const googleOneTapSchema: zod_mini.ZodMiniObject<{
|
|
13
|
-
code: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
14
|
-
state: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
15
|
-
error: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
16
|
-
error_description: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
17
|
-
error_uri: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
18
|
-
nonce: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
19
|
-
g_csrf_token: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
20
|
-
hd: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
21
|
-
credential: zod_mini.ZodMiniOptional<zod_mini.ZodMiniString<string>>;
|
|
22
|
-
}, zod_v4_core.$strip>;
|
|
23
|
-
declare class OAuth2Client {
|
|
24
|
-
private config;
|
|
25
|
-
constructor(config: OAuth2ClientConfig);
|
|
26
|
-
get baseUri(): string;
|
|
27
|
-
get successUri(): string;
|
|
28
|
-
get errorUri(): string;
|
|
29
|
-
private getClientConfig;
|
|
30
|
-
createAuthorizationUri({ registrationId, state, pkce, }: {
|
|
31
|
-
registrationId: string;
|
|
32
|
-
state: string;
|
|
33
|
-
pkce?: PkceParameters;
|
|
34
|
-
}): Promise<URL>;
|
|
35
|
-
exchangeAuthorizationCode({ registrationId, code, pkce, }: {
|
|
36
|
-
registrationId: string;
|
|
37
|
-
code: string;
|
|
38
|
-
pkce?: PkceParameters;
|
|
39
|
-
}): Promise<OAuth2Token>;
|
|
40
|
-
getUserInfo({ registrationId, token, }: {
|
|
41
|
-
registrationId: string;
|
|
42
|
-
token: OAuth2Token | OidcToken;
|
|
43
|
-
}): Promise<UserInfo<unknown>>;
|
|
44
|
-
refreshAccessToken({ registrationId, refreshToken, }: {
|
|
45
|
-
registrationId: string;
|
|
46
|
-
refreshToken: string;
|
|
47
|
-
}): Promise<OAuth2Token>;
|
|
48
|
-
revokeToken(registrationId: string, token: string): Promise<void>;
|
|
49
|
-
loginOAuth2Native({ registrationId, credentials, pkce, }: {
|
|
50
|
-
registrationId: string;
|
|
51
|
-
credentials: NativeCredential;
|
|
52
|
-
pkce?: PkceParameters;
|
|
53
|
-
}): Promise<{
|
|
54
|
-
token: OAuth2Token;
|
|
55
|
-
userInfo: UserInfo;
|
|
56
|
-
}>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { OAuth2Client, googleOneTapSchema, oauth2RedirectQuerySchema };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { NativeCredential, OAuth2Token, Provider } from '../types.js';
|
|
2
|
-
|
|
3
|
-
declare function createAppleProvider(): Provider;
|
|
4
|
-
declare const apple: Provider;
|
|
5
|
-
interface AppleUserInfo {
|
|
6
|
-
sub: string;
|
|
7
|
-
email: string;
|
|
8
|
-
email_verified: true | 'true';
|
|
9
|
-
is_private_email: boolean;
|
|
10
|
-
real_user_status: number;
|
|
11
|
-
name: string;
|
|
12
|
-
picture: string;
|
|
13
|
-
user?: {
|
|
14
|
-
name: {
|
|
15
|
-
firstName: string;
|
|
16
|
-
lastName: string;
|
|
17
|
-
};
|
|
18
|
-
email: string;
|
|
19
|
-
};
|
|
20
|
-
nonce?: string;
|
|
21
|
-
nonce_supported?: boolean;
|
|
22
|
-
}
|
|
23
|
-
interface AppleToken extends OAuth2Token {
|
|
24
|
-
access_token: string;
|
|
25
|
-
token_type: string;
|
|
26
|
-
expires_in: number;
|
|
27
|
-
refresh_token: string;
|
|
28
|
-
id_token: string;
|
|
29
|
-
}
|
|
30
|
-
interface AppleNativeCredential extends NativeCredential {
|
|
31
|
-
state: string;
|
|
32
|
-
code: string;
|
|
33
|
-
id_token: string;
|
|
34
|
-
user: string;
|
|
35
|
-
email?: string;
|
|
36
|
-
}
|
|
37
|
-
interface AppleErrorResponse {
|
|
38
|
-
error: 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'unauthorized_client' | 'unsupported_grant_type' | 'invalid_scope';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { type AppleErrorResponse, type AppleNativeCredential, type AppleToken, type AppleUserInfo, apple, createAppleProvider };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { PkceParameters, ExchangeCodeParams, RefreshTokenParams } from '../types.js';
|
|
2
|
-
|
|
3
|
-
declare function createAuthorizationUri(options: {
|
|
4
|
-
state: string;
|
|
5
|
-
scope: string[];
|
|
6
|
-
clientId: string;
|
|
7
|
-
redirectUri: string;
|
|
8
|
-
authorizationUri: string;
|
|
9
|
-
pkce?: Omit<PkceParameters, 'code_verifier'>;
|
|
10
|
-
}): URL;
|
|
11
|
-
declare function exchangeAuthorizationCode(params: ExchangeCodeParams & {
|
|
12
|
-
tokenUri: string;
|
|
13
|
-
authentication?: 'basic' | 'post';
|
|
14
|
-
}): Promise<Response>;
|
|
15
|
-
declare function refreshAccessToken(params: RefreshTokenParams & {
|
|
16
|
-
tokenUri: string;
|
|
17
|
-
authentication?: 'basic' | 'post';
|
|
18
|
-
}): Promise<Response>;
|
|
19
|
-
interface RevokeTokenParams {
|
|
20
|
-
token: string;
|
|
21
|
-
clientId: string;
|
|
22
|
-
clientSecret: string;
|
|
23
|
-
tokenRevokeUri: string;
|
|
24
|
-
authentication?: 'basic' | 'post';
|
|
25
|
-
}
|
|
26
|
-
declare function revokeToken(params: RevokeTokenParams): Promise<void>;
|
|
27
|
-
declare function verifyIdToken<T>(idToken: string, jwkSetUri: string): Promise<T>;
|
|
28
|
-
|
|
29
|
-
export { createAuthorizationUri, exchangeAuthorizationCode, refreshAccessToken, revokeToken, verifyIdToken };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { OAuth2Token, Provider } from '../types.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ref: https://developers.facebook.com/docs/facebook-login/guides/advanced/manual-flow/
|
|
5
|
-
* ref: https://developers.facebook.com/tools/explorer
|
|
6
|
-
* */
|
|
7
|
-
declare function createFacebookProvider(): Provider;
|
|
8
|
-
declare const facebook: Provider;
|
|
9
|
-
interface FacebookDecodedIdToken {
|
|
10
|
-
sub: string;
|
|
11
|
-
name: string;
|
|
12
|
-
email: string;
|
|
13
|
-
picture: string;
|
|
14
|
-
nonce?: string;
|
|
15
|
-
}
|
|
16
|
-
interface FacebookUserInfo {
|
|
17
|
-
id: string;
|
|
18
|
-
name: string;
|
|
19
|
-
email: string;
|
|
20
|
-
email_verified: boolean;
|
|
21
|
-
picture: {
|
|
22
|
-
data: {
|
|
23
|
-
url: string;
|
|
24
|
-
width: number;
|
|
25
|
-
height: number;
|
|
26
|
-
is_silhouette: boolean;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
interface FacebookToken extends OAuth2Token {
|
|
31
|
-
access_token: string;
|
|
32
|
-
token_type: 'bearer';
|
|
33
|
-
expires_in: number;
|
|
34
|
-
id_token?: string;
|
|
35
|
-
}
|
|
36
|
-
type FacebookAppCredential = {
|
|
37
|
-
state: string;
|
|
38
|
-
id_token: string;
|
|
39
|
-
} | {
|
|
40
|
-
state: string;
|
|
41
|
-
access_token: string;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export { type FacebookAppCredential, type FacebookDecodedIdToken, type FacebookToken, type FacebookUserInfo, createFacebookProvider, facebook };
|