@voltro/plugin-auth 0.86.0 → 0.87.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 +5321 -0
- package/README.md +83 -0
- package/THIRD-PARTY-NOTICES.md +1130 -11
- package/dist/authExtensions.js +9 -0
- package/dist/emailVerification.js +13 -11
- package/dist/guest.d.ts +99 -0
- package/dist/guest.js +3 -0
- package/dist/guestClient.js +237 -0
- package/dist/guestCredential.js +12 -0
- package/dist/guestPasswordUpgrade.js +85 -0
- package/dist/guestPlugin.js +166 -0
- package/dist/guestSchema.js +20 -0
- package/dist/guestSecrets.js +10 -0
- package/dist/guestService.js +224 -0
- package/dist/handlers.js +113 -113
- package/dist/impersonation.js +79 -78
- package/dist/index.d.ts +265 -15
- package/dist/index.js +27 -19
- package/dist/invitations.js +23 -23
- package/dist/native/guestStorage.js +41 -0
- package/dist/native.d.ts +110 -0
- package/dist/native.js +45 -43
- package/dist/nativeRoutes.js +61 -72
- package/dist/overlayPlugin.js +167 -0
- package/dist/plugin.d.ts +119 -10
- package/dist/plugin.js +99 -78
- package/dist/postgresUserStore.js +19 -7
- package/dist/revocation.js +40 -23
- package/dist/schema.d.ts +41 -1
- package/dist/schema.js +99 -98
- package/dist/sessionFamily.js +15 -0
- package/dist/sessionRegistry.js +93 -78
- package/dist/signedClaims.js +24 -0
- package/dist/strategy.d.ts +13 -9
- package/dist/strategy.js +26 -22
- package/dist/userStore.js +145 -138
- package/dist/web/guestStorage.js +47 -0
- package/dist/web.d.ts +94 -0
- package/dist/web.js +4 -2
- package/package.json +8 -3
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { GuestClientError as e } from "../guestClient.js";
|
|
2
|
+
//#region src/native/guestStorage.ts
|
|
3
|
+
var t = /* @__PURE__ */ new Set([
|
|
4
|
+
"keychain",
|
|
5
|
+
"keystore",
|
|
6
|
+
"credential-manager",
|
|
7
|
+
"stronghold"
|
|
8
|
+
]), n = () => new e("storage_unavailable"), r = (r) => {
|
|
9
|
+
let i;
|
|
10
|
+
try {
|
|
11
|
+
if (!r.namespace.trim() || !t.has(r.store.kind) || typeof r.exclusive != "function" || typeof r.store.get != "function" || typeof r.store.set != "function" || typeof r.store.delete != "function") throw n();
|
|
12
|
+
i = "voltro:guest:" + encodeURIComponent(r.namespace);
|
|
13
|
+
} catch {
|
|
14
|
+
throw n();
|
|
15
|
+
}
|
|
16
|
+
let a = async (e) => {
|
|
17
|
+
try {
|
|
18
|
+
return await e();
|
|
19
|
+
} catch {
|
|
20
|
+
throw n();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
exclusive: async (t) => {
|
|
25
|
+
try {
|
|
26
|
+
return await r.exclusive(i, t);
|
|
27
|
+
} catch (t) {
|
|
28
|
+
throw t instanceof e ? t : n();
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
read: () => a(async () => {
|
|
32
|
+
let e = await r.store.get(i);
|
|
33
|
+
if (e !== null && typeof e != "string") throw n();
|
|
34
|
+
return e;
|
|
35
|
+
}),
|
|
36
|
+
write: (e) => a(() => r.store.set(i, e)),
|
|
37
|
+
remove: () => a(() => r.store.delete(i))
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { r as nativeGuestStore };
|
package/dist/native.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Subject } from '@voltro/protocol';
|
|
2
|
+
import { SubjectIdentity } from '@voltro/protocol';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Mint the verifier + state and build the authorize URL. Nothing is sent yet;
|
|
@@ -6,6 +7,40 @@ import { Subject } from '@voltro/protocol';
|
|
|
6
7
|
*/
|
|
7
8
|
export declare const beginNativeLogin: (options: NativeLoginOptions) => Promise<NativeLoginHandoff>;
|
|
8
9
|
|
|
10
|
+
/** Serializes operations in one client. A rejected existing credential never
|
|
11
|
+
* creates a replacement identity. Storage failures never enable memory fallback. */
|
|
12
|
+
export declare const createGuestClient: (options: GuestClientOptions) => {
|
|
13
|
+
connect: () => Promise<GuestClientSession>;
|
|
14
|
+
/** Prepare without replacing the active proof, persist both proofs, then
|
|
15
|
+
* commit. A later connect recovers the same identity after a lost response. */
|
|
16
|
+
rotate: () => Promise<GuestClientSession>;
|
|
17
|
+
/** Revoke on the server first. Keep the durable proof on transport failure
|
|
18
|
+
* so the caller can retry; erase locally only after confirmed revocation. */
|
|
19
|
+
revoke: () => Promise<void>;
|
|
20
|
+
/** Turn this guest into an email/password account under the same subject ID
|
|
21
|
+
* (`authRoutesPlugin({ guestUpgrade })`). The device proof is erased only after the
|
|
22
|
+
* server confirmed the account; on any refusal or transport failure it stays. */
|
|
23
|
+
upgrade: (input: {
|
|
24
|
+
readonly email: string;
|
|
25
|
+
readonly password: string;
|
|
26
|
+
}) => Promise<{
|
|
27
|
+
readonly subject: unknown;
|
|
28
|
+
}>;
|
|
29
|
+
/** The registered account signed in on this device (cookie clients), or null. */
|
|
30
|
+
account: () => Promise<GuestClientAccount | null>;
|
|
31
|
+
/** The signed-in account if there is one, else this device's guest (resumed or created once).
|
|
32
|
+
* The usual entry for a game that offers accounts: a reload after `upgrade` or `signIn` stays the account. */
|
|
33
|
+
start: () => Promise<GuestClientPlayer>;
|
|
34
|
+
/** Sign in to an existing account with email and password (`authRoutesPlugin`), e.g. on a second
|
|
35
|
+
* device. This device's guest proof stays: after `signOut`, `start` resumes that guest. */
|
|
36
|
+
signIn: (input: {
|
|
37
|
+
readonly email: string;
|
|
38
|
+
readonly password: string;
|
|
39
|
+
}) => Promise<GuestClientAccount>;
|
|
40
|
+
/** End the account session on the server and clear its cookie. */
|
|
41
|
+
signOut: () => Promise<void>;
|
|
42
|
+
};
|
|
43
|
+
|
|
9
44
|
/** Trade the code + verifier for the session value. */
|
|
10
45
|
export declare const exchangeNativeCode: (input: {
|
|
11
46
|
readonly code: string;
|
|
@@ -14,6 +49,61 @@ export declare const exchangeNativeCode: (input: {
|
|
|
14
49
|
readonly fetch?: typeof fetch;
|
|
15
50
|
}) => Promise<NativeSession>;
|
|
16
51
|
|
|
52
|
+
/** A registered account signed in on this device (by upgrade or sign-in), through the session cookie. */
|
|
53
|
+
declare interface GuestClientAccount {
|
|
54
|
+
readonly subject: Extract<SubjectIdentity, {
|
|
55
|
+
readonly type: 'user';
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export declare class GuestClientError extends Error {
|
|
60
|
+
readonly code: 'storage_unavailable' | 'credential_rejected' | 'upgrade_conflict' | 'account_signed_in' | 'transport_failed' | 'invalid_response';
|
|
61
|
+
readonly status?: number | undefined;
|
|
62
|
+
constructor(code: 'storage_unavailable' | 'credential_rejected' | 'upgrade_conflict' | 'account_signed_in' | 'transport_failed' | 'invalid_response', status?: number | undefined);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export declare interface GuestClientOptions {
|
|
66
|
+
readonly apiBaseUrl: string;
|
|
67
|
+
readonly storage: GuestCredentialStore;
|
|
68
|
+
readonly prefix?: string;
|
|
69
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
70
|
+
/** Web clients include cookies and obtain a signed CSRF token for each post. */
|
|
71
|
+
readonly cookies?: boolean;
|
|
72
|
+
/** Prefix of the app's auth routes, for `upgrade`, `account`, `signIn` and `signOut` (default `/auth`). */
|
|
73
|
+
readonly accountPrefix?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** What `start` found: the signed-in account, else this device's guest. */
|
|
77
|
+
declare type GuestClientPlayer = {
|
|
78
|
+
readonly kind: 'account';
|
|
79
|
+
readonly subject: GuestClientAccount['subject'];
|
|
80
|
+
} | {
|
|
81
|
+
readonly kind: 'guest';
|
|
82
|
+
readonly subject: GuestClientSession['subject'];
|
|
83
|
+
readonly session: string;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export declare interface GuestClientSession {
|
|
87
|
+
readonly subject: Extract<SubjectIdentity, {
|
|
88
|
+
readonly type: 'user';
|
|
89
|
+
}> & {
|
|
90
|
+
readonly kind: 'guest';
|
|
91
|
+
};
|
|
92
|
+
readonly session: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Platform-backed durable secret storage. Native implementations use the
|
|
96
|
+
* operating system's secure store; writes resolve only after persistence. */
|
|
97
|
+
export declare interface GuestCredentialStore {
|
|
98
|
+
/** Serialize the whole read/create/write operation across users of this
|
|
99
|
+
* namespace, including other browser tabs or native client instances. */
|
|
100
|
+
readonly exclusive: <A>(work: () => Promise<A>) => Promise<A>;
|
|
101
|
+
readonly read: () => Promise<string | null>;
|
|
102
|
+
/** Persist the opaque value, including an in-progress rotation journal. */
|
|
103
|
+
readonly write: (value: string) => Promise<void>;
|
|
104
|
+
readonly remove: () => Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
|
|
17
107
|
export declare type NativeCallback = {
|
|
18
108
|
readonly kind: 'code';
|
|
19
109
|
readonly code: string;
|
|
@@ -40,6 +130,26 @@ export declare class NativeExchangeError extends Error {
|
|
|
40
130
|
constructor(status: number, code: string);
|
|
41
131
|
}
|
|
42
132
|
|
|
133
|
+
/** Adapt an explicitly supplied durable native store and host-wide lock.
|
|
134
|
+
* Refuse memory/unwired stores; never select a fallback or initialize a store. */
|
|
135
|
+
export declare const nativeGuestStore: (options: NativeGuestStoreOptions) => GuestCredentialStore;
|
|
136
|
+
|
|
137
|
+
/** Structurally accepts a platform TokenStore without importing a UI runtime. */
|
|
138
|
+
export declare interface NativeGuestStoreOptions {
|
|
139
|
+
/** App/tenant namespace; storage and the host lock use the same exact key. */
|
|
140
|
+
readonly namespace: string;
|
|
141
|
+
readonly store: {
|
|
142
|
+
readonly kind: string;
|
|
143
|
+
readonly get: (key: string) => Promise<string | null>;
|
|
144
|
+
readonly set: (key: string, value: string) => Promise<void>;
|
|
145
|
+
readonly delete: (key: string) => Promise<void>;
|
|
146
|
+
};
|
|
147
|
+
/** The host must serialize all client instances, including other processes.
|
|
148
|
+
* Release the lock after both success and failure; writes must be durable
|
|
149
|
+
* before resolving. A process-local Promise queue does not meet this contract. */
|
|
150
|
+
readonly exclusive: <A>(key: string, work: () => Promise<A>) => Promise<A>;
|
|
151
|
+
}
|
|
152
|
+
|
|
43
153
|
export declare interface NativeLoginHandoff {
|
|
44
154
|
/** Open this in the SYSTEM browser (not an in-app webview): the user's
|
|
45
155
|
* existing browser session and password manager are the point. */
|
package/dist/native.js
CHANGED
|
@@ -1,42 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GuestClientError as e, createGuestClient as t } from "./guestClient.js";
|
|
2
|
+
import { nativeGuestStore as n } from "./native/guestStorage.js";
|
|
3
|
+
import { SESSION_HEADER_NAME as r } from "@voltro/protocol";
|
|
2
4
|
//#region src/native/index.ts
|
|
3
|
-
var
|
|
5
|
+
var i = (e) => {
|
|
4
6
|
let t = "";
|
|
5
7
|
for (let n of e) t += String.fromCharCode(n);
|
|
6
8
|
return (typeof btoa == "function" ? btoa(t) : globalThis.Buffer.from(t, "binary").toString("base64")).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
7
|
-
},
|
|
9
|
+
}, a = (e) => {
|
|
8
10
|
let t = new Uint8Array(e.length);
|
|
9
11
|
for (let n = 0; n < e.length; n++) t[n] = e.charCodeAt(n) & 127;
|
|
10
12
|
return t;
|
|
11
|
-
},
|
|
12
|
-
let
|
|
13
|
+
}, o = (e) => e.replace(/\/+$/, ""), s = async (e, t) => i(await t.sha256(a(e))), c = async (e) => {
|
|
14
|
+
let t = i(e.crypto.randomBytes(32)), n = i(e.crypto.randomBytes(16)), r = await s(t, e.crypto), a = new URLSearchParams({
|
|
13
15
|
redirect_uri: e.redirectUri,
|
|
14
|
-
code_challenge:
|
|
16
|
+
code_challenge: r,
|
|
15
17
|
code_challenge_method: "S256",
|
|
16
|
-
state:
|
|
18
|
+
state: n
|
|
17
19
|
}), c = e.prefix ?? "/auth";
|
|
18
20
|
return {
|
|
19
|
-
url: `${
|
|
20
|
-
codeVerifier:
|
|
21
|
-
state:
|
|
21
|
+
url: `${o(e.apiBaseUrl)}${c}/native/authorize?${a.toString()}`,
|
|
22
|
+
codeVerifier: t,
|
|
23
|
+
state: n
|
|
22
24
|
};
|
|
23
|
-
},
|
|
24
|
-
let
|
|
25
|
-
if (r
|
|
25
|
+
}, l = (e, t, n) => {
|
|
26
|
+
let r = e.indexOf("?");
|
|
27
|
+
if (o(r === -1 ? e : e.slice(0, r)) !== o(n)) return {
|
|
26
28
|
kind: "ignored",
|
|
27
29
|
reason: "not-the-callback"
|
|
28
30
|
};
|
|
29
|
-
let
|
|
30
|
-
if (
|
|
31
|
+
let i = new URLSearchParams(r === -1 ? "" : e.slice(r + 1));
|
|
32
|
+
if (i.get("state") !== t.state) return {
|
|
31
33
|
kind: "ignored",
|
|
32
34
|
reason: "state-mismatch"
|
|
33
35
|
};
|
|
34
|
-
let
|
|
35
|
-
if (
|
|
36
|
+
let a = i.get("error");
|
|
37
|
+
if (a) return {
|
|
36
38
|
kind: "error",
|
|
37
|
-
error:
|
|
39
|
+
error: a
|
|
38
40
|
};
|
|
39
|
-
let s =
|
|
41
|
+
let s = i.get("code");
|
|
40
42
|
return s ? {
|
|
41
43
|
kind: "code",
|
|
42
44
|
code: s
|
|
@@ -44,43 +46,43 @@ var t = (e) => {
|
|
|
44
46
|
kind: "ignored",
|
|
45
47
|
reason: "no-code"
|
|
46
48
|
};
|
|
47
|
-
},
|
|
49
|
+
}, u = class extends Error {
|
|
48
50
|
status;
|
|
49
51
|
code;
|
|
50
52
|
constructor(e, t) {
|
|
51
53
|
super(`native login exchange failed: ${t} (${e})`), this.name = "NativeExchangeError", this.status = e, this.code = t;
|
|
52
54
|
}
|
|
53
|
-
},
|
|
54
|
-
let n = t.fetch ?? fetch,
|
|
55
|
+
}, d = async (e, t) => {
|
|
56
|
+
let n = t.fetch ?? fetch, r = t.prefix ?? "/auth", i = await n(`${o(t.apiBaseUrl)}${r}/native/exchange`, {
|
|
55
57
|
method: "POST",
|
|
56
58
|
headers: { "content-type": "application/json" },
|
|
57
59
|
body: JSON.stringify(e)
|
|
58
|
-
}),
|
|
59
|
-
if (!
|
|
60
|
+
}), a = await i.json().catch(() => ({}));
|
|
61
|
+
if (!i.ok || typeof a.session != "string" || typeof a.expiresAt != "number" || !a.subject) throw new u(i.status, a.error ?? "invalid_response");
|
|
60
62
|
return {
|
|
61
|
-
session:
|
|
62
|
-
expiresAt:
|
|
63
|
-
subject:
|
|
63
|
+
session: a.session,
|
|
64
|
+
expiresAt: a.expiresAt,
|
|
65
|
+
subject: a.subject
|
|
64
66
|
};
|
|
65
|
-
},
|
|
66
|
-
let n = t.fetch ?? fetch,
|
|
67
|
+
}, f = (e) => ({ [r]: e }), p = async (e, t) => {
|
|
68
|
+
let n = t.fetch ?? fetch, r = t.prefix ?? "/auth", i = await n(`${o(t.apiBaseUrl)}${r}/session`, {
|
|
67
69
|
method: "GET",
|
|
68
|
-
headers:
|
|
70
|
+
headers: f(e)
|
|
69
71
|
});
|
|
70
|
-
if (
|
|
71
|
-
let
|
|
72
|
-
return !
|
|
73
|
-
session:
|
|
74
|
-
expiresAt:
|
|
75
|
-
subject:
|
|
72
|
+
if (i.status === 401) return null;
|
|
73
|
+
let a = await i.json().catch(() => ({}));
|
|
74
|
+
return !i.ok || a.ok !== !0 || !a.subject || typeof a.expiresAt != "number" ? null : {
|
|
75
|
+
session: a.session ?? e,
|
|
76
|
+
expiresAt: a.expiresAt,
|
|
77
|
+
subject: a.subject
|
|
76
78
|
};
|
|
77
|
-
},
|
|
78
|
-
let t = await
|
|
79
|
+
}, m = async (e) => {
|
|
80
|
+
let t = await c(e);
|
|
79
81
|
await e.open(t.url);
|
|
80
|
-
let n = await e.awaitCallback((n) =>
|
|
81
|
-
if (n.kind === "error") throw new
|
|
82
|
-
if (n.kind !== "code") throw new
|
|
83
|
-
return
|
|
82
|
+
let n = await e.awaitCallback((n) => l(n, t, e.redirectUri));
|
|
83
|
+
if (n.kind === "error") throw new u(0, n.error);
|
|
84
|
+
if (n.kind !== "code") throw new u(0, n.reason);
|
|
85
|
+
return d({
|
|
84
86
|
code: n.code,
|
|
85
87
|
codeVerifier: t.codeVerifier
|
|
86
88
|
}, {
|
|
@@ -90,4 +92,4 @@ var t = (e) => {
|
|
|
90
92
|
});
|
|
91
93
|
};
|
|
92
94
|
//#endregion
|
|
93
|
-
export {
|
|
95
|
+
export { e as GuestClientError, u as NativeExchangeError, c as beginNativeLogin, t as createGuestClient, d as exchangeNativeCode, s as nativeCodeChallenge, n as nativeGuestStore, l as parseNativeCallback, p as probeNativeSession, m as runNativeLogin, f as sessionHeaders };
|
package/dist/nativeRoutes.js
CHANGED
|
@@ -1,37 +1,23 @@
|
|
|
1
1
|
import { hashToken as e, mintToken as t } from "./tokens.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { configSessionSecrets as n, issueUserSession as r } from "./handlers.js";
|
|
3
|
+
import { signAuthClaims as i, verifyAuthClaims as a } from "./signedClaims.js";
|
|
4
|
+
import { createHash as o, randomBytes as s } from "node:crypto";
|
|
4
5
|
import { Effect as c } from "effect";
|
|
5
6
|
import { buildSetCookie as l, readCookie as u } from "@voltro/protocol/session";
|
|
6
7
|
//#region src/nativeRoutes.ts
|
|
7
|
-
var d = "voltro:native", f = 600, p = "/login", m = (e) => e.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), h = (e) =>
|
|
8
|
-
let n = m(Buffer.from(JSON.stringify(e), "utf8"));
|
|
9
|
-
return `${n}.${m(a("sha256", t).update(n).digest())}`;
|
|
10
|
-
}, v = (e, t, n = Date.now) => {
|
|
11
|
-
if (!e) return null;
|
|
12
|
-
let r = e.indexOf(".");
|
|
13
|
-
if (r <= 0 || r === e.length - 1) return null;
|
|
14
|
-
let i = e.slice(0, r), o = h(e.slice(r + 1)), c = a("sha256", t).update(i).digest();
|
|
15
|
-
if (o.length !== c.length || !s(o, c)) return null;
|
|
16
|
-
try {
|
|
17
|
-
let e = JSON.parse(h(i).toString("utf8"));
|
|
18
|
-
return typeof e.exp != "number" || e.exp * 1e3 < n() ? null : e;
|
|
19
|
-
} catch {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
}, y = (e, t) => t.includes(e), b = (e, t) => {
|
|
8
|
+
var d = "voltro:native", f = 600, p = "/login", m = (e) => e.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), h = (e) => m(o("sha256").update(e, "ascii").digest()), g = (e, t) => t.includes(e), _ = (e, t) => {
|
|
23
9
|
let n = new URLSearchParams(t).toString();
|
|
24
10
|
return `${e}${e.includes("?") ? "&" : "?"}${n}`;
|
|
25
|
-
},
|
|
11
|
+
}, v = (e, t) => ({
|
|
26
12
|
status: e,
|
|
27
13
|
body: JSON.stringify(t),
|
|
28
14
|
contentType: "application/json; charset=utf-8"
|
|
29
|
-
}),
|
|
15
|
+
}), y = (e, t) => ({
|
|
30
16
|
status: 302,
|
|
31
17
|
body: "",
|
|
32
18
|
location: e,
|
|
33
19
|
...t === void 0 ? {} : { setCookie: t }
|
|
34
|
-
}),
|
|
20
|
+
}), b = (e) => {
|
|
35
21
|
if (!e) return null;
|
|
36
22
|
let { ch: t, r: n, s: r, exp: i } = e;
|
|
37
23
|
return typeof t != "string" || typeof n != "string" || typeof r != "string" || typeof i != "number" ? null : {
|
|
@@ -40,81 +26,84 @@ var d = "voltro:native", f = 600, p = "/login", m = (e) => e.toString("base64").
|
|
|
40
26
|
s: r,
|
|
41
27
|
exp: i
|
|
42
28
|
};
|
|
43
|
-
},
|
|
29
|
+
}, x = (e, t, r) => {
|
|
30
|
+
let i = n(r.config);
|
|
31
|
+
return [i.current, i.previous].filter((e) => e !== void 0).map((n) => a(e, n.secret, t, r.now)).find((e) => e !== null) ?? null;
|
|
32
|
+
}, S = (e, t, n) => l(e.native.pendingCookieName ?? "voltro:native", t, {
|
|
44
33
|
maxAgeSeconds: n,
|
|
45
34
|
httpOnly: !0,
|
|
46
35
|
sameSite: "lax",
|
|
47
36
|
secure: e.config.cookieSecure ?? !0,
|
|
48
37
|
path: `${e.prefix}/native`
|
|
49
|
-
}),
|
|
50
|
-
let
|
|
51
|
-
if (!
|
|
52
|
-
if (
|
|
38
|
+
}), C = (e) => `${e.native.loginPath ?? p}?next=${encodeURIComponent(`${e.prefix}/native/complete`)}`, w = (e, t, r, a) => c.gen(function* () {
|
|
39
|
+
let o = e.get("redirect_uri") ?? "", s = e.get("code_challenge") ?? "", c = e.get("code_challenge_method") ?? "S256", l = e.get("state") ?? "";
|
|
40
|
+
if (!g(o, a.native.redirectUris)) return v(400, { error: "redirect_uri_not_allowed" });
|
|
41
|
+
if (c !== "S256" || s.length < 43 || s.length > 128) return y(_(o, {
|
|
53
42
|
error: "invalid_request",
|
|
54
|
-
state:
|
|
43
|
+
state: l
|
|
55
44
|
}));
|
|
56
|
-
if (
|
|
57
|
-
let
|
|
58
|
-
ch:
|
|
59
|
-
r:
|
|
60
|
-
s:
|
|
61
|
-
exp: Math.floor(
|
|
62
|
-
},
|
|
45
|
+
if (l.length === 0) return y(_(o, { error: "invalid_request" }));
|
|
46
|
+
let u = a.now ?? Date.now, d = a.native.pendingTtlSeconds ?? f, p = {
|
|
47
|
+
ch: s,
|
|
48
|
+
r: o,
|
|
49
|
+
s: l,
|
|
50
|
+
exp: Math.floor(u() / 1e3) + d
|
|
51
|
+
}, m = S(a, i({ ...p }, n(a.config).current.secret, "native-pending"), d);
|
|
63
52
|
return t && t.subject.type === "user" && t.sessionId ? {
|
|
64
|
-
...yield*
|
|
53
|
+
...yield* T(p, {
|
|
65
54
|
userId: t.subject.id,
|
|
66
55
|
sessionId: t.sessionId
|
|
67
|
-
}, r,
|
|
68
|
-
setCookie:
|
|
69
|
-
} :
|
|
70
|
-
}),
|
|
71
|
-
let
|
|
72
|
-
yield*
|
|
73
|
-
id: `tok_${m(
|
|
74
|
-
tokenHash:
|
|
56
|
+
}, r, a),
|
|
57
|
+
setCookie: S(a, "", 0)
|
|
58
|
+
} : y(C(a), m);
|
|
59
|
+
}), T = (e, r, a, o) => c.gen(function* () {
|
|
60
|
+
let c = t("native-code", 300);
|
|
61
|
+
yield* a.insertToken({
|
|
62
|
+
id: `tok_${m(s(12))}`,
|
|
63
|
+
tokenHash: c.tokenHash,
|
|
75
64
|
userId: r.userId,
|
|
76
65
|
purpose: "native-code",
|
|
77
|
-
expiresAt:
|
|
66
|
+
expiresAt: c.expiresAt
|
|
78
67
|
});
|
|
79
|
-
let
|
|
68
|
+
let l = i({
|
|
80
69
|
sid: r.sessionId,
|
|
81
70
|
uid: r.userId,
|
|
82
71
|
ch: e.ch,
|
|
83
|
-
exp: Math.floor(
|
|
84
|
-
}, n(
|
|
85
|
-
return
|
|
86
|
-
code: `${
|
|
72
|
+
exp: Math.floor(c.expiresAt.getTime() / 1e3)
|
|
73
|
+
}, n(o.config).current.secret, "native-code");
|
|
74
|
+
return y(_(e.r, {
|
|
75
|
+
code: `${c.token}.${l}`,
|
|
87
76
|
state: e.s
|
|
88
77
|
}));
|
|
89
|
-
}),
|
|
90
|
-
let
|
|
91
|
-
return
|
|
92
|
-
...yield*
|
|
78
|
+
}), E = (e, t, n, r) => c.gen(function* () {
|
|
79
|
+
let i = b(x(u(e, r.native.pendingCookieName ?? "voltro:native"), "native-pending", r));
|
|
80
|
+
return i ? !t || t.subject.type !== "user" || !t.sessionId ? y(C(r)) : {
|
|
81
|
+
...yield* T(i, {
|
|
93
82
|
userId: t.subject.id,
|
|
94
83
|
sessionId: t.sessionId
|
|
95
|
-
},
|
|
96
|
-
setCookie:
|
|
97
|
-
} :
|
|
98
|
-
}),
|
|
99
|
-
let
|
|
100
|
-
if (
|
|
101
|
-
let
|
|
102
|
-
if (typeof
|
|
103
|
-
let
|
|
104
|
-
if (!
|
|
105
|
-
let
|
|
106
|
-
if (!
|
|
107
|
-
let
|
|
108
|
-
sessionId:
|
|
84
|
+
}, n, r),
|
|
85
|
+
setCookie: S(r, "", 0)
|
|
86
|
+
} : v(400, { error: "no_pending_native_login" });
|
|
87
|
+
}), D = (t, n, i) => c.gen(function* () {
|
|
88
|
+
let a = t.code.indexOf(".");
|
|
89
|
+
if (a <= 0) return v(400, { error: "invalid_code" });
|
|
90
|
+
let o = t.code.slice(0, a), s = x(t.code.slice(a + 1), "native-code", i), c = s?.sid, l = s?.uid, u = s?.ch;
|
|
91
|
+
if (typeof c != "string" || typeof l != "string" || typeof u != "string") return v(400, { error: "invalid_code" });
|
|
92
|
+
let d = yield* n.consumeToken(e(o), "native-code");
|
|
93
|
+
if (!d || d.userId !== l || t.codeVerifier.length < 43 || h(t.codeVerifier) !== u) return v(400, { error: "invalid_code" });
|
|
94
|
+
let f = yield* n.findById(l);
|
|
95
|
+
if (!f) return v(400, { error: "invalid_code" });
|
|
96
|
+
let p = yield* r(f, n, i.config, {
|
|
97
|
+
sessionId: c,
|
|
109
98
|
sessionRow: "existing",
|
|
110
99
|
clearLoginFailures: !1
|
|
111
100
|
});
|
|
112
|
-
return
|
|
101
|
+
return v(200, {
|
|
113
102
|
ok: !0,
|
|
114
|
-
session:
|
|
115
|
-
expiresAt:
|
|
116
|
-
subject:
|
|
103
|
+
session: p.value,
|
|
104
|
+
expiresAt: p.expiresAt,
|
|
105
|
+
subject: p.subject
|
|
117
106
|
});
|
|
118
107
|
});
|
|
119
108
|
//#endregion
|
|
120
|
-
export { d as NATIVE_PENDING_COOKIE,
|
|
109
|
+
export { d as NATIVE_PENDING_COOKIE, w as handleNativeAuthorize, E as handleNativeComplete, D as handleNativeExchange, g as isAllowedRedirectUri, C as nativeLoginRedirect, h as s256 };
|