@adonis-agora/authkit-poppy 0.3.1-rc.0 → 0.3.1-rc.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @adonis-agora/authkit-poppy
2
2
 
3
+ ## 0.3.1-rc.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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`.
8
+
9
+ `@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`).
10
+
3
11
  ## 0.3.1-rc.0
4
12
 
5
13
  ### 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';
@@ -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;
@@ -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
- return {
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
  }
@@ -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';
@@ -91,6 +91,16 @@ async function resolveReplay(replay, host) {
91
91
  const redis = await host.make('redis');
92
92
  return redisReplayStore(redis.connection(replay.redis));
93
93
  }
94
+ /** O app serve os dev tools do Agora (`@adonis-agora/agent` ligou `'agora.devTools'`)? */
95
+ async function servesDevTools(host) {
96
+ try {
97
+ const hub = await host.make('agora.devTools');
98
+ return typeof hub === 'object' && hub !== null;
99
+ }
100
+ catch {
101
+ return false;
102
+ }
103
+ }
94
104
  /** Bearer de MCP de Sessions logadas viram access tokens do oidc-provider (§7). */
95
105
  function mcpBridge(cfg, host) {
96
106
  const tokens = host.accessTokens;
@@ -141,7 +151,10 @@ export function poppy(config, options = {}) {
141
151
  },
142
152
  routes: (router, kit) => registerRoutes(router, resolved.prefix, kit),
143
153
  async setup(host) {
144
- const cfg = withRegistry(resolved, host);
154
+ const offered = resolved.devTools === null && (await servesDevTools(host))
155
+ ? withAgoraDevScope(resolved, config)
156
+ : resolved;
157
+ const cfg = withRegistry(offered, host);
145
158
  const limiter = cfg.rateLimit === false
146
159
  ? null
147
160
  : typeof cfg.rateLimit === 'function'
@@ -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
  };
@@ -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
  };
@@ -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
- /** Descrição de um scope para o usuário. */
189
- describe(ids: string[]): {
190
- id: string;
191
- description: string;
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. */
@@ -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
- /** Descrição de um scope para o usuário. */
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) => ({ id, description: this.cfg.scopes[id] ?? 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonis-agora/authkit-poppy",
3
- "version": "0.3.1-rc.0",
3
+ "version": "0.3.1-rc.1",
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.4",
43
+ "@adonis-agora/authkit-server": "^1.0.0-rc.6",
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.4",
52
+ "@adonis-agora/authkit-server": "1.0.0-rc.6",
53
53
  "@adonisjs/core": "7.6.0",
54
54
  "@adonisjs/lucid": "22.4.2",
55
55
  "@adonisjs/session": "8.3.0",