@adonis-agora/authkit-server 0.77.0 → 0.79.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 +4 -0
- package/build/host/views/agents/consent.edge +13 -2
- package/build/host/views/agents/done.edge +3 -0
- package/build/index.d.ts +10 -0
- package/build/index.js +8 -0
- package/build/providers/authkit_server_provider.js +15 -1
- package/build/src/agents/config.d.ts +22 -3
- package/build/src/agents/config.js +22 -4
- package/build/src/agents/delegation_service.js +18 -8
- package/build/src/agents/delegation_store.d.ts +16 -0
- package/build/src/agents/delegation_store.js +44 -0
- package/build/src/agents/middleware.js +2 -1
- package/build/src/agents/poppy/client_registry.d.ts +45 -0
- package/build/src/agents/poppy/client_registry.js +226 -0
- package/build/src/agents/poppy/config.d.ts +365 -0
- package/build/src/agents/poppy/config.js +208 -0
- package/build/src/agents/poppy/dpop.d.ts +61 -0
- package/build/src/agents/poppy/dpop.js +158 -0
- package/build/src/agents/poppy/errors.d.ts +20 -0
- package/build/src/agents/poppy/errors.js +22 -0
- package/build/src/agents/poppy/replay.d.ts +25 -0
- package/build/src/agents/poppy/replay.js +106 -0
- package/build/src/agents/poppy/resource.d.ts +95 -0
- package/build/src/agents/poppy/resource.js +125 -0
- package/build/src/agents/poppy/safe_fetch.d.ts +48 -0
- package/build/src/agents/poppy/safe_fetch.js +256 -0
- package/build/src/agents/poppy/service.d.ts +286 -0
- package/build/src/agents/poppy/service.js +1464 -0
- package/build/src/agents/poppy/store.d.ts +111 -0
- package/build/src/agents/poppy/store.js +269 -0
- package/build/src/agents/poppy/web_session.d.ts +32 -0
- package/build/src/agents/poppy/web_session.js +104 -0
- package/build/src/agents/protocol.d.ts +8 -4
- package/build/src/agents/registry_store.d.ts +41 -0
- package/build/src/agents/registry_store.js +138 -0
- package/build/src/agents/runtime.d.ts +30 -1
- package/build/src/agents/runtime.js +221 -14
- package/build/src/audit/audit_sink.d.ts +1 -1
- package/build/src/audit/audit_sink.js +6 -0
- package/build/src/define_config.js +6 -0
- package/build/src/host/account_api/account_api_controller.d.ts +12 -1
- package/build/src/host/account_api/account_api_controller.js +10 -5
- package/build/src/host/admin_api/dto.d.ts +1 -1
- package/build/src/host/admin_console/admin_shell_controller.js +7 -0
- package/build/src/host/admin_console/console_personal_agents_controller.d.ts +83 -0
- package/build/src/host/admin_console/console_personal_agents_controller.js +337 -0
- package/build/src/host/admin_sessions_service.js +8 -5
- package/build/src/host/auth_host_config.d.ts +2 -1
- package/build/src/host/controllers/account_apps_controller.js +13 -3
- package/build/src/host/controllers/poppy_consent_controller.d.ts +19 -0
- package/build/src/host/controllers/poppy_consent_controller.js +173 -0
- package/build/src/host/controllers/poppy_controller.d.ts +25 -0
- package/build/src/host/controllers/poppy_controller.js +194 -0
- package/build/src/host/csrf.d.ts +7 -0
- package/build/src/host/csrf.js +16 -1
- package/build/src/host/i18n.d.ts +4 -0
- package/build/src/host/i18n.js +4 -0
- package/build/src/host/poppy_session_key.d.ts +9 -0
- package/build/src/host/poppy_session_key.js +9 -0
- package/build/src/host/register_auth_host.js +76 -0
- package/build/src/host/ui-dist/assets/index-LrScaR9C.js +155 -0
- package/build/src/host/ui-dist/index.html +1 -1
- package/build/src/provider/oidc_service.d.ts +5 -0
- package/build/src/provider/oidc_service.js +9 -2
- package/build/src/schema/ensure.js +152 -0
- package/package.json +2 -2
- package/build/src/host/ui-dist/assets/index-CIqtoNcO.js +0 -155
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
import type { DelegationStore } from '../delegation_store.js';
|
|
3
|
+
import type { PoppyClient, PoppyClientRegistry } from './client_registry.js';
|
|
4
|
+
import type { PoppyLimiter, PoppyPrincipalBase, PoppyReplayStore, ResolvedPoppyConfig } from './config.js';
|
|
5
|
+
import { type DpopNonceSource } from './dpop.js';
|
|
6
|
+
import type { PoppyStore, RequestRow } from './store.js';
|
|
7
|
+
export declare const JWT_BEARER_GRANT = "urn:ietf:params:oauth:grant-type:jwt-bearer";
|
|
8
|
+
export declare const DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
9
|
+
export declare const CLIENT_ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer";
|
|
10
|
+
export declare const BROWSER_ASSERTION_TYP = "poppy-browser+jwt";
|
|
11
|
+
/** URLs públicas do authorization server Poppy. */
|
|
12
|
+
export interface PoppyUrls {
|
|
13
|
+
origin: string;
|
|
14
|
+
issuer: string;
|
|
15
|
+
/** RFC 8414 §3.1: `/.well-known/oauth-authorization-server{issuer path}`. */
|
|
16
|
+
metadata: string;
|
|
17
|
+
token: string;
|
|
18
|
+
revocation: string;
|
|
19
|
+
authorization: string;
|
|
20
|
+
deviceAuthorization: string;
|
|
21
|
+
/** Tela do device flow (`verification_uri`). */
|
|
22
|
+
device: string;
|
|
23
|
+
mediated: string;
|
|
24
|
+
browserSession: string;
|
|
25
|
+
discovery: string;
|
|
26
|
+
}
|
|
27
|
+
/** Deriva as URLs da ORIGEM do issuer configurado — nunca do Host da request. */
|
|
28
|
+
export declare function poppyUrls(oidcIssuer: string, prefix: string): PoppyUrls;
|
|
29
|
+
/** Resposta do token endpoint (§4.2, §4.4). */
|
|
30
|
+
export interface PoppyTokenResponse {
|
|
31
|
+
access_token: string;
|
|
32
|
+
token_type: 'DPoP' | 'Bearer';
|
|
33
|
+
expires_in: number;
|
|
34
|
+
scope: string;
|
|
35
|
+
session_id: string;
|
|
36
|
+
signed_in: boolean;
|
|
37
|
+
refresh_token?: string;
|
|
38
|
+
refresh_token_expires_in?: number;
|
|
39
|
+
}
|
|
40
|
+
/** Ponte com o oidc-provider para os tokens Bearer de MCP (§4.3, §6). */
|
|
41
|
+
export interface PoppyMcpBridge {
|
|
42
|
+
/** `url` é um servidor MCP deste app (de `apis` ou do registro de resources)? */
|
|
43
|
+
isMcpResource(url: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Emite o Bearer de uma Session LOGADA como access token do oidc-provider,
|
|
46
|
+
* para que a integração MCP existente (`AccessToken.find`) o aceite. `null` =
|
|
47
|
+
* sem ponte (o token fica só no store do Poppy).
|
|
48
|
+
*/
|
|
49
|
+
mint?(input: {
|
|
50
|
+
grantId: string;
|
|
51
|
+
accountId: string;
|
|
52
|
+
clientId: string;
|
|
53
|
+
scope: string;
|
|
54
|
+
resource: string;
|
|
55
|
+
expiresIn: number;
|
|
56
|
+
grantExpiresAt: Date;
|
|
57
|
+
}): Promise<string | null>;
|
|
58
|
+
/** Revoga o grant (e os tokens) no oidc-provider. */
|
|
59
|
+
revoke?(grantId: string): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
export interface PoppyServiceDeps {
|
|
62
|
+
cfg: ResolvedPoppyConfig;
|
|
63
|
+
urls: PoppyUrls;
|
|
64
|
+
store: PoppyStore;
|
|
65
|
+
grants: DelegationStore;
|
|
66
|
+
registry: PoppyClientRegistry;
|
|
67
|
+
replay: PoppyReplayStore;
|
|
68
|
+
limiter: PoppyLimiter | null;
|
|
69
|
+
nonces: DpopNonceSource;
|
|
70
|
+
/** A conta ainda pode agir? (existe e não está desabilitada). Default: sempre. */
|
|
71
|
+
isAccountActive?: (accountId: string) => Promise<boolean>;
|
|
72
|
+
mcp?: PoppyMcpBridge;
|
|
73
|
+
now?: () => Date;
|
|
74
|
+
}
|
|
75
|
+
/** Entrada de uma request para {@link PoppyService.verifyAccess}. */
|
|
76
|
+
export interface PoppyRequestInput {
|
|
77
|
+
method: string;
|
|
78
|
+
url: string;
|
|
79
|
+
headers: Record<string, string | string[] | undefined>;
|
|
80
|
+
}
|
|
81
|
+
export interface PoppyVerifyOptions {
|
|
82
|
+
/** Scopes exigidos (todos). Faltando: `sign_in_required` (deslogado) ou `insufficient_scope`. */
|
|
83
|
+
scopes?: string[];
|
|
84
|
+
/** Exige Session logada. */
|
|
85
|
+
signedIn?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* `resource` exigido por este endpoint. Default: derivado da URL contra
|
|
88
|
+
* `apis`/`agent.protocols` do config (entradas com `resource`) e os MCP.
|
|
89
|
+
*/
|
|
90
|
+
resource?: string | null;
|
|
91
|
+
}
|
|
92
|
+
export type PoppyAuthError = 'invalid_token' | 'sign_in_required' | 'insufficient_scope' | 'invalid_dpop_proof' | 'use_dpop_nonce';
|
|
93
|
+
export type PoppyVerifyResult = {
|
|
94
|
+
ok: true;
|
|
95
|
+
principal: PoppyPrincipalBase;
|
|
96
|
+
jkt: string | null;
|
|
97
|
+
} | {
|
|
98
|
+
ok: false;
|
|
99
|
+
status: 401 | 403;
|
|
100
|
+
error: PoppyAuthError;
|
|
101
|
+
description: string;
|
|
102
|
+
scope?: string;
|
|
103
|
+
wwwAuthenticate: string;
|
|
104
|
+
/** Headers extras (`DPoP-Nonce`). */
|
|
105
|
+
headers: Record<string, string>;
|
|
106
|
+
};
|
|
107
|
+
/** Pedido Direct aguardando o usuário na tela de consentimento. */
|
|
108
|
+
export interface PoppyConsentRequest {
|
|
109
|
+
id: string;
|
|
110
|
+
clientId: string;
|
|
111
|
+
agentName: string;
|
|
112
|
+
agentOrigin: string;
|
|
113
|
+
logoUri: string | null;
|
|
114
|
+
scopes: {
|
|
115
|
+
id: string;
|
|
116
|
+
description: string;
|
|
117
|
+
}[];
|
|
118
|
+
userCode?: string;
|
|
119
|
+
}
|
|
120
|
+
export type PoppyAuthorizeOutcome = {
|
|
121
|
+
kind: 'consent';
|
|
122
|
+
request: PoppyConsentRequest;
|
|
123
|
+
} | {
|
|
124
|
+
kind: 'redirect';
|
|
125
|
+
url: string;
|
|
126
|
+
} | {
|
|
127
|
+
kind: 'error';
|
|
128
|
+
description: string;
|
|
129
|
+
};
|
|
130
|
+
export interface PoppyGrantSummary {
|
|
131
|
+
id: string;
|
|
132
|
+
clientId: string;
|
|
133
|
+
scopes: {
|
|
134
|
+
id: string;
|
|
135
|
+
description: string;
|
|
136
|
+
}[];
|
|
137
|
+
createdAt: Date;
|
|
138
|
+
updatedAt: Date;
|
|
139
|
+
expiresAt: Date;
|
|
140
|
+
}
|
|
141
|
+
export type PoppyMediatedResponse = ({
|
|
142
|
+
status: 'complete';
|
|
143
|
+
} & PoppyTokenResponse) | {
|
|
144
|
+
status: 'code_required';
|
|
145
|
+
sign_in_id: string;
|
|
146
|
+
code: {
|
|
147
|
+
sent_to: string;
|
|
148
|
+
};
|
|
149
|
+
expires_at: string;
|
|
150
|
+
} | {
|
|
151
|
+
status: 'failed';
|
|
152
|
+
} | {
|
|
153
|
+
status: 'expired';
|
|
154
|
+
};
|
|
155
|
+
export interface PoppyBrowserSessionResult {
|
|
156
|
+
sessionId: string;
|
|
157
|
+
clientId: string;
|
|
158
|
+
userId: string;
|
|
159
|
+
accountId: string | null;
|
|
160
|
+
scopes: string[];
|
|
161
|
+
returnTo: string;
|
|
162
|
+
}
|
|
163
|
+
/** Estado atual de uma Session (para o cookie do site acompanhar — §5). */
|
|
164
|
+
export interface PoppySessionState {
|
|
165
|
+
active: boolean;
|
|
166
|
+
sessionId: string;
|
|
167
|
+
clientId: string;
|
|
168
|
+
userId: string;
|
|
169
|
+
accountId: string | null;
|
|
170
|
+
signedIn: boolean;
|
|
171
|
+
scopes: string[];
|
|
172
|
+
}
|
|
173
|
+
/** Aceita o código como o usuário digitar: minúsculas, sem hífen, com espaços. */
|
|
174
|
+
export declare function normalizePoppyUserCode(input: unknown): string | null;
|
|
175
|
+
/** Slot global onde o `@adonis-agora/agent` registra o endpoint de conversas Poppy. */
|
|
176
|
+
export declare const POPPY_ENDPOINTS_SLOT: unique symbol;
|
|
177
|
+
/**
|
|
178
|
+
* `agent.protocols` vindo do slot `Symbol.for('@adonis-agora/poppy:endpoints')`
|
|
179
|
+
* (`{ conversations: 'https://…' }`), usado quando o config não declara
|
|
180
|
+
* `agent.protocols` — o mesmo padrão do slot de resources do MCP.
|
|
181
|
+
*/
|
|
182
|
+
export declare function registeredConversationProtocols(): {
|
|
183
|
+
type: string;
|
|
184
|
+
endpoint: string;
|
|
185
|
+
resource?: string;
|
|
186
|
+
}[];
|
|
187
|
+
/**
|
|
188
|
+
* @experimental Poppy (Personal Agent Protocol) Draft 0.1 — pode mudar de forma incompatível enquanto a spec for draft.
|
|
189
|
+
*/
|
|
190
|
+
export declare class PoppyService {
|
|
191
|
+
#private;
|
|
192
|
+
readonly cfg: ResolvedPoppyConfig;
|
|
193
|
+
readonly urls: PoppyUrls;
|
|
194
|
+
readonly registry: PoppyClientRegistry;
|
|
195
|
+
constructor(deps: PoppyServiceDeps);
|
|
196
|
+
/** Um nonce DPoP novo (header `DPoP-Nonce`), quando o app exige nonces. */
|
|
197
|
+
nonce(): string | null;
|
|
198
|
+
/** Domínios da empresa (o principal + aliases). */
|
|
199
|
+
get domains(): string[];
|
|
200
|
+
/** Descrição de um scope para o usuário. */
|
|
201
|
+
describe(ids: string[]): {
|
|
202
|
+
id: string;
|
|
203
|
+
description: string;
|
|
204
|
+
}[];
|
|
205
|
+
/** `/.well-known/poppy.json` (§3) para o domínio pedido; `null` = domínio que não é nosso. */
|
|
206
|
+
discoveryDocument(requestHost: string): Record<string, unknown> | null;
|
|
207
|
+
/** RFC 8414 com `poppy_domains` (§3.2). */
|
|
208
|
+
authorizationServerMetadata(): Record<string, unknown>;
|
|
209
|
+
/**
|
|
210
|
+
* `private_key_jwt` (RFC 7523 §2.2, §3): `client_assertion` assinada por uma
|
|
211
|
+
* chave do `jwks_uri`, `iss` = `sub` = `client_id`, `aud` = o endpoint
|
|
212
|
+
* chamado (ou o token endpoint/issuer), `exp` curto, `jti` único.
|
|
213
|
+
*/
|
|
214
|
+
authenticateClient(form: Record<string, unknown>, endpoint: string): Promise<PoppyClient>;
|
|
215
|
+
/** `POST token_endpoint` (§4.2, §4.3, §4.5, §4.6, §4.8). */
|
|
216
|
+
token(form: Record<string, unknown>, dpopHeader: string | string[] | undefined): Promise<PoppyTokenResponse>;
|
|
217
|
+
/** `POST device_authorization_endpoint` (§4.6). */
|
|
218
|
+
deviceAuthorization(form: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
219
|
+
/** `POST revocation_endpoint` (§4.9, RFC 7009). */
|
|
220
|
+
revoke(form: Record<string, unknown>): Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* Revoga um Account Token (grant): as Sessions logadas com ele continuam
|
|
223
|
+
* deslogadas (§4.9) e os Bearer de MCP no oidc-provider morrem junto.
|
|
224
|
+
*/
|
|
225
|
+
revokeGrant(grantId: string): Promise<void>;
|
|
226
|
+
/**
|
|
227
|
+
* `GET authorization_endpoint` com o usuário já logado neste app. Erros no
|
|
228
|
+
* `client_id`/`redirect_uri` não redirecionam (RFC 6749 §4.1.2.1); os demais
|
|
229
|
+
* voltam ao agente com `error`, `state` e `iss`.
|
|
230
|
+
*/
|
|
231
|
+
startAuthorization(params: Record<string, unknown>, accountId: string): Promise<PoppyAuthorizeOutcome>;
|
|
232
|
+
/**
|
|
233
|
+
* `POST` da tela de consentimento Direct. Devolve para onde mandar o
|
|
234
|
+
* navegador (`code`/`error`, `state`, `iss`), ou `null` quando o pedido não
|
|
235
|
+
* vale mais (expirou, decidido em outra aba, de outra conta).
|
|
236
|
+
*/
|
|
237
|
+
decideAuthorization(input: {
|
|
238
|
+
requestId: string;
|
|
239
|
+
accountId: string;
|
|
240
|
+
allow: boolean;
|
|
241
|
+
scopes: string[];
|
|
242
|
+
}): Promise<{
|
|
243
|
+
url: string;
|
|
244
|
+
approved: string[] | null;
|
|
245
|
+
clientId: string;
|
|
246
|
+
} | null>;
|
|
247
|
+
pendingDevice(userCodeInput: unknown): Promise<PoppyConsentRequest | null>;
|
|
248
|
+
/** Aprova (scopes marcados) ou nega um device code. `null` = não está mais pendente. */
|
|
249
|
+
decideDevice(input: {
|
|
250
|
+
userCode: string;
|
|
251
|
+
accountId: string;
|
|
252
|
+
allow: boolean;
|
|
253
|
+
scopes: string[];
|
|
254
|
+
}): Promise<{
|
|
255
|
+
approved: string[] | null;
|
|
256
|
+
clientId: string;
|
|
257
|
+
} | null>;
|
|
258
|
+
/** `POST auth.mediated.endpoint` — já autenticado pelo Session Token (DPoP). */
|
|
259
|
+
mediatedStart(principal: PoppyPrincipalBase, jkt: string | null, body: unknown, ctx: HttpContext): Promise<PoppyMediatedResponse>;
|
|
260
|
+
/** `POST {mediated}/{sign_in_id}` com o código de uso único. */
|
|
261
|
+
mediatedCode(principal: PoppyPrincipalBase, jkt: string | null, signInId: string, body: unknown): Promise<PoppyMediatedResponse | null>;
|
|
262
|
+
/**
|
|
263
|
+
* Verifica `Authorization: DPoP|Bearer` (+ prova DPoP) de uma request a uma API
|
|
264
|
+
* ou conversa do app. Nunca lê token da URL (§4.3).
|
|
265
|
+
*/
|
|
266
|
+
verifyAccess(input: PoppyRequestInput, options?: PoppyVerifyOptions): Promise<PoppyVerifyResult>;
|
|
267
|
+
/**
|
|
268
|
+
* Confere a asserção de navegador (`typ` `poppy-browser+jwt`). `requestOrigin`
|
|
269
|
+
* é a origem em que o POST chegou — o cookie precisa nascer nela.
|
|
270
|
+
*/
|
|
271
|
+
verifyBrowserAssertion(assertion: unknown, requestOrigin: string): Promise<PoppyBrowserSessionResult>;
|
|
272
|
+
/** Estado atual da Session (ativa? logada? scopes) — o cookie do site segue isto. */
|
|
273
|
+
sessionState(sessionId: string): Promise<PoppySessionState | null>;
|
|
274
|
+
listGrants(accountId: string): Promise<PoppyGrantSummary[]>;
|
|
275
|
+
/** Desconectar o agente pela conta (§4.9): revoga um Account Token DA CONTA. */
|
|
276
|
+
revokeAccountGrant(accountId: string, grantId: string): Promise<boolean>;
|
|
277
|
+
/** Revoga todos os Account Tokens da conta (sair de tudo, conta suspensa…). */
|
|
278
|
+
revokeAllAccountGrants(accountId: string): Promise<number>;
|
|
279
|
+
/**
|
|
280
|
+
* Bloqueio pelo console admin: revoga todos os Account Tokens do agente (todas as
|
|
281
|
+
* contas) e encerra as Sessions dele — os Session Tokens param na próxima request.
|
|
282
|
+
* Devolve quantos Account Tokens estavam vivos.
|
|
283
|
+
*/
|
|
284
|
+
disconnectClient(clientId: string): Promise<number>;
|
|
285
|
+
}
|
|
286
|
+
export type { RequestRow };
|