@dokebi/oauth 0.0.0-stage → 0.1.1
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/AI.md +469 -0
- package/LICENSE +21 -0
- package/README.md +41 -2
- package/dist/bounded.d.ts +9 -0
- package/dist/bounded.js +36 -0
- package/dist/cimd.d.ts +97 -0
- package/dist/cimd.js +384 -0
- package/dist/clients.d.ts +85 -0
- package/dist/clients.js +303 -0
- package/dist/dependency.d.ts +4 -0
- package/dist/dependency.js +14 -0
- package/dist/errors.d.ts +87 -0
- package/dist/errors.js +34 -0
- package/dist/extension.d.ts +161 -0
- package/dist/extension.js +108 -0
- package/dist/grants.d.ts +126 -0
- package/dist/grants.js +280 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +28 -0
- package/dist/install.d.ts +33 -0
- package/dist/install.js +112 -0
- package/dist/live.d.ts +47 -0
- package/dist/live.js +105 -0
- package/dist/options.d.ts +173 -0
- package/dist/options.js +521 -0
- package/dist/plugin.d.ts +113 -0
- package/dist/plugin.js +766 -0
- package/dist/protocol.d.ts +81 -0
- package/dist/protocol.js +249 -0
- package/dist/server.d.ts +148 -0
- package/dist/server.js +1516 -0
- package/dist/signin.d.ts +40 -0
- package/dist/signin.js +86 -0
- package/dist/store-redis.d.ts +38 -0
- package/dist/store-redis.js +173 -0
- package/dist/store-sql.d.ts +46 -0
- package/dist/store-sql.js +363 -0
- package/dist/store.d.ts +126 -0
- package/dist/store.js +266 -0
- package/options.schema.json +633 -0
- package/package.json +143 -4
- package/templates/extension.ts +45 -0
- package/templates/migrations/dokebi_oauth.ts +117 -0
package/dist/signin.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** The reserved prefix of this plugin's abilities. */
|
|
2
|
+
export declare const RESERVED = "dokebi-oauth:";
|
|
3
|
+
/** The ability that carries a sign-in time (epoch ms, floored to whole seconds). */
|
|
4
|
+
export declare function authTimeMark(authTime: number): string;
|
|
5
|
+
/** The sign-in time (epoch ms) a list of abilities or stored scopes carries, or null. */
|
|
6
|
+
export declare function authTimeOf(list: readonly string[] | null | undefined): number | null;
|
|
7
|
+
/** The marks of a list (what a refresh carries to the new access token). */
|
|
8
|
+
export declare function marksOf(list: readonly string[] | null | undefined): string[];
|
|
9
|
+
/**
|
|
10
|
+
* The mark of a code whose grant holds a pending pair (a token family with a live token from the
|
|
11
|
+
* consent until the code expires): the exchange then requires that family to be live for the user,
|
|
12
|
+
* so an account-wide invalidation (a new stamp, `tokens.revokeAll`, `active: false`) or a revoked
|
|
13
|
+
* grant ends the code too. Codes issued before it lack the mark and skip that check. Never a token
|
|
14
|
+
* ability of the exchanged tokens.
|
|
15
|
+
*/
|
|
16
|
+
export declare const PENDING_MARK = "dokebi-oauth:pending";
|
|
17
|
+
/** A list without this plugin's marks (the scopes). */
|
|
18
|
+
export declare function withoutMarks(list: readonly string[]): string[];
|
|
19
|
+
/** The prompt values this server acts on (OIDC Core §3.1.2.1). */
|
|
20
|
+
export type PromptValue = 'login' | 'consent';
|
|
21
|
+
/**
|
|
22
|
+
* The `prompt` parameter: space-separated values. `login` asks for a fresh sign-in; `consent` is
|
|
23
|
+
* what this server always does. `none` (no page at all) and `select_account` cannot be honoured:
|
|
24
|
+
* the consent page is always shown, and an account is chosen by signing in.
|
|
25
|
+
*/
|
|
26
|
+
export declare function parsePrompt(value: string | undefined): {
|
|
27
|
+
ok: true;
|
|
28
|
+
values: ReadonlySet<PromptValue>;
|
|
29
|
+
} | {
|
|
30
|
+
ok: false;
|
|
31
|
+
description: string;
|
|
32
|
+
};
|
|
33
|
+
/** `max_age`: whole seconds (OIDC Core §3.1.2.1), or a refusal. */
|
|
34
|
+
export declare function parseMaxAge(value: string | undefined): {
|
|
35
|
+
ok: true;
|
|
36
|
+
seconds: number | null;
|
|
37
|
+
} | {
|
|
38
|
+
ok: false;
|
|
39
|
+
description: string;
|
|
40
|
+
};
|
package/dist/signin.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The sign-in time of a token chain (D-0122): `max_age` and `prompt=login` of the authorization
|
|
3
|
+
* request (OIDC Core §3.1.2.1, RFC 9470 §4) and the `auth_time` the issued tokens carry.
|
|
4
|
+
*
|
|
5
|
+
* dokebi-auth tokens are opaque rows with abilities; the time rides with each token chain as a
|
|
6
|
+
* reserved ability of its tokens (`dokebi-oauth:auth_time:<epoch seconds>`, like
|
|
7
|
+
* `dokebi-oauth:none`), and from the consent to the token exchange in the stored scopes of the
|
|
8
|
+
* code (a code lives `codeMs`). Neither is a scope: resources may not declare names under
|
|
9
|
+
* `dokebi-oauth:`, and both are taken out before a scope list is shown, compared or answered.
|
|
10
|
+
* (Since D-0124 a grant is one authorization, so the chain and the grant have one time; the mark
|
|
11
|
+
* stays on the tokens so that no table changes.)
|
|
12
|
+
*
|
|
13
|
+
* The value is exact (D-0124): dokebi-auth's `request.auth.authenticatedAt()` at the consent, the
|
|
14
|
+
* last time the user authenticated (the sign-in, the one behind a remember cookie, or a later
|
|
15
|
+
* re-authentication), in whole seconds.
|
|
16
|
+
*/
|
|
17
|
+
/** The reserved prefix of this plugin's abilities. */
|
|
18
|
+
export const RESERVED = 'dokebi-oauth:';
|
|
19
|
+
const AUTH_TIME = `${RESERVED}auth_time:`;
|
|
20
|
+
const SECONDS = /^[0-9]{1,12}$/;
|
|
21
|
+
/** The ability that carries a sign-in time (epoch ms, floored to whole seconds). */
|
|
22
|
+
export function authTimeMark(authTime) {
|
|
23
|
+
return `${AUTH_TIME}${Math.floor(authTime / 1000)}`;
|
|
24
|
+
}
|
|
25
|
+
/** The sign-in time (epoch ms) a list of abilities or stored scopes carries, or null. */
|
|
26
|
+
export function authTimeOf(list) {
|
|
27
|
+
if (!list)
|
|
28
|
+
return null;
|
|
29
|
+
for (const item of list)
|
|
30
|
+
if (item.startsWith(AUTH_TIME)) {
|
|
31
|
+
const text = item.slice(AUTH_TIME.length);
|
|
32
|
+
return SECONDS.test(text) ? Number(text) * 1000 : null;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
/** The marks of a list (what a refresh carries to the new access token). */
|
|
37
|
+
export function marksOf(list) {
|
|
38
|
+
return (list ?? []).filter((item) => item.startsWith(AUTH_TIME));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The mark of a code whose grant holds a pending pair (a token family with a live token from the
|
|
42
|
+
* consent until the code expires): the exchange then requires that family to be live for the user,
|
|
43
|
+
* so an account-wide invalidation (a new stamp, `tokens.revokeAll`, `active: false`) or a revoked
|
|
44
|
+
* grant ends the code too. Codes issued before it lack the mark and skip that check. Never a token
|
|
45
|
+
* ability of the exchanged tokens.
|
|
46
|
+
*/
|
|
47
|
+
export const PENDING_MARK = `${RESERVED}pending`;
|
|
48
|
+
/** A list without this plugin's marks (the scopes). */
|
|
49
|
+
export function withoutMarks(list) {
|
|
50
|
+
return list.filter((item) => !item.startsWith(AUTH_TIME) && item !== PENDING_MARK);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The `prompt` parameter: space-separated values. `login` asks for a fresh sign-in; `consent` is
|
|
54
|
+
* what this server always does. `none` (no page at all) and `select_account` cannot be honoured:
|
|
55
|
+
* the consent page is always shown, and an account is chosen by signing in.
|
|
56
|
+
*/
|
|
57
|
+
export function parsePrompt(value) {
|
|
58
|
+
const values = new Set();
|
|
59
|
+
if (value === undefined)
|
|
60
|
+
return { ok: true, values };
|
|
61
|
+
for (const item of value.split(' ')) {
|
|
62
|
+
if (item === '')
|
|
63
|
+
continue;
|
|
64
|
+
if (item === 'login' || item === 'consent')
|
|
65
|
+
values.add(item);
|
|
66
|
+
else if (item === 'none')
|
|
67
|
+
return {
|
|
68
|
+
ok: false,
|
|
69
|
+
description: 'prompt=none is not supported: this server always shows its consent page',
|
|
70
|
+
};
|
|
71
|
+
else
|
|
72
|
+
return {
|
|
73
|
+
ok: false,
|
|
74
|
+
description: 'prompt may only be login and/or consent on this server',
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return { ok: true, values };
|
|
78
|
+
}
|
|
79
|
+
/** `max_age`: whole seconds (OIDC Core §3.1.2.1), or a refusal. */
|
|
80
|
+
export function parseMaxAge(value) {
|
|
81
|
+
if (value === undefined)
|
|
82
|
+
return { ok: true, seconds: null };
|
|
83
|
+
if (!/^[0-9]{1,9}$/.test(value))
|
|
84
|
+
return { ok: false, description: 'max_age must be a whole number of seconds' };
|
|
85
|
+
return { ok: true, seconds: Number(value) };
|
|
86
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ClientRow, type CodeRow, type ConsumedCode, type GrantRow, type OAuthStore, type PurgeCounts } from './store.js';
|
|
2
|
+
/** The part of a dokebi-redis connection this store uses (declared here: redis is optional). */
|
|
3
|
+
export interface OAuthRedisConnection {
|
|
4
|
+
get(key: string): Promise<string | null>;
|
|
5
|
+
script(source: string): {
|
|
6
|
+
run(input: {
|
|
7
|
+
keys: readonly string[];
|
|
8
|
+
arguments: readonly string[];
|
|
9
|
+
}): Promise<unknown>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare class RedisOAuthStore implements OAuthStore {
|
|
13
|
+
#private;
|
|
14
|
+
readonly name = "redis";
|
|
15
|
+
constructor(connection: OAuthRedisConnection, namespace: string, settings: {
|
|
16
|
+
readonly codeGraceMs: number;
|
|
17
|
+
readonly clientUnusedMs: number;
|
|
18
|
+
/** `refreshMs`: the client key lives at least this long after its last use (`clientKeptMs`). */
|
|
19
|
+
readonly refreshMs?: number;
|
|
20
|
+
});
|
|
21
|
+
insertGrant(row: GrantRow): Promise<void>;
|
|
22
|
+
findGrant(id: string): Promise<GrantRow | undefined>;
|
|
23
|
+
listGrants(realm: string, userId: string): Promise<GrantRow[]>;
|
|
24
|
+
revokeGrant(id: string, at: number): Promise<boolean>;
|
|
25
|
+
touchGrant(id: string, at: number): Promise<void>;
|
|
26
|
+
insertCode(row: CodeRow): Promise<void>;
|
|
27
|
+
findCode(hash: string): Promise<CodeRow | undefined>;
|
|
28
|
+
consumeCode(hash: string, at: number): Promise<ConsumedCode | undefined>;
|
|
29
|
+
insertClient(row: ClientRow): Promise<void>;
|
|
30
|
+
findClient(id: string): Promise<ClientRow | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* A use moves the expiry: an unused client disappears max(`clientUnusedMs`, `refreshMs`) after
|
|
33
|
+
* its last use.
|
|
34
|
+
*/
|
|
35
|
+
touchClient(id: string, at: number): Promise<void>;
|
|
36
|
+
/** Redis expires everything with its lifetime: nothing to delete. */
|
|
37
|
+
purge(): Promise<PurgeCounts>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { checkClient, checkCode, checkGrant, clientKeptMs, } from './store.js';
|
|
2
|
+
/** SET a value with its lifetime; with a second key, add ARGV[3] to that set (kept as long). */
|
|
3
|
+
const INSERT = `redis.call('SET', KEYS[1], ARGV[1], 'PX', ARGV[2])
|
|
4
|
+
if KEYS[2] then
|
|
5
|
+
local existed = redis.call('EXISTS', KEYS[2])
|
|
6
|
+
redis.call('SADD', KEYS[2], ARGV[3])
|
|
7
|
+
local ttl = redis.call('PTTL', KEYS[2])
|
|
8
|
+
if existed == 0 or (ttl >= 0 and ttl < tonumber(ARGV[2])) then
|
|
9
|
+
redis.call('PEXPIRE', KEYS[2], ARGV[2])
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
return 1`;
|
|
13
|
+
/** Merges ARGV[1] (JSON fields) into a value; with ARGV[2] = 'once' only while ARGV[3] is null. */
|
|
14
|
+
const MERGE = `local raw = redis.call('GET', KEYS[1])
|
|
15
|
+
if not raw then return 0 end
|
|
16
|
+
local row = cjson.decode(raw)
|
|
17
|
+
if ARGV[2] == 'once' and row[ARGV[3]] ~= cjson.null then return 0 end
|
|
18
|
+
for key, value in pairs(cjson.decode(ARGV[1])) do row[key] = value end
|
|
19
|
+
if ARGV[4] and ARGV[4] ~= '' then
|
|
20
|
+
redis.call('SET', KEYS[1], cjson.encode(row), 'PX', ARGV[4])
|
|
21
|
+
else
|
|
22
|
+
redis.call('SET', KEYS[1], cjson.encode(row), 'KEEPTTL')
|
|
23
|
+
end
|
|
24
|
+
return 1`;
|
|
25
|
+
/** The atomic single use: 'F' + the row for the first use, 'R' + the row for a replay. */
|
|
26
|
+
const CONSUME = `local raw = redis.call('GET', KEYS[1])
|
|
27
|
+
if not raw then return false end
|
|
28
|
+
local row = cjson.decode(raw)
|
|
29
|
+
if row.usedAt ~= cjson.null then return 'R' .. raw end
|
|
30
|
+
row.usedAt = tonumber(ARGV[1])
|
|
31
|
+
redis.call('SET', KEYS[1], cjson.encode(row), 'KEEPTTL')
|
|
32
|
+
return 'F' .. raw`;
|
|
33
|
+
/** The values of a set's members; drops members whose value expired. */
|
|
34
|
+
const LIST = `local rows = {}
|
|
35
|
+
for _, id in ipairs(redis.call('SMEMBERS', KEYS[1])) do
|
|
36
|
+
local raw = redis.call('GET', ARGV[1] .. id)
|
|
37
|
+
if raw then
|
|
38
|
+
rows[#rows + 1] = raw
|
|
39
|
+
else
|
|
40
|
+
redis.call('SREM', KEYS[1], id)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
return rows`;
|
|
44
|
+
/** Lua's cjson writes an empty list as `{}`: lists of this store are read back as lists. */
|
|
45
|
+
function lists(row, keys) {
|
|
46
|
+
for (const key of keys) {
|
|
47
|
+
const value = row[key];
|
|
48
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
49
|
+
if (Object.keys(value).length === 0)
|
|
50
|
+
row[key] = [];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return row;
|
|
54
|
+
}
|
|
55
|
+
export class RedisOAuthStore {
|
|
56
|
+
name = 'redis';
|
|
57
|
+
#connection;
|
|
58
|
+
#grant;
|
|
59
|
+
#user;
|
|
60
|
+
#code;
|
|
61
|
+
#client;
|
|
62
|
+
#codeGraceMs;
|
|
63
|
+
#clientUnusedMs;
|
|
64
|
+
#insert;
|
|
65
|
+
#merge;
|
|
66
|
+
#consume;
|
|
67
|
+
#list;
|
|
68
|
+
constructor(connection, namespace, settings) {
|
|
69
|
+
this.#connection = connection;
|
|
70
|
+
this.#grant = `${namespace}:oauth:grant:`;
|
|
71
|
+
this.#user = `${namespace}:oauth:grant-user:`;
|
|
72
|
+
this.#code = `${namespace}:oauth:code:`;
|
|
73
|
+
this.#client = `${namespace}:oauth:client:`;
|
|
74
|
+
this.#codeGraceMs = settings.codeGraceMs;
|
|
75
|
+
this.#clientUnusedMs = clientKeptMs(settings.clientUnusedMs, settings.refreshMs);
|
|
76
|
+
this.#insert = connection.script(INSERT);
|
|
77
|
+
this.#merge = connection.script(MERGE);
|
|
78
|
+
this.#consume = connection.script(CONSUME);
|
|
79
|
+
this.#list = connection.script(LIST);
|
|
80
|
+
}
|
|
81
|
+
#userKey(realm, userId) {
|
|
82
|
+
return `${this.#user}${realm}:${Buffer.from(userId, 'utf8').toString('base64url')}`;
|
|
83
|
+
}
|
|
84
|
+
#json(raw, what) {
|
|
85
|
+
if (typeof raw !== 'string')
|
|
86
|
+
throw new Error(`Redis returned an unexpected ${what} value`);
|
|
87
|
+
return JSON.parse(raw);
|
|
88
|
+
}
|
|
89
|
+
#parseGrant(raw) {
|
|
90
|
+
return checkGrant(lists(this.#json(raw, 'grant'), ['scopes']), this.name);
|
|
91
|
+
}
|
|
92
|
+
#parseCode(raw) {
|
|
93
|
+
return checkCode(lists(this.#json(raw, 'code'), ['scopes']), this.name);
|
|
94
|
+
}
|
|
95
|
+
async insertGrant(row) {
|
|
96
|
+
await this.#insert.run({
|
|
97
|
+
keys: [this.#grant + row.id, this.#userKey(row.realm, row.userId)],
|
|
98
|
+
arguments: [JSON.stringify(row), String(Math.max(1, row.expiresAt - Date.now())), row.id],
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async findGrant(id) {
|
|
102
|
+
const raw = await this.#connection.get(this.#grant + id);
|
|
103
|
+
return raw === null ? undefined : this.#parseGrant(raw);
|
|
104
|
+
}
|
|
105
|
+
async listGrants(realm, userId) {
|
|
106
|
+
const reply = await this.#list.run({
|
|
107
|
+
keys: [this.#userKey(realm, userId)],
|
|
108
|
+
arguments: [this.#grant],
|
|
109
|
+
});
|
|
110
|
+
if (!Array.isArray(reply))
|
|
111
|
+
throw new Error('Redis returned an unexpected grant list');
|
|
112
|
+
return reply.map((raw) => this.#parseGrant(raw));
|
|
113
|
+
}
|
|
114
|
+
async revokeGrant(id, at) {
|
|
115
|
+
const reply = await this.#merge.run({
|
|
116
|
+
keys: [this.#grant + id],
|
|
117
|
+
arguments: [JSON.stringify({ revokedAt: at }), 'once', 'revokedAt', ''],
|
|
118
|
+
});
|
|
119
|
+
return Number(reply) === 1;
|
|
120
|
+
}
|
|
121
|
+
async touchGrant(id, at) {
|
|
122
|
+
await this.#merge.run({
|
|
123
|
+
keys: [this.#grant + id],
|
|
124
|
+
arguments: [JSON.stringify({ lastUsedAt: at }), 'always', '', ''],
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
async insertCode(row) {
|
|
128
|
+
// Kept past its expiry so that a late replay is still recognized (and revokes the grant).
|
|
129
|
+
const ttl = Math.max(1, row.expiresAt - Date.now()) + this.#codeGraceMs;
|
|
130
|
+
await this.#insert.run({
|
|
131
|
+
keys: [this.#code + row.hash],
|
|
132
|
+
arguments: [JSON.stringify(row), String(ttl), ''],
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
async findCode(hash) {
|
|
136
|
+
const raw = await this.#connection.get(this.#code + hash);
|
|
137
|
+
return raw === null ? undefined : this.#parseCode(raw);
|
|
138
|
+
}
|
|
139
|
+
async consumeCode(hash, at) {
|
|
140
|
+
const reply = await this.#consume.run({ keys: [this.#code + hash], arguments: [String(at)] });
|
|
141
|
+
if (reply === null || reply === false || reply === undefined)
|
|
142
|
+
return undefined;
|
|
143
|
+
if (typeof reply !== 'string')
|
|
144
|
+
throw new Error('Redis returned an unexpected code answer');
|
|
145
|
+
return { row: this.#parseCode(reply.slice(1)), first: reply.startsWith('F') };
|
|
146
|
+
}
|
|
147
|
+
async insertClient(row) {
|
|
148
|
+
await this.#insert.run({
|
|
149
|
+
keys: [this.#client + row.id],
|
|
150
|
+
arguments: [JSON.stringify(row), String(this.#clientUnusedMs), ''],
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async findClient(id) {
|
|
154
|
+
const raw = await this.#connection.get(this.#client + id);
|
|
155
|
+
return raw === null
|
|
156
|
+
? undefined
|
|
157
|
+
: checkClient(lists(this.#json(raw, 'client'), ['redirectUris']), this.name);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* A use moves the expiry: an unused client disappears max(`clientUnusedMs`, `refreshMs`) after
|
|
161
|
+
* its last use.
|
|
162
|
+
*/
|
|
163
|
+
async touchClient(id, at) {
|
|
164
|
+
await this.#merge.run({
|
|
165
|
+
keys: [this.#client + id],
|
|
166
|
+
arguments: [JSON.stringify({ lastUsedAt: at }), 'always', '', String(this.#clientUnusedMs)],
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/** Redis expires everything with its lifetime: nothing to delete. */
|
|
170
|
+
purge() {
|
|
171
|
+
return Promise.resolve({ grants: 0, codes: 0, clients: 0 });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Logger } from '@dokebi/core';
|
|
2
|
+
import type { SqlOAuthStoreOptions } from './options.js';
|
|
3
|
+
import { type ClientRow, type CodeRow, type ConsumedCode, type GrantRow, type OAuthStore, type PurgeCounts, type PurgeSettings } from './store.js';
|
|
4
|
+
export type SqlDialect = 'postgres' | 'mysql' | 'mariadb';
|
|
5
|
+
export declare const DEFAULT_TABLE_PREFIX = "dokebi_oauth";
|
|
6
|
+
/** The statements that create the three tables (what the migration runs; also in AI.md). */
|
|
7
|
+
export declare function oauthTableStatements(dialect: SqlDialect, prefix?: string): string[];
|
|
8
|
+
/** The statements that remove the three tables (the migration's `down`). */
|
|
9
|
+
export declare function dropOAuthTableStatements(prefix?: string): string[];
|
|
10
|
+
interface Result {
|
|
11
|
+
readonly rows: Record<string, unknown>[];
|
|
12
|
+
readonly affected: number;
|
|
13
|
+
}
|
|
14
|
+
type Query = (sql: string, values: readonly unknown[]) => Promise<Result>;
|
|
15
|
+
/**
|
|
16
|
+
* Finds which driver a pool is by the shape of one `SELECT 1` answer (no DDL, no write): pg
|
|
17
|
+
* answers `{ rows }`, mysql2/promise `[rows, fields]`, mariadb an array of rows. Anything else
|
|
18
|
+
* (a MongoDB client has no `query`) is undefined.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sqlQuery(resource: unknown): Promise<{
|
|
21
|
+
dialect: SqlDialect;
|
|
22
|
+
query: Query;
|
|
23
|
+
} | undefined>;
|
|
24
|
+
export declare class SqlOAuthStore implements OAuthStore {
|
|
25
|
+
#private;
|
|
26
|
+
readonly name = "sql";
|
|
27
|
+
/** 'unknown' in a describing app (D-0133): the pool was never asked. */
|
|
28
|
+
readonly dialect: SqlDialect | 'unknown';
|
|
29
|
+
constructor(query: Query, dialect: SqlDialect | 'unknown', prefix: string);
|
|
30
|
+
/** Start: the three tables must exist (a migration made them). */
|
|
31
|
+
check(connection: string): Promise<void>;
|
|
32
|
+
insertGrant(row: GrantRow): Promise<void>;
|
|
33
|
+
findGrant(id: string): Promise<GrantRow | undefined>;
|
|
34
|
+
listGrants(realm: string, userId: string): Promise<GrantRow[]>;
|
|
35
|
+
revokeGrant(id: string, at: number): Promise<boolean>;
|
|
36
|
+
touchGrant(id: string, at: number): Promise<void>;
|
|
37
|
+
insertCode(row: CodeRow): Promise<void>;
|
|
38
|
+
findCode(hash: string): Promise<CodeRow | undefined>;
|
|
39
|
+
consumeCode(hash: string, at: number): Promise<ConsumedCode | undefined>;
|
|
40
|
+
insertClient(row: ClientRow): Promise<void>;
|
|
41
|
+
findClient(id: string): Promise<ClientRow | undefined>;
|
|
42
|
+
touchClient(id: string, at: number): Promise<void>;
|
|
43
|
+
purge(settings: PurgeSettings): Promise<PurgeCounts>;
|
|
44
|
+
}
|
|
45
|
+
export declare function openSqlStore(resource: unknown, options: SqlOAuthStoreOptions, logger: Logger, describing?: boolean): Promise<SqlOAuthStore>;
|
|
46
|
+
export {};
|