@absolutejs/auth 0.55.0 → 0.55.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/README.md +7 -0
- package/dist/agents/context.d.ts +46 -0
- package/dist/agents/index.d.ts +2 -1
- package/dist/agents/index.js +47 -37
- package/dist/agents/index.js.map +5 -4
- package/dist/agents/routes.d.ts +29 -22
- package/dist/apikeys/routes.d.ts +2 -2
- package/dist/authInstance.d.ts +12 -0
- package/dist/authorization/protectPermission.d.ts +2 -2
- package/dist/credentials/login.d.ts +4 -4
- package/dist/credentials/routes.d.ts +4 -4
- package/dist/index.d.ts +3 -303
- package/dist/index.js +196 -182
- package/dist/index.js.map +7 -6
- package/dist/mfa/routes.d.ts +2 -2
- package/dist/mfa/sms.d.ts +2 -2
- package/dist/oidc/routes.d.ts +13 -13
- package/dist/organizations/routes.d.ts +1 -1
- package/dist/portal/routes.d.ts +3 -3
- package/dist/roles/routes.d.ts +1 -1
- package/dist/routes/protectRoute.d.ts +2 -2
- package/dist/routes/refresh.d.ts +1 -1
- package/dist/routes/revoke.d.ts +1 -1
- package/dist/routes/sessions.d.ts +3 -3
- package/dist/server.d.ts +18 -0
- package/dist/server.js +29365 -0
- package/dist/server.js.map +288 -0
- package/dist/sso/discoveryRoute.d.ts +1 -1
- package/dist/sso/oidcRoutes.d.ts +2 -2
- package/dist/sso/samlRoutes.d.ts +4 -4
- package/dist/utils.d.ts +1 -1
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Absolute Auth
|
|
2
2
|
|
|
3
|
+
Server applications should import the primary authentication contract from
|
|
4
|
+
`@absolutejs/auth/server`. This declaration-stable entry point exposes `auth`,
|
|
5
|
+
session types, route protection, provider configuration, and the other core
|
|
6
|
+
server utilities without loading declarations for every optional Auth feature.
|
|
7
|
+
The root entry point remains available for applications that need the complete
|
|
8
|
+
feature export surface.
|
|
9
|
+
|
|
3
10
|
## Overview
|
|
4
11
|
|
|
5
12
|
Absolute Auth is a TypeScript-based authentication system that provides a comprehensive solution for handling user authentication in web applications. It supports multiple authentication providers and offers features such as authorization, callback handling, token refresh, token revocation, and session management.
|
|
@@ -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 {};
|
package/dist/agents/index.d.ts
CHANGED
|
@@ -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,
|
|
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';
|
package/dist/agents/index.js
CHANGED
|
@@ -1423,12 +1423,16 @@ var resolveAgentPrincipal = async (request, config) => {
|
|
|
1423
1423
|
userId: delegation.userId
|
|
1424
1424
|
};
|
|
1425
1425
|
};
|
|
1426
|
-
// src/agents/
|
|
1426
|
+
// src/agents/context.ts
|
|
1427
1427
|
import { Elysia } from "elysia";
|
|
1428
|
+
var DELETE_CODE_POINT = 127;
|
|
1429
|
+
var HTTP_FORBIDDEN = 403;
|
|
1430
|
+
var HTTP_UNAUTHORIZED = 401;
|
|
1431
|
+
var MINIMUM_PRINTABLE_CODE_POINT = 32;
|
|
1428
1432
|
var quoteHeaderValue = (value) => {
|
|
1429
1433
|
const printable = [...value].filter((character) => {
|
|
1430
1434
|
const codePoint = character.codePointAt(0) ?? 0;
|
|
1431
|
-
return codePoint >=
|
|
1435
|
+
return codePoint >= MINIMUM_PRINTABLE_CODE_POINT && codePoint !== DELETE_CODE_POINT;
|
|
1432
1436
|
}).join("");
|
|
1433
1437
|
return `"${printable.replace(/[\\"]/g, "\\$&")}"`;
|
|
1434
1438
|
};
|
|
@@ -1461,9 +1465,40 @@ var failureResponse = (config, failure, requiredScopes) => new Response(JSON.str
|
|
|
1461
1465
|
requiredScopes
|
|
1462
1466
|
})
|
|
1463
1467
|
},
|
|
1464
|
-
status: failure.code === "Forbidden" ?
|
|
1468
|
+
status: failure.code === "Forbidden" ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED
|
|
1465
1469
|
});
|
|
1466
|
-
var
|
|
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;
|
|
1501
|
+
var json = (value, status = HTTP_OK) => new Response(JSON.stringify(value), {
|
|
1467
1502
|
headers: {
|
|
1468
1503
|
"cache-control": "no-store",
|
|
1469
1504
|
"content-type": "application/json"
|
|
@@ -1497,7 +1532,7 @@ var registrationResponse = (result) => {
|
|
|
1497
1532
|
...body,
|
|
1498
1533
|
error: "interaction_required",
|
|
1499
1534
|
error_description: "Authenticate at the service and confirm the account link."
|
|
1500
|
-
},
|
|
1535
|
+
}, HTTP_UNAUTHORIZED2);
|
|
1501
1536
|
}
|
|
1502
1537
|
return json(body);
|
|
1503
1538
|
};
|
|
@@ -1525,33 +1560,7 @@ var parseRegistrationInput = (value) => {
|
|
|
1525
1560
|
};
|
|
1526
1561
|
var escapeHtml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
1527
1562
|
var agentAuthPlugin = (config) => {
|
|
1528
|
-
const plugin =
|
|
1529
|
-
protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
|
|
1530
|
-
if (config === undefined) {
|
|
1531
|
-
const failure = {
|
|
1532
|
-
code: "Unauthorized",
|
|
1533
|
-
message: "Agent is not authenticated"
|
|
1534
|
-
};
|
|
1535
|
-
return await handleAuthFail?.(failure) ?? new Response(failure.message, { status: 401 });
|
|
1536
|
-
}
|
|
1537
|
-
const principal = await resolveAgentPrincipal(request, config);
|
|
1538
|
-
if (principal === undefined) {
|
|
1539
|
-
const failure = {
|
|
1540
|
-
code: "Unauthorized",
|
|
1541
|
-
message: "Agent is not authenticated"
|
|
1542
|
-
};
|
|
1543
|
-
return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
|
|
1544
|
-
}
|
|
1545
|
-
if (!agentHasScopes(principal, requiredScopes)) {
|
|
1546
|
-
const failure = {
|
|
1547
|
-
code: "Forbidden",
|
|
1548
|
-
message: "Insufficient agent scopes"
|
|
1549
|
-
};
|
|
1550
|
-
return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
|
|
1551
|
-
}
|
|
1552
|
-
return handleAuth(principal);
|
|
1553
|
-
}
|
|
1554
|
-
}));
|
|
1563
|
+
const plugin = agentAuthContextPlugin(config);
|
|
1555
1564
|
if (config === undefined)
|
|
1556
1565
|
return plugin.as("global");
|
|
1557
1566
|
if (config.agentRegistration === undefined) {
|
|
@@ -1582,11 +1591,11 @@ var agentAuthPlugin = (config) => {
|
|
|
1582
1591
|
}).post(identityRoute, async ({ body }) => {
|
|
1583
1592
|
const value = recordBody(body);
|
|
1584
1593
|
if (value === undefined || typeof value.type !== "string") {
|
|
1585
|
-
return json({ error: "invalid_request" },
|
|
1594
|
+
return json({ error: "invalid_request" }, HTTP_BAD_REQUEST);
|
|
1586
1595
|
}
|
|
1587
1596
|
const input = parseRegistrationInput(value);
|
|
1588
1597
|
if (input === undefined)
|
|
1589
|
-
return json({ error: "invalid_request" },
|
|
1598
|
+
return json({ error: "invalid_request" }, HTTP_BAD_REQUEST);
|
|
1590
1599
|
const result = await startAgentRegistration(config, input);
|
|
1591
1600
|
if ("error" in result) {
|
|
1592
1601
|
return json({
|
|
@@ -1598,7 +1607,7 @@ var agentAuthPlugin = (config) => {
|
|
|
1598
1607
|
}).post(claimRoute, async ({ body }) => {
|
|
1599
1608
|
const value = recordBody(body);
|
|
1600
1609
|
if (value === undefined || typeof value.claim_token !== "string" || typeof value.email !== "string") {
|
|
1601
|
-
return json({ error: "invalid_request" },
|
|
1610
|
+
return json({ error: "invalid_request" }, HTTP_BAD_REQUEST);
|
|
1602
1611
|
}
|
|
1603
1612
|
const result = await beginAgentClaim(config, {
|
|
1604
1613
|
claimToken: value.claim_token,
|
|
@@ -1613,7 +1622,7 @@ var agentAuthPlugin = (config) => {
|
|
|
1613
1622
|
value = Object.fromEntries(new URLSearchParams(body));
|
|
1614
1623
|
}
|
|
1615
1624
|
if (value === undefined || typeof value.claim_attempt_token !== "string" || typeof value.user_code !== "string") {
|
|
1616
|
-
return json({ error: "invalid_request" },
|
|
1625
|
+
return json({ error: "invalid_request" }, HTTP_BAD_REQUEST);
|
|
1617
1626
|
}
|
|
1618
1627
|
const result = await completeAgentClaim(config, {
|
|
1619
1628
|
attemptToken: value.claim_attempt_token,
|
|
@@ -12819,6 +12828,7 @@ export {
|
|
|
12819
12828
|
agentHasScopes,
|
|
12820
12829
|
agentDelegationsTable,
|
|
12821
12830
|
agentAuthPlugin,
|
|
12831
|
+
agentAuthContextPlugin,
|
|
12822
12832
|
agentAuthChallenge,
|
|
12823
12833
|
DEFAULT_AGENT_RESOURCE_METADATA_ROUTE,
|
|
12824
12834
|
AGENT_IDENTITY_ASSERTION_TYPE,
|
|
@@ -12826,5 +12836,5 @@ export {
|
|
|
12826
12836
|
AGENT_CLAIM_GRANT_TYPE
|
|
12827
12837
|
};
|
|
12828
12838
|
|
|
12829
|
-
//# debugId=
|
|
12839
|
+
//# debugId=35BBF77DF315307D64756E2164756E21
|
|
12830
12840
|
//# sourceMappingURL=index.js.map
|