ovr 6.2.5 → 7.0.0-next.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/README.md +3 -1
- package/dist/app/index.d.ts +51 -7
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +163 -28
- package/dist/auth/auth-data.d.ts +26 -0
- package/dist/auth/auth-data.d.ts.map +1 -0
- package/dist/auth/auth-data.js +42 -0
- package/dist/auth/cbor.d.ts +50 -0
- package/dist/auth/cbor.d.ts.map +1 -0
- package/dist/auth/cbor.js +200 -0
- package/dist/auth/client-source.d.ts +3 -0
- package/dist/auth/client-source.d.ts.map +1 -0
- package/dist/auth/client-source.js +3 -0
- package/dist/auth/client.d.ts +3 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/client.js +186 -0
- package/dist/auth/configure.d.ts +28 -0
- package/dist/auth/configure.d.ts.map +1 -0
- package/dist/auth/configure.js +228 -0
- package/dist/auth/der.d.ts +6 -0
- package/dist/auth/der.d.ts.map +1 -0
- package/dist/auth/der.js +36 -0
- package/dist/auth/index.d.ts +242 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +152 -0
- package/dist/auth/issue.d.ts +36 -0
- package/dist/auth/issue.d.ts.map +1 -0
- package/dist/auth/issue.js +47 -0
- package/dist/auth/metadata.d.ts +22 -0
- package/dist/auth/metadata.d.ts.map +1 -0
- package/dist/auth/metadata.js +134 -0
- package/dist/auth/oauth.d.ts +29 -0
- package/dist/auth/oauth.d.ts.map +1 -0
- package/dist/auth/oauth.js +724 -0
- package/dist/auth/passkey.d.ts +101 -0
- package/dist/auth/passkey.d.ts.map +1 -0
- package/dist/auth/passkey.js +393 -0
- package/dist/auth/state.d.ts +49 -0
- package/dist/auth/state.d.ts.map +1 -0
- package/dist/auth/state.js +184 -0
- package/dist/auth/storage.d.ts +193 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +410 -0
- package/dist/auth/token.d.ts +12 -0
- package/dist/auth/token.d.ts.map +1 -0
- package/dist/auth/token.js +39 -0
- package/dist/context/index.d.ts +86 -16
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +166 -42
- package/dist/cookie/index.d.ts +3 -0
- package/dist/cookie/index.d.ts.map +1 -1
- package/dist/cookie/index.js +1 -0
- package/dist/database/index.d.ts +262 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +807 -0
- package/dist/form/index.d.ts +699 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +901 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -3
- package/dist/jsx/elements.d.ts +28 -2
- package/dist/jsx/elements.d.ts.map +1 -1
- package/dist/jsx/index.d.ts +20 -4
- package/dist/jsx/index.d.ts.map +1 -1
- package/dist/jsx/index.js +6 -65
- package/dist/limiter/index.d.ts +65 -0
- package/dist/limiter/index.d.ts.map +1 -0
- package/dist/limiter/index.js +157 -0
- package/dist/markdown/index.d.ts +61 -0
- package/dist/markdown/index.d.ts.map +1 -0
- package/dist/markdown/index.js +1160 -0
- package/dist/markup/index.d.ts +188 -0
- package/dist/markup/index.d.ts.map +1 -0
- package/dist/markup/index.js +718 -0
- package/dist/mcp/index.d.ts +73 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +988 -0
- package/dist/middleware/index.d.ts +3 -4
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/multipart/index.d.ts +53 -7
- package/dist/multipart/index.d.ts.map +1 -1
- package/dist/multipart/index.js +289 -123
- package/dist/route/index.d.ts +226 -80
- package/dist/route/index.d.ts.map +1 -1
- package/dist/route/index.js +239 -99
- package/dist/schema/index.d.ts +307 -734
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +783 -1050
- package/dist/table/index.d.ts +132 -0
- package/dist/table/index.d.ts.map +1 -0
- package/dist/table/index.js +188 -0
- package/dist/trie/index.js +4 -4
- package/dist/util/index.d.ts +37 -5
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +156 -41
- package/package.json +11 -4
- package/src/app/index.ts +230 -42
- package/src/auth/auth-data.ts +56 -0
- package/src/auth/cbor.ts +231 -0
- package/src/auth/client-source.ts +3 -0
- package/src/auth/client.ts +205 -0
- package/src/auth/configure.ts +279 -0
- package/src/auth/der.ts +35 -0
- package/src/auth/index.ts +387 -0
- package/src/auth/issue.ts +52 -0
- package/src/auth/metadata.ts +149 -0
- package/src/auth/oauth.ts +882 -0
- package/src/auth/passkey.ts +556 -0
- package/src/auth/state.ts +213 -0
- package/src/auth/storage.ts +572 -0
- package/src/auth/token.ts +67 -0
- package/src/context/index.ts +240 -65
- package/src/cookie/index.ts +3 -0
- package/src/database/index.ts +1193 -0
- package/src/form/index.ts +1720 -0
- package/src/index.ts +10 -3
- package/src/jsx/elements.ts +45 -25
- package/src/jsx/index.ts +24 -69
- package/src/limiter/index.ts +221 -0
- package/src/markdown/index.ts +1322 -0
- package/src/markup/index.ts +853 -0
- package/src/mcp/conformance.2025-11-25.yml +39 -0
- package/src/mcp/conformance.2026-07-28.yml +56 -0
- package/src/mcp/index.ts +1262 -0
- package/src/middleware/index.ts +5 -6
- package/src/multipart/index.ts +360 -148
- package/src/route/index.ts +559 -278
- package/src/schema/index.ts +1542 -2256
- package/src/table/index.ts +387 -0
- package/src/trie/index.ts +4 -4
- package/src/util/index.ts +163 -49
- package/dist/render/index.d.ts +0 -79
- package/dist/render/index.d.ts.map +0 -1
- package/dist/render/index.js +0 -265
- package/src/render/index.ts +0 -318
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { agent } from "../context/index.js";
|
|
2
|
+
import { Codec, Time, noStore } from "../util/index.js";
|
|
3
|
+
import { Issue } from "./issue.js";
|
|
4
|
+
import { Token } from "./token.js";
|
|
5
|
+
/** Internal authentication state for exactly one service and request. */
|
|
6
|
+
export class State {
|
|
7
|
+
static #cookie = "__Host-auth-session";
|
|
8
|
+
static #binding = "__Host-auth-browser";
|
|
9
|
+
static #return = "__Host-auth-return";
|
|
10
|
+
#c;
|
|
11
|
+
#browser;
|
|
12
|
+
#session;
|
|
13
|
+
/** Normalized authentication configuration. */
|
|
14
|
+
options;
|
|
15
|
+
/** Create authentication helpers for the current request. */
|
|
16
|
+
constructor(c, options) {
|
|
17
|
+
this.#c = c;
|
|
18
|
+
const lifetime = options.lifetime ?? 30 * Time.day;
|
|
19
|
+
this.options = {
|
|
20
|
+
...options,
|
|
21
|
+
lifetime,
|
|
22
|
+
// a session never outlives its lifetime, however recently it was used
|
|
23
|
+
idle: Math.min(options.idle ?? Time.week, lifetime),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A request on another host has no session there, its cookies are bound to
|
|
28
|
+
* Auth's origin, and passkeys cannot be used on it.
|
|
29
|
+
*
|
|
30
|
+
* @throws When the request is not on Auth's origin
|
|
31
|
+
*/
|
|
32
|
+
#origin() {
|
|
33
|
+
if (this.#c.url.origin !== this.options.origin)
|
|
34
|
+
throw new Error(`Auth serves ${this.options.origin}, this request is for ${this.#c.url.origin}`);
|
|
35
|
+
}
|
|
36
|
+
/** Read a browser binding; create it only while preparing a form in the handler. */
|
|
37
|
+
browser(create = false) {
|
|
38
|
+
if (create)
|
|
39
|
+
this.#origin();
|
|
40
|
+
this.#browser ??= this.#c.cookie.get(State.#binding);
|
|
41
|
+
if (!this.#browser && create) {
|
|
42
|
+
this.#browser = crypto.randomUUID();
|
|
43
|
+
this.#set(State.#binding, this.#browser);
|
|
44
|
+
}
|
|
45
|
+
return this.#browser;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set one of Auth's cookies, which only its origin's server reads.
|
|
49
|
+
*
|
|
50
|
+
* @param name Cookie name
|
|
51
|
+
* @param value Cookie value
|
|
52
|
+
* @param options How long it lasts, a browser session without it
|
|
53
|
+
*/
|
|
54
|
+
#set(name, value, options) {
|
|
55
|
+
this.#c.cookie.set(name, value, {
|
|
56
|
+
secure: true,
|
|
57
|
+
httpOnly: true,
|
|
58
|
+
sameSite: "Lax",
|
|
59
|
+
...options,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
#clear() {
|
|
63
|
+
noStore(this.#c.res.headers);
|
|
64
|
+
this.#set(State.#cookie, "", { maxAge: 0 });
|
|
65
|
+
}
|
|
66
|
+
async #read() {
|
|
67
|
+
// an agent's tool call, authorized by its token
|
|
68
|
+
const { req } = this.#c;
|
|
69
|
+
const call = req && agent.get(req);
|
|
70
|
+
if (call?.session)
|
|
71
|
+
return call.session;
|
|
72
|
+
// nobody is signed in on another host, its session cookie is not sent there
|
|
73
|
+
if (this.#c.url.origin !== this.options.origin)
|
|
74
|
+
return null;
|
|
75
|
+
noStore(this.#c.res.headers);
|
|
76
|
+
const cookie = this.#c.cookie.get(State.#cookie);
|
|
77
|
+
if (!cookie)
|
|
78
|
+
return null;
|
|
79
|
+
let id;
|
|
80
|
+
try {
|
|
81
|
+
id = await Token.open(this.options.secret, "session", cookie);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
if (!(e instanceof Issue))
|
|
85
|
+
throw e;
|
|
86
|
+
this.#clear();
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
// Storage failures must propagate, rather than appear to be successful logouts.
|
|
90
|
+
const session = await this.options.sessions.get(id);
|
|
91
|
+
const now = Date.now();
|
|
92
|
+
if (session &&
|
|
93
|
+
session.id === id &&
|
|
94
|
+
session.expiration > now &&
|
|
95
|
+
session.started + this.options.lifetime > now)
|
|
96
|
+
return this.#renew(session, now);
|
|
97
|
+
this.#clear();
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Extend a session that is being used, up to its lifetime. Only the record
|
|
102
|
+
* changes: the cookie lasts the whole lifetime, so a renewal sets no header
|
|
103
|
+
* and works after the response has started streaming.
|
|
104
|
+
*
|
|
105
|
+
* @param session Valid stored session
|
|
106
|
+
* @param now Current time
|
|
107
|
+
* @returns The session with its current expiration
|
|
108
|
+
*/
|
|
109
|
+
async #renew(session, now) {
|
|
110
|
+
const { idle, lifetime } = this.options;
|
|
111
|
+
let { expiration } = session;
|
|
112
|
+
const later = Math.min(now + idle, session.started + lifetime);
|
|
113
|
+
// at most once a day, or each half of a shorter idle timeout
|
|
114
|
+
const renewed = expiration - idle;
|
|
115
|
+
if (now - renewed >= Math.min(Time.day, idle / 2) && later > expiration) {
|
|
116
|
+
await this.options.sessions.renew(session.id, later);
|
|
117
|
+
expiration = later;
|
|
118
|
+
}
|
|
119
|
+
return { id: session.id, user: session.user, expiration };
|
|
120
|
+
}
|
|
121
|
+
/** Read a non-expired, non-revoked session, renewing it while it is used. */
|
|
122
|
+
session() {
|
|
123
|
+
return (this.#session ??= this.#read());
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Return to a local path after the next login, such as an agent's
|
|
127
|
+
* authorization request.
|
|
128
|
+
*
|
|
129
|
+
* @param path Local path with its query
|
|
130
|
+
*/
|
|
131
|
+
remember(path) {
|
|
132
|
+
this.#origin();
|
|
133
|
+
this.#set(State.#return, path, {
|
|
134
|
+
maxAge: Math.floor((15 * Time.minute) / Time.second),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @param fallback Destination without a remembered path
|
|
139
|
+
* @returns The remembered path, cleared, or the fallback
|
|
140
|
+
*/
|
|
141
|
+
resume(fallback) {
|
|
142
|
+
this.#origin();
|
|
143
|
+
const path = this.#c.cookie.get(State.#return);
|
|
144
|
+
if (!path)
|
|
145
|
+
return fallback;
|
|
146
|
+
this.#set(State.#return, "", { maxAge: 0 });
|
|
147
|
+
return path.startsWith("/") &&
|
|
148
|
+
!path.startsWith("//") &&
|
|
149
|
+
!path.includes("\\")
|
|
150
|
+
? path
|
|
151
|
+
: fallback;
|
|
152
|
+
}
|
|
153
|
+
/** Replace the current session and issue a new signed, secure cookie. */
|
|
154
|
+
async login(user) {
|
|
155
|
+
this.#origin();
|
|
156
|
+
if (!user.trim() || Codec.encode(user).length > 1024)
|
|
157
|
+
throw new TypeError("Auth user ID must contain 1 to 1024 UTF-8 bytes");
|
|
158
|
+
const previous = await this.session();
|
|
159
|
+
if (previous)
|
|
160
|
+
await this.options.sessions.delete(previous.id);
|
|
161
|
+
const now = Date.now();
|
|
162
|
+
const session = {
|
|
163
|
+
id: crypto.randomUUID(),
|
|
164
|
+
user,
|
|
165
|
+
expiration: now + this.options.idle,
|
|
166
|
+
};
|
|
167
|
+
await this.options.sessions.set(session.id, { ...session, started: now });
|
|
168
|
+
this.#set(State.#cookie, await Token.seal(this.options.secret, "session", session.id),
|
|
169
|
+
// renewals only change the record, so the cookie covers the lifetime
|
|
170
|
+
{ maxAge: Math.floor(this.options.lifetime / Time.second) });
|
|
171
|
+
this.#session = Promise.resolve(session);
|
|
172
|
+
return session;
|
|
173
|
+
}
|
|
174
|
+
/** Revoke the current session and expire its cookie. Always await this method. */
|
|
175
|
+
async logout() {
|
|
176
|
+
this.#origin();
|
|
177
|
+
const session = await this.session();
|
|
178
|
+
if (session)
|
|
179
|
+
await this.options.sessions.delete(session.id);
|
|
180
|
+
this.#clear();
|
|
181
|
+
this.#session = Promise.resolve(null);
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { type Database } from "../database/index.js";
|
|
2
|
+
import { Schema } from "../schema/index.js";
|
|
3
|
+
import { Table } from "../table/index.js";
|
|
4
|
+
import type { Auth } from "./index.js";
|
|
5
|
+
/**
|
|
6
|
+
* A value, or a promise of it, from storage.
|
|
7
|
+
*
|
|
8
|
+
* @template T Value
|
|
9
|
+
*/
|
|
10
|
+
type Result<T> = T | Promise<T>;
|
|
11
|
+
export declare namespace Storage {
|
|
12
|
+
/** Server-side state for one WebAuthn ceremony. */
|
|
13
|
+
interface Challenge {
|
|
14
|
+
readonly challenge: string;
|
|
15
|
+
readonly browser: string;
|
|
16
|
+
readonly method: "register" | "login";
|
|
17
|
+
readonly action: string;
|
|
18
|
+
readonly origin: string;
|
|
19
|
+
readonly expiration: number;
|
|
20
|
+
readonly user?: string;
|
|
21
|
+
/** SHA-256 base64url digest binding validated registration fields to the provider label. */
|
|
22
|
+
readonly fields?: string;
|
|
23
|
+
}
|
|
24
|
+
/** Single-use challenges shared by all instances. */
|
|
25
|
+
interface Challenges {
|
|
26
|
+
/** Store until expiration. Return false when capacity is exhausted. */
|
|
27
|
+
set(id: string, challenge: Challenge): Result<void | boolean>;
|
|
28
|
+
/** Atomically return and delete an entry; concurrent calls have one winner. */
|
|
29
|
+
take(id: string): Result<Challenge | null | undefined>;
|
|
30
|
+
}
|
|
31
|
+
/** A stored session, with the time it started for its lifetime. */
|
|
32
|
+
interface Session extends Auth.Session {
|
|
33
|
+
/** Sign-in time in milliseconds. */
|
|
34
|
+
readonly started: number;
|
|
35
|
+
}
|
|
36
|
+
/** Revocable sessions shared by all instances. */
|
|
37
|
+
interface Sessions {
|
|
38
|
+
set(id: string, session: Session): Result<void>;
|
|
39
|
+
/** Return a session, or nothing if it has expired or been revoked. */
|
|
40
|
+
get(id: string): Result<Session | null | undefined>;
|
|
41
|
+
/** Move a session's expiration later, never earlier. */
|
|
42
|
+
renew(id: string, expiration: number): Result<void>;
|
|
43
|
+
delete(id: string): Result<void>;
|
|
44
|
+
}
|
|
45
|
+
/** OAuth client registered by an agent. */
|
|
46
|
+
/** OAuth authorization code or token, stored by its hash. */
|
|
47
|
+
interface Token {
|
|
48
|
+
readonly kind: "code" | "access" | "refresh";
|
|
49
|
+
readonly user: string;
|
|
50
|
+
readonly client: string;
|
|
51
|
+
readonly resource: string;
|
|
52
|
+
readonly scope: string;
|
|
53
|
+
readonly expiration: number;
|
|
54
|
+
readonly redirect?: string;
|
|
55
|
+
readonly challenge?: string;
|
|
56
|
+
/** Hash of the code the token descends from, defaults to its own */
|
|
57
|
+
readonly family?: string;
|
|
58
|
+
}
|
|
59
|
+
/** Credential lookup and compare-and-swap updates. */
|
|
60
|
+
interface Credentials {
|
|
61
|
+
get(id: string): Result<Auth.Credential | null | undefined>;
|
|
62
|
+
/** IDs of the user's credentials */
|
|
63
|
+
list(user: string): Result<readonly string[]>;
|
|
64
|
+
/** Save `credential` only if the record still matches `previous`. */
|
|
65
|
+
update(credential: Auth.Credential, previous: Auth.Credential): Result<boolean>;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Authentication persistence in the application's Postgres database. */
|
|
69
|
+
export declare class Storage {
|
|
70
|
+
#private;
|
|
71
|
+
/** Registered passkeys. */
|
|
72
|
+
static readonly credentials: Table<"auth_credentials", {
|
|
73
|
+
id: Schema<string>;
|
|
74
|
+
user: Schema<string>;
|
|
75
|
+
publicKey: Schema<string>;
|
|
76
|
+
counter: Schema<number>;
|
|
77
|
+
eligible: Schema<boolean>;
|
|
78
|
+
backedUp: Schema<boolean>;
|
|
79
|
+
}, {}>;
|
|
80
|
+
/** Revocable sessions. */
|
|
81
|
+
static readonly sessions: Table<"auth_sessions", {
|
|
82
|
+
id: Schema<string>;
|
|
83
|
+
user: Schema<string>;
|
|
84
|
+
expiration: Schema<number>;
|
|
85
|
+
started: Schema<number>;
|
|
86
|
+
}, {}>;
|
|
87
|
+
/** Outstanding WebAuthn ceremonies. */
|
|
88
|
+
static readonly challenges: Table<"auth_challenges", {
|
|
89
|
+
id: Schema<string>;
|
|
90
|
+
challenge: Schema<string>;
|
|
91
|
+
browser: Schema<string>;
|
|
92
|
+
method: Schema<"login" | "register">;
|
|
93
|
+
action: Schema<string>;
|
|
94
|
+
origin: Schema<string>;
|
|
95
|
+
expiration: Schema<number>;
|
|
96
|
+
user: Schema<string | null>;
|
|
97
|
+
fields: Schema<string | null>;
|
|
98
|
+
}, {}>;
|
|
99
|
+
/** Authorization codes, access tokens, and refresh tokens, by hash. */
|
|
100
|
+
static readonly tokens: Table<"auth_tokens", {
|
|
101
|
+
id: Schema<string>;
|
|
102
|
+
kind: Schema<"access" | "code" | "refresh" | "spent">;
|
|
103
|
+
user: Schema<string>;
|
|
104
|
+
client: Schema<string>;
|
|
105
|
+
resource: Schema<string>;
|
|
106
|
+
scope: Schema<string>;
|
|
107
|
+
redirect: Schema<string | null>;
|
|
108
|
+
challenge: Schema<string | null>;
|
|
109
|
+
family: Schema<string>;
|
|
110
|
+
expiration: Schema<number>;
|
|
111
|
+
}, {}>;
|
|
112
|
+
/** Tables whose rows belong to a user, and must reference the users table. */
|
|
113
|
+
static readonly owners: readonly [Table<"auth_credentials", {
|
|
114
|
+
id: Schema<string>;
|
|
115
|
+
user: Schema<string>;
|
|
116
|
+
publicKey: Schema<string>;
|
|
117
|
+
counter: Schema<number>;
|
|
118
|
+
eligible: Schema<boolean>;
|
|
119
|
+
backedUp: Schema<boolean>;
|
|
120
|
+
}, {}>, Table<"auth_sessions", {
|
|
121
|
+
id: Schema<string>;
|
|
122
|
+
user: Schema<string>;
|
|
123
|
+
expiration: Schema<number>;
|
|
124
|
+
started: Schema<number>;
|
|
125
|
+
}, {}>, Table<"auth_tokens", {
|
|
126
|
+
id: Schema<string>;
|
|
127
|
+
kind: Schema<"access" | "code" | "refresh" | "spent">;
|
|
128
|
+
user: Schema<string>;
|
|
129
|
+
client: Schema<string>;
|
|
130
|
+
resource: Schema<string>;
|
|
131
|
+
scope: Schema<string>;
|
|
132
|
+
redirect: Schema<string | null>;
|
|
133
|
+
challenge: Schema<string | null>;
|
|
134
|
+
family: Schema<string>;
|
|
135
|
+
expiration: Schema<number>;
|
|
136
|
+
}, {}>];
|
|
137
|
+
/**
|
|
138
|
+
* @param db Database containing the authentication tables
|
|
139
|
+
*/
|
|
140
|
+
constructor(db: Database);
|
|
141
|
+
/**
|
|
142
|
+
* @param db Database containing the authentication tables
|
|
143
|
+
* @returns The database's store
|
|
144
|
+
*/
|
|
145
|
+
static of(db: Database): Storage;
|
|
146
|
+
/**
|
|
147
|
+
* @param token Code or token
|
|
148
|
+
* @returns SHA-256 hash to store it by
|
|
149
|
+
*/
|
|
150
|
+
static hash(token: string): Promise<string>;
|
|
151
|
+
readonly tokens: {
|
|
152
|
+
/**
|
|
153
|
+
* @param token Code or token, stored by its hash
|
|
154
|
+
* @param row Token data
|
|
155
|
+
*/
|
|
156
|
+
set: (token: string, row: Storage.Token) => Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Uses a code or refresh token once, in one transaction with the tokens
|
|
159
|
+
* it is exchanged for. Replaying a used one revokes its whole family.
|
|
160
|
+
*
|
|
161
|
+
* @param token Code or refresh token
|
|
162
|
+
* @param kind Kind of token
|
|
163
|
+
* @param exchange Checks the unexpired token, returns the tokens to issue in its family, or `undefined` to refuse
|
|
164
|
+
* @returns `true` if the tokens were issued
|
|
165
|
+
*/
|
|
166
|
+
exchange: (token: string, kind: "code" | "refresh", exchange: (row: Storage.Token) => Promise<Record<string, Storage.Token> | undefined>) => Promise<boolean>;
|
|
167
|
+
/**
|
|
168
|
+
* Disconnect one of a user's agents: its codes, access tokens, and
|
|
169
|
+
* refresh tokens, including ones an exchange is issuing at the same time.
|
|
170
|
+
*
|
|
171
|
+
* @param user User ID
|
|
172
|
+
* @param client Agent's client ID
|
|
173
|
+
*/
|
|
174
|
+
revoke: (user: string, client: string) => Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* @param token Access token
|
|
177
|
+
* @returns The unexpired token
|
|
178
|
+
*/
|
|
179
|
+
get: (token: string) => Promise<Storage.Token | undefined>;
|
|
180
|
+
};
|
|
181
|
+
readonly challenges: Storage.Challenges;
|
|
182
|
+
readonly sessions: Storage.Sessions;
|
|
183
|
+
readonly credentials: Storage.Credentials;
|
|
184
|
+
/**
|
|
185
|
+
* Create the account and its first credential in one transaction.
|
|
186
|
+
*
|
|
187
|
+
* @param create Application callback creating the account
|
|
188
|
+
* @param credential Verified credential
|
|
189
|
+
*/
|
|
190
|
+
register(create: (t: Database.Transaction, user: string) => Result<void>, credential: Auth.Credential): Promise<void>;
|
|
191
|
+
}
|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