@adonis-agora/authkit-poppy 0.3.1-rc.0 → 0.3.1-rc.2
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 +23 -0
- package/build/index.d.ts +2 -1
- package/build/index.js +1 -0
- package/build/src/config.d.ts +20 -0
- package/build/src/config.js +47 -1
- package/build/src/extension.js +24 -4
- package/build/src/messages.d.ts +2 -0
- package/build/src/messages.js +3 -0
- package/build/src/replay.d.ts +3 -1
- package/build/src/replay.js +7 -5
- package/build/src/service.d.ts +15 -9
- package/build/src/service.js +18 -2
- package/build/src/store.d.ts +5 -1
- package/build/src/store.js +23 -19
- package/build/src/tables.d.ts +5 -1
- package/build/src/tables.js +4 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @adonis-agora/authkit-poppy
|
|
2
2
|
|
|
3
|
+
## 0.3.1-rc.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#474](https://github.com/DavideCarvalho/adonis-agora-authkit/pull/474) [`df9e49d`](https://github.com/DavideCarvalho/adonis-agora-authkit/commit/df9e49d7817c03a7cce4cac1df709c7788d6307c) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - AuthKit's tables can live in their own database schema: `schema: { name: 'auth' }` in `defineConfig` puts every table AuthKit owns in `auth` (`"auth"."auth_settings"`) while the app stays in `public`. The schema is written into every statement, so it works on any connection and inside the app's own transaction, with no `searchPath` (which leaks across clients behind PgBouncer in transaction mode).
|
|
8
|
+
|
|
9
|
+
- The boot creates the schema (`CREATE SCHEMA IF NOT EXISTS`; MySQL: `CREATE DATABASE IF NOT EXISTS`) when `autoManage` is on, and fails with a message naming the schema and the grant when the role cannot create it. `ensureAuthkitSchema(db, { schema })` does the same from a migration.
|
|
10
|
+
- Covers the OIDC adapter table (`adapters.database({ schema })` overrides), the Lucid keystore (`jwks.store: { driver: 'lucid', schema }` overrides), the account store's tables (MFA, password history, organizations), runtime settings, session revocations, the personal-agent tables and agent extensions (`PersonalAgentHost.table(name)`, `AuthkitTable.create(table, { table })`, `ensureAuthkitTables(db, tables, { schema })`; Poppy uses them and `ensurePoppySchema(db, { schema })`).
|
|
11
|
+
- authkit-client: `lucidRevocationStore({ schema })`.
|
|
12
|
+
- SQLite with `schema.name` fails the boot instead of ignoring the option.
|
|
13
|
+
- `agora:doctor` gains `authkit.db-schema`: the schema exists, the tables are in it, the connection can write there. Silent without `schema.name`.
|
|
14
|
+
- The key-rotation lock key includes the schema, so two installs in two schemas of one database do not share it.
|
|
15
|
+
|
|
16
|
+
Without `schema.name` nothing changes.
|
|
17
|
+
|
|
18
|
+
## 0.3.1-rc.1
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- [#464](https://github.com/DavideCarvalho/adonis-agora-authkit/pull/464) [`3250c35`](https://github.com/DavideCarvalho/adonis-agora-authkit/commit/3250c35eee328e8e3780df32001323be45fe1bae) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Developer tools over MCP. When the app runs `@adonis-agora/agent`'s dev tools endpoint (`/mcp/agora`), the admin console's data is served there with no config: `authkit_get_overview`, `authkit_list_users`, `authkit_get_user`, `authkit_list_user_sessions`, `authkit_list_user_grants`, `authkit_list_orgs`, `authkit_get_org`, `authkit_list_clients`, `authkit_list_audit`, and the destructive actions `authkit_revoke_user_sessions` and `authkit_disable_user` (hidden until the endpoint allows actions; audited with `mcp:<caller>` as actor). Access follows `admin.authorize`; when it allows the MCP request, `admin.roles` is not checked. Without `admin.authorize`, production refuses and other environments need an AuthKit sign-in holding one of `admin.roles`.
|
|
23
|
+
|
|
24
|
+
`@adonis-agora/authkit-poppy` offers the `agora:dev` scope when the app serves those dev tools (`devTools` option to force it on or off). The consent screen never ticks it for the person, and Mediated Sign-In can't grant it. The personal-agent consent screen supports opt-in scopes (`optIn`, `descriptionKey` on each scope of `agents/consent`).
|
|
25
|
+
|
|
3
26
|
## 0.3.1-rc.0
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/build/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { configure, POPPY_CONFIG_SNIPPET } from './configure.js';
|
|
8
8
|
export type { PoppyAgentProtocolEntry, PoppyApiEntry, PoppyBrowserLogin, PoppyClientsConfigInput, PoppyConfigInput, PoppyLimiter, PoppyMediatedConfigInput, PoppyMediatedField, PoppyMediatedResult, PoppyMediatedVerifyInput, PoppyPrincipalBase, PoppyReplayStore, PoppyScopeHint, PoppySignInType, ResolvedPoppyConfig, } from './src/config.js';
|
|
9
|
+
export { AGORA_DEV_SCOPE } from './src/config.js';
|
|
9
10
|
export { accessTokenHash, type DpopNonceSource, type DpopResult, hmacNonceSource, type VerifyDpopInput, verifyDpopProof, } from './src/dpop.js';
|
|
10
11
|
export { maskEmail, type PoppyEmailCodeSignInOptions, type PoppySignInCodeEmail, poppyEmailCodeSignIn, } from './src/email_code_sign_in.js';
|
|
11
12
|
export { PoppyError, type PoppyErrorCode } from './src/errors.js';
|
|
@@ -15,6 +16,6 @@ export { databaseReplayStore, memoryReplayStore, redisReplayStore, } from './src
|
|
|
15
16
|
export { installPoppySlots, POPPY_AUTHENTICATE_SLOT, type PoppyAuthenticate, type PoppyAuthResult, type PoppyPrincipal, type PoppySlotRequest, poppyAuth, poppyOf, verifyPoppyRequest, writePoppyAuthError, } from './src/resource.js';
|
|
16
17
|
export { POPPY_PROTOCOL_ID, poppyFor, poppyFromApp } from './src/runtime.js';
|
|
17
18
|
export { isBlockedAddress, SafeFetchError, safeFetchJson, } from './src/safe_fetch.js';
|
|
18
|
-
export type { PoppyAuthError, PoppyGrantSummary, PoppyService, PoppySessionState, PoppyTokenResponse, PoppyVerifyOptions, } from './src/service.js';
|
|
19
|
+
export type { PoppyAuthError, PoppyGrantSummary, PoppyScopeDescription, PoppyService, PoppySessionState, PoppyTokenResponse, PoppyVerifyOptions, } from './src/service.js';
|
|
19
20
|
export { ensurePoppySchema, POPPY_TABLES } from './src/tables.js';
|
|
20
21
|
export { isPoppyBrowser, POPPY_WEB_SESSION_KEY, type PoppyWebSessionMarker, poppyWebSession, poppyWebSessionOf, } from './src/web_session.js';
|
package/build/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Experimental: this package stays on 0.x and follows the draft spec, so any minor may break.
|
|
6
6
|
*/
|
|
7
7
|
export { configure, POPPY_CONFIG_SNIPPET } from './configure.js';
|
|
8
|
+
export { AGORA_DEV_SCOPE } from './src/config.js';
|
|
8
9
|
export { accessTokenHash, hmacNonceSource, verifyDpopProof, } from './src/dpop.js';
|
|
9
10
|
export { maskEmail, poppyEmailCodeSignIn, } from './src/email_code_sign_in.js';
|
|
10
11
|
export { PoppyError } from './src/errors.js';
|
package/build/src/config.d.ts
CHANGED
|
@@ -286,6 +286,13 @@ export interface PoppyConfigInput {
|
|
|
286
286
|
* global devolvem `actor`.
|
|
287
287
|
*/
|
|
288
288
|
toActor?: (principal: PoppyPrincipalBase) => unknown | Promise<unknown>;
|
|
289
|
+
/**
|
|
290
|
+
* Offer the `agora:dev` scope: a personal agent the person grants it to may use the app's Agora
|
|
291
|
+
* developer tools over MCP (`@adonis-agora/agent`, `/mcp/agora`). It is never ticked for the
|
|
292
|
+
* person on the consent screen and Mediated Sign-In can never grant it. Default: offered when the
|
|
293
|
+
* app serves those dev tools (the `'agora.devTools'` binding exists). `false` never offers it.
|
|
294
|
+
*/
|
|
295
|
+
devTools?: boolean;
|
|
289
296
|
}
|
|
290
297
|
/**
|
|
291
298
|
* O que uma request verificada autoriza — sem o `actor`.
|
|
@@ -391,6 +398,19 @@ export interface ResolvedPoppyConfig {
|
|
|
391
398
|
mediatedPerHour: number;
|
|
392
399
|
} | PoppyLimiter;
|
|
393
400
|
toActor?: PoppyConfigInput['toActor'];
|
|
401
|
+
/** `agora:dev` offered: `true`/`false` as configured, `null` = when the app serves dev tools. */
|
|
402
|
+
devTools: boolean | null;
|
|
394
403
|
}
|
|
395
404
|
export declare function normalizePoppyPrefix(prefix: string | undefined): string;
|
|
396
405
|
export declare function resolvePoppyConfig(input: PoppyConfigInput | undefined, fallbackScopes: Record<string, string> | undefined): ResolvedPoppyConfig | undefined;
|
|
406
|
+
/** The scope that lets a personal agent use the app's Agora developer tools over MCP. */
|
|
407
|
+
export declare const AGORA_DEV_SCOPE = "agora:dev";
|
|
408
|
+
/** The catalog description of {@link AGORA_DEV_SCOPE} (the consent screen shows a translated text). */
|
|
409
|
+
export declare const AGORA_DEV_SCOPE_DESCRIPTION = "Use this app's developer tools: read its accounts, sessions, workflows and logs over MCP";
|
|
410
|
+
/** The message key the consent screen shows for {@link AGORA_DEV_SCOPE}. */
|
|
411
|
+
export declare const AGORA_DEV_SCOPE_MESSAGE = "poppy.scope.agora_dev";
|
|
412
|
+
/**
|
|
413
|
+
* `cfg` with {@link AGORA_DEV_SCOPE} offered: in the catalog, and in the Direct and Device sign-in
|
|
414
|
+
* lists that were left to their default (every scope). Never in Mediated Sign-In.
|
|
415
|
+
*/
|
|
416
|
+
export declare function withAgoraDevScope(cfg: ResolvedPoppyConfig, input: Pick<PoppyConfigInput, 'signIn'>): ResolvedPoppyConfig;
|
package/build/src/config.js
CHANGED
|
@@ -113,6 +113,9 @@ export function resolvePoppyConfig(input, fallbackScopes) {
|
|
|
113
113
|
fail('signIn.mediated.verify é obrigatório.');
|
|
114
114
|
if (!Array.isArray(m.scopes))
|
|
115
115
|
fail('signIn.mediated.scopes é obrigatório.');
|
|
116
|
+
if (m.scopes.includes(AGORA_DEV_SCOPE)) {
|
|
117
|
+
fail(`signIn.mediated.scopes — "${AGORA_DEV_SCOPE}" needs the consent screen; Mediated Sign-In cannot grant it.`);
|
|
118
|
+
}
|
|
116
119
|
const mediatedScopes = typeScopes({ scopes: m.scopes }, all, 'mediated').scopes;
|
|
117
120
|
mediated = {
|
|
118
121
|
fields: m.fields.map((f) => ({ name: f.name, label: f.label, secret: f.secret })),
|
|
@@ -177,7 +180,7 @@ export function resolvePoppyConfig(input, fallbackScopes) {
|
|
|
177
180
|
mediatedPerHour: positive(input.rateLimit?.mediatedPerHour, 10, 'rateLimit.mediatedPerHour'),
|
|
178
181
|
};
|
|
179
182
|
}
|
|
180
|
-
|
|
183
|
+
const resolved = {
|
|
181
184
|
organization: { name: org.name, domain: domains[0], aliases: domains.slice(1) },
|
|
182
185
|
prefix: normalizePoppyPrefix(input.prefix),
|
|
183
186
|
scopes,
|
|
@@ -224,5 +227,48 @@ export function resolvePoppyConfig(input, fallbackScopes) {
|
|
|
224
227
|
replay: input.replay ?? 'database',
|
|
225
228
|
rateLimit,
|
|
226
229
|
toActor: input.toActor,
|
|
230
|
+
devTools: null,
|
|
231
|
+
};
|
|
232
|
+
resolved.devTools = input.devTools ?? null;
|
|
233
|
+
return input.devTools === true ? withAgoraDevScope(resolved, input) : resolved;
|
|
234
|
+
}
|
|
235
|
+
/** The scope that lets a personal agent use the app's Agora developer tools over MCP. */
|
|
236
|
+
export const AGORA_DEV_SCOPE = 'agora:dev';
|
|
237
|
+
/** The catalog description of {@link AGORA_DEV_SCOPE} (the consent screen shows a translated text). */
|
|
238
|
+
export const AGORA_DEV_SCOPE_DESCRIPTION = "Use this app's developer tools: read its accounts, sessions, workflows and logs over MCP";
|
|
239
|
+
/** The message key the consent screen shows for {@link AGORA_DEV_SCOPE}. */
|
|
240
|
+
export const AGORA_DEV_SCOPE_MESSAGE = 'poppy.scope.agora_dev';
|
|
241
|
+
/**
|
|
242
|
+
* `cfg` with {@link AGORA_DEV_SCOPE} offered: in the catalog, and in the Direct and Device sign-in
|
|
243
|
+
* lists that were left to their default (every scope). Never in Mediated Sign-In.
|
|
244
|
+
*/
|
|
245
|
+
export function withAgoraDevScope(cfg, input) {
|
|
246
|
+
const add = (current, configured) => {
|
|
247
|
+
if (current === null)
|
|
248
|
+
return null;
|
|
249
|
+
const explicit = typeof configured === 'object' && Array.isArray(configured.scopes);
|
|
250
|
+
if (explicit || current.scopes.includes(AGORA_DEV_SCOPE))
|
|
251
|
+
return current;
|
|
252
|
+
return { scopes: [...current.scopes, AGORA_DEV_SCOPE] };
|
|
253
|
+
};
|
|
254
|
+
return {
|
|
255
|
+
...cfg,
|
|
256
|
+
devTools: true,
|
|
257
|
+
scopes: {
|
|
258
|
+
...cfg.scopes,
|
|
259
|
+
[AGORA_DEV_SCOPE]: cfg.scopes[AGORA_DEV_SCOPE] ?? AGORA_DEV_SCOPE_DESCRIPTION,
|
|
260
|
+
},
|
|
261
|
+
scopeHints: {
|
|
262
|
+
...cfg.scopeHints,
|
|
263
|
+
[AGORA_DEV_SCOPE]: cfg.scopeHints[AGORA_DEV_SCOPE] ?? {
|
|
264
|
+
changes: 'irreversible',
|
|
265
|
+
personal_data: true,
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
signIn: {
|
|
269
|
+
...cfg.signIn,
|
|
270
|
+
direct: add(cfg.signIn.direct, input.signIn?.direct),
|
|
271
|
+
device: add(cfg.signIn.device, input.signIn?.device),
|
|
272
|
+
},
|
|
227
273
|
};
|
|
228
274
|
}
|
package/build/src/extension.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PoppyClientRegistry } from './client_registry.js';
|
|
2
|
-
import { resolvePoppyConfig, } from './config.js';
|
|
2
|
+
import { resolvePoppyConfig, withAgoraDevScope, } from './config.js';
|
|
3
3
|
import { hmacNonceSource } from './dpop.js';
|
|
4
4
|
import { POPPY_MESSAGES } from './messages.js';
|
|
5
5
|
import { databaseReplayStore, memoryLimiter, memoryReplayStore, redisReplayStore, } from './replay.js';
|
|
@@ -81,16 +81,33 @@ function withRegistry(cfg, host) {
|
|
|
81
81
|
},
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* How the host names AuthKit's tables (with `schema.name`, `schema.table`). A host from before
|
|
86
|
+
* `table()` existed has no schema option, so the bare name is right there.
|
|
87
|
+
*/
|
|
88
|
+
function tableOf(host) {
|
|
89
|
+
return (name) => (typeof host.table === 'function' ? host.table(name) : name);
|
|
90
|
+
}
|
|
84
91
|
async function resolveReplay(replay, host) {
|
|
85
92
|
if (replay === 'memory')
|
|
86
93
|
return memoryReplayStore();
|
|
87
94
|
if (replay === 'database')
|
|
88
|
-
return databaseReplayStore(() => host.db());
|
|
95
|
+
return databaseReplayStore(() => host.db(), tableOf(host));
|
|
89
96
|
if (typeof replay.claim === 'function')
|
|
90
97
|
return replay;
|
|
91
98
|
const redis = await host.make('redis');
|
|
92
99
|
return redisReplayStore(redis.connection(replay.redis));
|
|
93
100
|
}
|
|
101
|
+
/** O app serve os dev tools do Agora (`@adonis-agora/agent` ligou `'agora.devTools'`)? */
|
|
102
|
+
async function servesDevTools(host) {
|
|
103
|
+
try {
|
|
104
|
+
const hub = await host.make('agora.devTools');
|
|
105
|
+
return typeof hub === 'object' && hub !== null;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
94
111
|
/** Bearer de MCP de Sessions logadas viram access tokens do oidc-provider (§7). */
|
|
95
112
|
function mcpBridge(cfg, host) {
|
|
96
113
|
const tokens = host.accessTokens;
|
|
@@ -141,7 +158,10 @@ export function poppy(config, options = {}) {
|
|
|
141
158
|
},
|
|
142
159
|
routes: (router, kit) => registerRoutes(router, resolved.prefix, kit),
|
|
143
160
|
async setup(host) {
|
|
144
|
-
const
|
|
161
|
+
const offered = resolved.devTools === null && (await servesDevTools(host))
|
|
162
|
+
? withAgoraDevScope(resolved, config)
|
|
163
|
+
: resolved;
|
|
164
|
+
const cfg = withRegistry(offered, host);
|
|
145
165
|
const limiter = cfg.rateLimit === false
|
|
146
166
|
? null
|
|
147
167
|
: typeof cfg.rateLimit === 'function'
|
|
@@ -150,7 +170,7 @@ export function poppy(config, options = {}) {
|
|
|
150
170
|
return new PoppyService({
|
|
151
171
|
cfg,
|
|
152
172
|
urls: poppyUrls(host.issuer, cfg.prefix),
|
|
153
|
-
store: new PoppyStore(() => host.db()),
|
|
173
|
+
store: new PoppyStore(() => host.db(), tableOf(host)),
|
|
154
174
|
grants: host.grants,
|
|
155
175
|
registry: new PoppyClientRegistry(cfg, { fetchJson: options.fetchJson }),
|
|
156
176
|
replay: await resolveReplay(cfg.replay, host),
|
package/build/src/messages.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare const POPPY_MESSAGES: {
|
|
|
9
9
|
readonly 'mail.poppy_sign_in.intro': '{agent} asked to sign in to your account. If that was you, give it the code below. It expires in {minutes} minutes and works once.';
|
|
10
10
|
readonly 'mail.poppy_sign_in.code_label': 'Your code:';
|
|
11
11
|
readonly 'mail.poppy_sign_in.fallback': 'If you did not ask for this, ignore this email — nobody gets in without the code. Never share it with anyone else.';
|
|
12
|
+
readonly 'poppy.scope.agora_dev': "Use this app's developer tools: read its accounts, sessions, workflows and logs (and, if the app allows it, act on them)";
|
|
12
13
|
};
|
|
13
14
|
readonly 'pt-BR': {
|
|
14
15
|
readonly 'mail.poppy_sign_in.subject': 'Seu código para conectar {agent}';
|
|
@@ -16,5 +17,6 @@ export declare const POPPY_MESSAGES: {
|
|
|
16
17
|
readonly 'mail.poppy_sign_in.intro': '{agent} pediu para entrar na sua conta. Se foi você, informe o código abaixo. Ele expira em {minutes} minutos e serve uma única vez.';
|
|
17
18
|
readonly 'mail.poppy_sign_in.code_label': 'Seu código:';
|
|
18
19
|
readonly 'mail.poppy_sign_in.fallback': 'Se não foi você, ignore este e-mail — ninguém entra sem o código. Nunca o compartilhe com outra pessoa.';
|
|
20
|
+
readonly 'poppy.scope.agora_dev': 'Usar as ferramentas de desenvolvedor deste app: ler contas, sessões, workflows e logs (e, se o app permitir, agir sobre eles)';
|
|
19
21
|
};
|
|
20
22
|
};
|
package/build/src/messages.js
CHANGED
|
@@ -11,6 +11,8 @@ export const POPPY_MESSAGES = {
|
|
|
11
11
|
'mail.poppy_sign_in.intro': '{agent} asked to sign in to your account. If that was you, give it the code below. It expires in {minutes} minutes and works once.',
|
|
12
12
|
'mail.poppy_sign_in.code_label': 'Your code:',
|
|
13
13
|
'mail.poppy_sign_in.fallback': 'If you did not ask for this, ignore this email — nobody gets in without the code. Never share it with anyone else.',
|
|
14
|
+
// O scope `agora:dev` na tela de consentimento.
|
|
15
|
+
'poppy.scope.agora_dev': "Use this app's developer tools: read its accounts, sessions, workflows and logs (and, if the app allows it, act on them)",
|
|
14
16
|
},
|
|
15
17
|
'pt-BR': {
|
|
16
18
|
'mail.poppy_sign_in.subject': 'Seu código para conectar {agent}',
|
|
@@ -18,5 +20,6 @@ export const POPPY_MESSAGES = {
|
|
|
18
20
|
'mail.poppy_sign_in.intro': '{agent} pediu para entrar na sua conta. Se foi você, informe o código abaixo. Ele expira em {minutes} minutos e serve uma única vez.',
|
|
19
21
|
'mail.poppy_sign_in.code_label': 'Seu código:',
|
|
20
22
|
'mail.poppy_sign_in.fallback': 'Se não foi você, ignore este e-mail — ninguém entra sem o código. Nunca o compartilhe com outra pessoa.',
|
|
23
|
+
'poppy.scope.agora_dev': 'Usar as ferramentas de desenvolvedor deste app: ler contas, sessões, workflows e logs (e, se o app permitir, agir sobre eles)',
|
|
21
24
|
},
|
|
22
25
|
};
|
package/build/src/replay.d.ts
CHANGED
|
@@ -11,7 +11,9 @@ export declare function memoryReplayStore(options?: {
|
|
|
11
11
|
* Na tabela lib-owned `auth_poppy_jtis` (PK = chave): o INSERT de uma chave que
|
|
12
12
|
* já existe falha — atômico entre instâncias. Linhas vencidas saem aos poucos.
|
|
13
13
|
*/
|
|
14
|
-
export declare function databaseReplayStore(conn: () => any,
|
|
14
|
+
export declare function databaseReplayStore(conn: () => any,
|
|
15
|
+
/** Nome da tabela como os statements o escrevem (`schema.tabela` quando o app usa um schema). */
|
|
16
|
+
table?: (name: string) => string, options?: {
|
|
15
17
|
now?: () => Date;
|
|
16
18
|
}): PoppyReplayStore;
|
|
17
19
|
/** Numa conexão Redis (`SET key 1 PX ttl NX`). */
|
package/build/src/replay.js
CHANGED
|
@@ -36,22 +36,24 @@ export function memoryReplayStore(options = {}) {
|
|
|
36
36
|
* Na tabela lib-owned `auth_poppy_jtis` (PK = chave): o INSERT de uma chave que
|
|
37
37
|
* já existe falha — atômico entre instâncias. Linhas vencidas saem aos poucos.
|
|
38
38
|
*/
|
|
39
|
-
export function databaseReplayStore(conn,
|
|
39
|
+
export function databaseReplayStore(conn,
|
|
40
|
+
/** Nome da tabela como os statements o escrevem (`schema.tabela` quando o app usa um schema). */
|
|
41
|
+
table = (name) => name, options = {}) {
|
|
40
42
|
const now = options.now ?? (() => new Date());
|
|
41
43
|
let claims = 0;
|
|
42
44
|
return {
|
|
43
45
|
async claim(key, expiresAt) {
|
|
44
46
|
const t = now();
|
|
45
47
|
if (++claims % 200 === 1) {
|
|
46
|
-
await conn().from(JTI_TABLE).where('expires_at', '<', t).delete();
|
|
48
|
+
await conn().from(table(JTI_TABLE)).where('expires_at', '<', t).delete();
|
|
47
49
|
}
|
|
48
50
|
try {
|
|
49
|
-
await conn().table(JTI_TABLE).insert({ key, expires_at: expiresAt });
|
|
51
|
+
await conn().table(table(JTI_TABLE)).insert({ key, expires_at: expiresAt });
|
|
50
52
|
return true;
|
|
51
53
|
}
|
|
52
54
|
catch (error) {
|
|
53
55
|
// Chave já usada — a não ser que a linha vencida ainda não tenha saído.
|
|
54
|
-
const row = await conn().from(JTI_TABLE).where('key', key).first();
|
|
56
|
+
const row = await conn().from(table(JTI_TABLE)).where('key', key).first();
|
|
55
57
|
if (!row)
|
|
56
58
|
throw error;
|
|
57
59
|
const exp = row.expires_at instanceof Date
|
|
@@ -60,7 +62,7 @@ export function databaseReplayStore(conn, options = {}) {
|
|
|
60
62
|
if (exp.getTime() > t.getTime())
|
|
61
63
|
return false;
|
|
62
64
|
const updated = await conn()
|
|
63
|
-
.from(JTI_TABLE)
|
|
65
|
+
.from(table(JTI_TABLE))
|
|
64
66
|
.where('key', key)
|
|
65
67
|
.where('expires_at', '<=', t)
|
|
66
68
|
.update({ expires_at: expiresAt });
|
package/build/src/service.d.ts
CHANGED
|
@@ -105,16 +105,22 @@ export type PoppyVerifyResult = {
|
|
|
105
105
|
headers: Record<string, string>;
|
|
106
106
|
};
|
|
107
107
|
/** Pedido Direct aguardando o usuário na tela de consentimento. */
|
|
108
|
+
/** Um scope como as telas mostram. */
|
|
109
|
+
export interface PoppyScopeDescription {
|
|
110
|
+
id: string;
|
|
111
|
+
description: string;
|
|
112
|
+
/** Chave de mensagem mostrada no lugar de `description`. */
|
|
113
|
+
descriptionKey?: string;
|
|
114
|
+
/** Não vem marcado na tela de consentimento: só é concedido se a pessoa marcar. */
|
|
115
|
+
optIn?: boolean;
|
|
116
|
+
}
|
|
108
117
|
export interface PoppyConsentRequest {
|
|
109
118
|
id: string;
|
|
110
119
|
clientId: string;
|
|
111
120
|
agentName: string;
|
|
112
121
|
agentOrigin: string;
|
|
113
122
|
logoUri: string | null;
|
|
114
|
-
scopes:
|
|
115
|
-
id: string;
|
|
116
|
-
description: string;
|
|
117
|
-
}[];
|
|
123
|
+
scopes: PoppyScopeDescription[];
|
|
118
124
|
userCode?: string;
|
|
119
125
|
}
|
|
120
126
|
export type PoppyAuthorizeOutcome = {
|
|
@@ -185,11 +191,11 @@ export declare class PoppyService implements PersonalAgentProtocolRuntime {
|
|
|
185
191
|
nonce(): string | null;
|
|
186
192
|
/** Domínios da empresa (o principal + aliases). */
|
|
187
193
|
get domains(): string[];
|
|
188
|
-
/**
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Descrição de um scope para o usuário. `agora:dev` vem desmarcado na tela de consentimento
|
|
196
|
+
* (`optIn`) e, sem descrição própria do app, com o texto traduzido (`descriptionKey`).
|
|
197
|
+
*/
|
|
198
|
+
describe(ids: string[]): PoppyScopeDescription[];
|
|
193
199
|
/** `www.{domínio}` não é a empresa (§3.1): a descoberta redireciona para o domínio (§3). */
|
|
194
200
|
discoveryRedirect(requestHost: string): string | null;
|
|
195
201
|
/** `/.well-known/poppy.json` (§3) para o domínio pedido; `null` = domínio que não é nosso. */
|
package/build/src/service.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { createHash, randomBytes, randomInt, randomUUID } from 'node:crypto';
|
|
11
11
|
import { jwtVerify } from 'jose';
|
|
12
12
|
import { redirectUriAllowed } from './client_registry.js';
|
|
13
|
+
import { AGORA_DEV_SCOPE, AGORA_DEV_SCOPE_DESCRIPTION, AGORA_DEV_SCOPE_MESSAGE } from './config.js';
|
|
13
14
|
import { normalizeHtu, verifyDpopProof } from './dpop.js';
|
|
14
15
|
import { PoppyError } from './errors.js';
|
|
15
16
|
import { replayKey } from './replay.js';
|
|
@@ -173,9 +174,24 @@ export class PoppyService {
|
|
|
173
174
|
get domains() {
|
|
174
175
|
return [this.cfg.organization.domain, ...this.cfg.organization.aliases];
|
|
175
176
|
}
|
|
176
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* Descrição de um scope para o usuário. `agora:dev` vem desmarcado na tela de consentimento
|
|
179
|
+
* (`optIn`) e, sem descrição própria do app, com o texto traduzido (`descriptionKey`).
|
|
180
|
+
*/
|
|
177
181
|
describe(ids) {
|
|
178
|
-
return ids.map((id) =>
|
|
182
|
+
return ids.map((id) => {
|
|
183
|
+
const description = this.cfg.scopes[id] ?? id;
|
|
184
|
+
if (id !== AGORA_DEV_SCOPE)
|
|
185
|
+
return { id, description };
|
|
186
|
+
return {
|
|
187
|
+
id,
|
|
188
|
+
description,
|
|
189
|
+
optIn: true,
|
|
190
|
+
...(description === AGORA_DEV_SCOPE_DESCRIPTION
|
|
191
|
+
? { descriptionKey: AGORA_DEV_SCOPE_MESSAGE }
|
|
192
|
+
: {}),
|
|
193
|
+
};
|
|
194
|
+
});
|
|
179
195
|
}
|
|
180
196
|
// ─── descoberta ───────────────────────────────────────────────────────────
|
|
181
197
|
/** A URL `https://{domain}` de um domínio (no host do issuer, a origem dele — dev com porta). */
|
package/build/src/store.d.ts
CHANGED
|
@@ -64,7 +64,11 @@ export interface RequestRow {
|
|
|
64
64
|
}
|
|
65
65
|
export declare class PoppyStore {
|
|
66
66
|
private conn;
|
|
67
|
-
|
|
67
|
+
/** Nome da tabela como os statements o escrevem (`schema.tabela` quando o app usa um schema). */
|
|
68
|
+
private t;
|
|
69
|
+
constructor(conn: () => any,
|
|
70
|
+
/** Nome da tabela como os statements o escrevem (`schema.tabela` quando o app usa um schema). */
|
|
71
|
+
t?: (name: string) => string);
|
|
68
72
|
insertSession(row: Omit<SessionRow, 'endedAt'>): Promise<void>;
|
|
69
73
|
findSession(id: string): Promise<SessionRow | null>;
|
|
70
74
|
/** Estende a vida da Session (uso). */
|
package/build/src/store.js
CHANGED
|
@@ -92,12 +92,16 @@ function toRequest(row) {
|
|
|
92
92
|
}
|
|
93
93
|
export class PoppyStore {
|
|
94
94
|
conn;
|
|
95
|
-
|
|
95
|
+
t;
|
|
96
|
+
constructor(conn,
|
|
97
|
+
/** Nome da tabela como os statements o escrevem (`schema.tabela` quando o app usa um schema). */
|
|
98
|
+
t = (name) => name) {
|
|
96
99
|
this.conn = conn;
|
|
100
|
+
this.t = t;
|
|
97
101
|
}
|
|
98
102
|
// ─── sessions ─────────────────────────────────────────────────────────────
|
|
99
103
|
async insertSession(row) {
|
|
100
|
-
await this.conn().table(SESSION_TABLE).insert({
|
|
104
|
+
await this.conn().table(this.t(SESSION_TABLE)).insert({
|
|
101
105
|
id: row.id,
|
|
102
106
|
client_id: row.clientId,
|
|
103
107
|
user_id: row.userId,
|
|
@@ -113,13 +117,13 @@ export class PoppyStore {
|
|
|
113
117
|
async findSession(id) {
|
|
114
118
|
if (typeof id !== 'string' || !id)
|
|
115
119
|
return null;
|
|
116
|
-
const row = await this.conn().from(SESSION_TABLE).where('id', id).first();
|
|
120
|
+
const row = await this.conn().from(this.t(SESSION_TABLE)).where('id', id).first();
|
|
117
121
|
return row ? toSession(row) : null;
|
|
118
122
|
}
|
|
119
123
|
/** Estende a vida da Session (uso). */
|
|
120
124
|
async touchSession(id, expiresAt, at) {
|
|
121
125
|
await this.conn()
|
|
122
|
-
.from(SESSION_TABLE)
|
|
126
|
+
.from(this.t(SESSION_TABLE))
|
|
123
127
|
.where('id', id)
|
|
124
128
|
.whereNull('ended_at')
|
|
125
129
|
.update({ expires_at: expiresAt, updated_at: at });
|
|
@@ -130,7 +134,7 @@ export class PoppyStore {
|
|
|
130
134
|
*/
|
|
131
135
|
async bindSessionAccount(id, accountId, at) {
|
|
132
136
|
const result = await this.conn()
|
|
133
|
-
.from(SESSION_TABLE)
|
|
137
|
+
.from(this.t(SESSION_TABLE))
|
|
134
138
|
.where('id', id)
|
|
135
139
|
.where((q) => q.whereNull('account_id').orWhere('account_id', accountId))
|
|
136
140
|
.update({ account_id: accountId, updated_at: at });
|
|
@@ -139,7 +143,7 @@ export class PoppyStore {
|
|
|
139
143
|
/** Encerra todas as Sessions de um agente (bloqueio no console): param na hora. */
|
|
140
144
|
async endSessionsOfClient(clientId, at) {
|
|
141
145
|
const result = await this.conn()
|
|
142
|
-
.from(SESSION_TABLE)
|
|
146
|
+
.from(this.t(SESSION_TABLE))
|
|
143
147
|
.where('client_id', clientId)
|
|
144
148
|
.whereNull('ended_at')
|
|
145
149
|
.update({ ended_at: at, grant_id: null, scope: '', updated_at: at });
|
|
@@ -147,7 +151,7 @@ export class PoppyStore {
|
|
|
147
151
|
}
|
|
148
152
|
// ─── access tokens ────────────────────────────────────────────────────────
|
|
149
153
|
async insertToken(row) {
|
|
150
|
-
await this.conn().table(TOKEN_TABLE).insert({
|
|
154
|
+
await this.conn().table(this.t(TOKEN_TABLE)).insert({
|
|
151
155
|
token_hash: row.tokenHash,
|
|
152
156
|
// `session_id`/`user_id` são NOT NULL desde a Draft 0.1 e o schema só é aditivo; o sign-in
|
|
153
157
|
// não conhece a Session nem o User ID (§4.4).
|
|
@@ -164,19 +168,19 @@ export class PoppyStore {
|
|
|
164
168
|
});
|
|
165
169
|
}
|
|
166
170
|
async findToken(hash) {
|
|
167
|
-
const row = await this.conn().from(TOKEN_TABLE).where('token_hash', hash).first();
|
|
171
|
+
const row = await this.conn().from(this.t(TOKEN_TABLE)).where('token_hash', hash).first();
|
|
168
172
|
return row ? toToken(row) : null;
|
|
169
173
|
}
|
|
170
174
|
async deleteToken(hash) {
|
|
171
|
-
return affected(await this.conn().from(TOKEN_TABLE).where('token_hash', hash).delete()) > 0;
|
|
175
|
+
return (affected(await this.conn().from(this.t(TOKEN_TABLE)).where('token_hash', hash).delete()) > 0);
|
|
172
176
|
}
|
|
173
177
|
async deleteTokensExpiredBefore(before) {
|
|
174
|
-
await this.conn().from(TOKEN_TABLE).where('expires_at', '<', before).delete();
|
|
178
|
+
await this.conn().from(this.t(TOKEN_TABLE)).where('expires_at', '<', before).delete();
|
|
175
179
|
}
|
|
176
180
|
// ─── sign-in requests ─────────────────────────────────────────────────────
|
|
177
181
|
async insertRequest(row) {
|
|
178
182
|
await this.conn()
|
|
179
|
-
.table(REQUEST_TABLE)
|
|
183
|
+
.table(this.t(REQUEST_TABLE))
|
|
180
184
|
.insert({
|
|
181
185
|
id: row.id,
|
|
182
186
|
kind: row.kind,
|
|
@@ -200,15 +204,15 @@ export class PoppyStore {
|
|
|
200
204
|
async findRequest(id) {
|
|
201
205
|
if (typeof id !== 'string' || !id)
|
|
202
206
|
return null;
|
|
203
|
-
const row = await this.conn().from(REQUEST_TABLE).where('id', id).first();
|
|
207
|
+
const row = await this.conn().from(this.t(REQUEST_TABLE)).where('id', id).first();
|
|
204
208
|
return row ? toRequest(row) : null;
|
|
205
209
|
}
|
|
206
210
|
async findRequestByCodeHash(hash) {
|
|
207
|
-
const row = await this.conn().from(REQUEST_TABLE).where('code_hash', hash).first();
|
|
211
|
+
const row = await this.conn().from(this.t(REQUEST_TABLE)).where('code_hash', hash).first();
|
|
208
212
|
return row ? toRequest(row) : null;
|
|
209
213
|
}
|
|
210
214
|
async findRequestByUserCode(userCode) {
|
|
211
|
-
const row = await this.conn().from(REQUEST_TABLE).where('user_code', userCode).first();
|
|
215
|
+
const row = await this.conn().from(this.t(REQUEST_TABLE)).where('user_code', userCode).first();
|
|
212
216
|
return row ? toRequest(row) : null;
|
|
213
217
|
}
|
|
214
218
|
/** Transição atômica — só se o pedido ainda está em `from`. */
|
|
@@ -231,7 +235,7 @@ export class PoppyStore {
|
|
|
231
235
|
if (patch.data !== undefined)
|
|
232
236
|
update.data = JSON.stringify(patch.data);
|
|
233
237
|
const result = await this.conn()
|
|
234
|
-
.from(REQUEST_TABLE)
|
|
238
|
+
.from(this.t(REQUEST_TABLE))
|
|
235
239
|
.where('id', id)
|
|
236
240
|
.where('status', from)
|
|
237
241
|
.update(update);
|
|
@@ -240,7 +244,7 @@ export class PoppyStore {
|
|
|
240
244
|
/** Conta uma tentativa errada (atômico sobre o valor lido). */
|
|
241
245
|
async bumpAttempts(id, from) {
|
|
242
246
|
const result = await this.conn()
|
|
243
|
-
.from(REQUEST_TABLE)
|
|
247
|
+
.from(this.t(REQUEST_TABLE))
|
|
244
248
|
.where('id', id)
|
|
245
249
|
.where('attempts', from)
|
|
246
250
|
.update({ attempts: from + 1 });
|
|
@@ -248,14 +252,14 @@ export class PoppyStore {
|
|
|
248
252
|
}
|
|
249
253
|
async setRequestData(id, data) {
|
|
250
254
|
await this.conn()
|
|
251
|
-
.from(REQUEST_TABLE)
|
|
255
|
+
.from(this.t(REQUEST_TABLE))
|
|
252
256
|
.where('id', id)
|
|
253
257
|
.update({ data: JSON.stringify(data) });
|
|
254
258
|
}
|
|
255
259
|
async markPolled(id, at) {
|
|
256
|
-
await this.conn().from(REQUEST_TABLE).where('id', id).update({ last_polled_at: at });
|
|
260
|
+
await this.conn().from(this.t(REQUEST_TABLE)).where('id', id).update({ last_polled_at: at });
|
|
257
261
|
}
|
|
258
262
|
async deleteRequestsExpiredBefore(before) {
|
|
259
|
-
await this.conn().from(REQUEST_TABLE).where('expires_at', '<', before).delete();
|
|
263
|
+
await this.conn().from(this.t(REQUEST_TABLE)).where('expires_at', '<', before).delete();
|
|
260
264
|
}
|
|
261
265
|
}
|
package/build/src/tables.d.ts
CHANGED
|
@@ -18,10 +18,14 @@ export declare const POPPY_TABLES: readonly AuthkitTable[];
|
|
|
18
18
|
* async up() {
|
|
19
19
|
* await ensureAuthkitSchema(this.db)
|
|
20
20
|
* await ensurePoppySchema(this.db)
|
|
21
|
+
* // with `schema.name: 'auth'`: pass `{ schema: 'auth' }` to both
|
|
21
22
|
* }
|
|
22
23
|
* }
|
|
23
24
|
* ```
|
|
24
25
|
*/
|
|
25
|
-
export declare function ensurePoppySchema(db: unknown,
|
|
26
|
+
export declare function ensurePoppySchema(db: unknown,
|
|
27
|
+
/** The same `connection` and `schema` (`schema.name`) as AuthKit's tables. */
|
|
28
|
+
options?: {
|
|
26
29
|
connection?: string;
|
|
30
|
+
schema?: string;
|
|
27
31
|
}): Promise<Pick<import("@adonis-agora/authkit-server").EnsureSchemaReport, "altered" | "created" | "indexed">>;
|
package/build/src/tables.js
CHANGED
|
@@ -147,10 +147,13 @@ export const POPPY_TABLES = [
|
|
|
147
147
|
* async up() {
|
|
148
148
|
* await ensureAuthkitSchema(this.db)
|
|
149
149
|
* await ensurePoppySchema(this.db)
|
|
150
|
+
* // with `schema.name: 'auth'`: pass `{ schema: 'auth' }` to both
|
|
150
151
|
* }
|
|
151
152
|
* }
|
|
152
153
|
* ```
|
|
153
154
|
*/
|
|
154
|
-
export function ensurePoppySchema(db,
|
|
155
|
+
export function ensurePoppySchema(db,
|
|
156
|
+
/** The same `connection` and `schema` (`schema.name`) as AuthKit's tables. */
|
|
157
|
+
options = {}) {
|
|
155
158
|
return ensureAuthkitTables(db, POPPY_TABLES, options);
|
|
156
159
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonis-agora/authkit-poppy",
|
|
3
|
-
"version": "0.3.1-rc.
|
|
3
|
+
"version": "0.3.1-rc.2",
|
|
4
4
|
"description": "Personal Agent Protocol (\"Poppy\") for AuthKit: discovery, signed Poppy-Session agent sessions, Direct/Device/Mediated sign-in, MCP and browser sessions — an optional extension of @adonis-agora/authkit-server.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dudousxd",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"node": ">=24"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@adonis-agora/authkit-server": "^1.0.0-rc.
|
|
43
|
+
"@adonis-agora/authkit-server": "^1.0.0-rc.12",
|
|
44
44
|
"@adonisjs/core": "^7.5.0",
|
|
45
45
|
"@adonisjs/session": "^8.1.0",
|
|
46
46
|
"@adonisjs/shield": "^9.0.0"
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"jose": "6.2.16"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@adonis-agora/authkit-server": "1.0.0-rc.
|
|
52
|
+
"@adonis-agora/authkit-server": "1.0.0-rc.12",
|
|
53
53
|
"@adonisjs/core": "7.6.0",
|
|
54
54
|
"@adonisjs/lucid": "22.4.2",
|
|
55
55
|
"@adonisjs/session": "8.3.0",
|