@absolutejs/auth 0.55.1 → 0.55.3

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.
@@ -0,0 +1,46 @@
1
+ import { Elysia } from 'elysia';
2
+ import { type AgentAuthConfig } from './config';
3
+ import type { AgentPrincipal } from './types';
4
+ type AgentAuthFailure = {
5
+ code: 'Forbidden' | 'Unauthorized';
6
+ message: 'Agent is not authenticated' | 'Insufficient agent scopes';
7
+ };
8
+ export declare const agentAuthChallenge: ({ config, error, requiredScopes }: {
9
+ config: AgentAuthConfig;
10
+ error?: "invalid_token" | "insufficient_scope";
11
+ requiredScopes?: string[];
12
+ }) => string;
13
+ export declare const agentResourceMetadataUrl: (config: AgentAuthConfig) => string;
14
+ export declare const agentAuthContextPlugin: (config?: AgentAuthConfig) => Elysia<"", {
15
+ decorator: {};
16
+ store: {};
17
+ derive: {};
18
+ resolve: {};
19
+ }, {
20
+ typebox: {};
21
+ error: {};
22
+ }, {
23
+ schema: {};
24
+ standaloneSchema: {};
25
+ macro: {};
26
+ macroFn: {};
27
+ parser: {};
28
+ response: {};
29
+ }, {}, {
30
+ derive: {};
31
+ resolve: {};
32
+ schema: {};
33
+ standaloneSchema: {};
34
+ response: {};
35
+ }, {
36
+ derive: {
37
+ readonly protectAgent: <AuthReturn, AuthFailReturn>(requiredScopes: string[], handleAuth: (principal: AgentPrincipal) => AuthReturn | Promise<AuthReturn>, handleAuthFail?: (error: AgentAuthFailure) => AuthFailReturn | Promise<AuthFailReturn>) => Promise<Response | AuthReturn | NonNullable<Awaited<AuthFailReturn>>>;
38
+ };
39
+ resolve: {};
40
+ schema: {};
41
+ standaloneSchema: {};
42
+ response: import("elysia").ExtractErrorFromHandle<{
43
+ readonly protectAgent: <AuthReturn, AuthFailReturn>(requiredScopes: string[], handleAuth: (principal: AgentPrincipal) => AuthReturn | Promise<AuthReturn>, handleAuthFail?: (error: AgentAuthFailure) => AuthFailReturn | Promise<AuthFailReturn>) => Promise<Response | AuthReturn | NonNullable<Awaited<AuthFailReturn>>>;
44
+ }>;
45
+ }>;
46
+ export {};
@@ -6,6 +6,7 @@ export * from './idJag';
6
6
  export * from '../oidc/clientIdMetadata';
7
7
  export { createOidcAgentCredentialVerifier } from './oidcAdapter';
8
8
  export { agentHasScopes, resolveAgentPrincipal } from './principal';
9
- export { agentAuthChallenge, agentAuthPlugin } from './routes';
9
+ export { agentAuthChallenge, agentAuthContextPlugin } from './context';
10
+ export { agentAuthPlugin } from './routes';
10
11
  export { createInMemoryAgentDelegationStore, createInMemoryAgentIdentityRegistrationStore, createInMemoryAgentRegistrationStore } from './inMemoryStores';
11
12
  export { agentDelegationsTable, agentIdentityRegistrationsTable, agentRegistrationsTable, createNeonAgentDelegationStore, createNeonAgentIdentityRegistrationStore, createNeonAgentRegistrationStore, createPostgresAgentDelegationStore, createPostgresAgentIdentityRegistrationStore, createPostgresAgentRegistrationStore } from './postgresStores';
@@ -1423,12 +1423,10 @@ var resolveAgentPrincipal = async (request, config) => {
1423
1423
  userId: delegation.userId
1424
1424
  };
1425
1425
  };
1426
- // src/agents/routes.ts
1426
+ // src/agents/context.ts
1427
1427
  import { Elysia } from "elysia";
1428
1428
  var DELETE_CODE_POINT = 127;
1429
- var HTTP_BAD_REQUEST = 400;
1430
1429
  var HTTP_FORBIDDEN = 403;
1431
- var HTTP_OK = 200;
1432
1430
  var HTTP_UNAUTHORIZED = 401;
1433
1431
  var MINIMUM_PRINTABLE_CODE_POINT = 32;
1434
1432
  var quoteHeaderValue = (value) => {
@@ -1469,6 +1467,37 @@ var failureResponse = (config, failure, requiredScopes) => new Response(JSON.str
1469
1467
  },
1470
1468
  status: failure.code === "Forbidden" ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED
1471
1469
  });
1470
+ var agentAuthContextPlugin = (config) => new Elysia().derive(({ request }) => ({
1471
+ protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
1472
+ if (config === undefined) {
1473
+ const failure = {
1474
+ code: "Unauthorized",
1475
+ message: "Agent is not authenticated"
1476
+ };
1477
+ return await handleAuthFail?.(failure) ?? new Response(failure.message, { status: HTTP_UNAUTHORIZED });
1478
+ }
1479
+ const principal = await resolveAgentPrincipal(request, config);
1480
+ if (principal === undefined) {
1481
+ const failure = {
1482
+ code: "Unauthorized",
1483
+ message: "Agent is not authenticated"
1484
+ };
1485
+ return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
1486
+ }
1487
+ if (!agentHasScopes(principal, requiredScopes)) {
1488
+ const failure = {
1489
+ code: "Forbidden",
1490
+ message: "Insufficient agent scopes"
1491
+ };
1492
+ return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
1493
+ }
1494
+ return handleAuth(principal);
1495
+ }
1496
+ }));
1497
+ // src/agents/routes.ts
1498
+ var HTTP_BAD_REQUEST = 400;
1499
+ var HTTP_OK = 200;
1500
+ var HTTP_UNAUTHORIZED2 = 401;
1472
1501
  var json = (value, status = HTTP_OK) => new Response(JSON.stringify(value), {
1473
1502
  headers: {
1474
1503
  "cache-control": "no-store",
@@ -1503,7 +1532,7 @@ var registrationResponse = (result) => {
1503
1532
  ...body,
1504
1533
  error: "interaction_required",
1505
1534
  error_description: "Authenticate at the service and confirm the account link."
1506
- }, HTTP_UNAUTHORIZED);
1535
+ }, HTTP_UNAUTHORIZED2);
1507
1536
  }
1508
1537
  return json(body);
1509
1538
  };
@@ -1530,33 +1559,6 @@ var parseRegistrationInput = (value) => {
1530
1559
  return input;
1531
1560
  };
1532
1561
  var escapeHtml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
1533
- var agentAuthContextPlugin = (config) => new Elysia().derive(({ request }) => ({
1534
- protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
1535
- if (config === undefined) {
1536
- const failure = {
1537
- code: "Unauthorized",
1538
- message: "Agent is not authenticated"
1539
- };
1540
- return await handleAuthFail?.(failure) ?? new Response(failure.message, { status: 401 });
1541
- }
1542
- const principal = await resolveAgentPrincipal(request, config);
1543
- if (principal === undefined) {
1544
- const failure = {
1545
- code: "Unauthorized",
1546
- message: "Agent is not authenticated"
1547
- };
1548
- return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
1549
- }
1550
- if (!agentHasScopes(principal, requiredScopes)) {
1551
- const failure = {
1552
- code: "Forbidden",
1553
- message: "Insufficient agent scopes"
1554
- };
1555
- return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
1556
- }
1557
- return handleAuth(principal);
1558
- }
1559
- }));
1560
1562
  var agentAuthPlugin = (config) => {
1561
1563
  const plugin = agentAuthContextPlugin(config);
1562
1564
  if (config === undefined)
@@ -12826,6 +12828,7 @@ export {
12826
12828
  agentHasScopes,
12827
12829
  agentDelegationsTable,
12828
12830
  agentAuthPlugin,
12831
+ agentAuthContextPlugin,
12829
12832
  agentAuthChallenge,
12830
12833
  DEFAULT_AGENT_RESOURCE_METADATA_ROUTE,
12831
12834
  AGENT_IDENTITY_ASSERTION_TYPE,
@@ -12833,5 +12836,5 @@ export {
12833
12836
  AGENT_CLAIM_GRANT_TYPE
12834
12837
  };
12835
12838
 
12836
- //# debugId=05CB90C7C290284064756E2164756E21
12839
+ //# debugId=35BBF77DF315307D64756E2164756E21
12837
12840
  //# sourceMappingURL=index.js.map