@absolutejs/auth 0.56.5 → 0.56.7
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/dist/cli/migrate.js.map +1 -1
- package/dist/index.js +62 -29
- package/dist/index.js.map +8 -8
- package/dist/oidc/config.d.ts +7 -0
- package/dist/oidc/index.d.ts +1 -1
- package/dist/oidc/index.js +8 -1
- package/dist/oidc/index.js.map +3 -3
- package/dist/oidc/types.d.ts +5 -0
- package/dist/server.js +62 -29
- package/dist/server.js.map +8 -8
- package/package.json +1 -1
package/dist/oidc/types.d.ts
CHANGED
|
@@ -80,12 +80,17 @@ export type OidcRefreshToken = {
|
|
|
80
80
|
tokenHash: string;
|
|
81
81
|
userId: string;
|
|
82
82
|
};
|
|
83
|
+
export type OidcRefreshTokenConnection = {
|
|
84
|
+
clientId: string;
|
|
85
|
+
userId: string;
|
|
86
|
+
};
|
|
83
87
|
export type OidcRefreshTokenStore = {
|
|
84
88
|
consumeToken: (tokenHash: string) => Promise<OidcRefreshToken | undefined>;
|
|
85
89
|
deleteForUser: (userId: string) => Promise<void>;
|
|
86
90
|
deleteForUserClient: (userId: string, clientId: string) => Promise<number>;
|
|
87
91
|
getToken: (tokenHash: string) => Promise<OidcRefreshToken | undefined>;
|
|
88
92
|
listClientIdsForUser: (userId: string) => Promise<string[]>;
|
|
93
|
+
listConnections: () => Promise<OidcRefreshTokenConnection[]>;
|
|
89
94
|
saveToken: (token: OidcRefreshToken) => Promise<void>;
|
|
90
95
|
};
|
|
91
96
|
export type DeviceAuthorizationStatus = 'approved' | 'denied' | 'pending';
|
package/dist/server.js
CHANGED
|
@@ -8193,6 +8193,12 @@ var oidcProviderRoutes = (config) => {
|
|
|
8193
8193
|
return errorRedirect("insufficient_user_authentication");
|
|
8194
8194
|
}
|
|
8195
8195
|
const code = generateSecureToken(TOKEN_BYTES4);
|
|
8196
|
+
const userSub = getUserId(userSession.user);
|
|
8197
|
+
await config.onAuthorizationCodeApproved?.({
|
|
8198
|
+
clientId: client.clientId,
|
|
8199
|
+
scopes: granted,
|
|
8200
|
+
userSub
|
|
8201
|
+
});
|
|
8196
8202
|
await authorizationCodeStore.saveCode({
|
|
8197
8203
|
acr: userAcr,
|
|
8198
8204
|
audience: effectiveQuery.resource,
|
|
@@ -8205,7 +8211,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8205
8211
|
nonce,
|
|
8206
8212
|
redirectUri,
|
|
8207
8213
|
scopes: granted,
|
|
8208
|
-
userId:
|
|
8214
|
+
userId: userSub
|
|
8209
8215
|
});
|
|
8210
8216
|
const params = {
|
|
8211
8217
|
code,
|
|
@@ -27164,6 +27170,20 @@ var createInMemoryOidcRefreshTokenStore = () => {
|
|
|
27164
27170
|
const active = Array.from(tokens.values()).filter((token) => token.userId === userId && token.expiresAt > now);
|
|
27165
27171
|
return Array.from(new Set(active.map((token) => token.clientId)));
|
|
27166
27172
|
},
|
|
27173
|
+
listConnections: async () => {
|
|
27174
|
+
const now = Date.now();
|
|
27175
|
+
const connections = new Map;
|
|
27176
|
+
for (const token of tokens.values()) {
|
|
27177
|
+
if (token.expiresAt <= now)
|
|
27178
|
+
continue;
|
|
27179
|
+
const connection = {
|
|
27180
|
+
clientId: token.clientId,
|
|
27181
|
+
userId: token.userId
|
|
27182
|
+
};
|
|
27183
|
+
connections.set(`${connection.userId}\x00${connection.clientId}`, connection);
|
|
27184
|
+
}
|
|
27185
|
+
return Array.from(connections.values());
|
|
27186
|
+
},
|
|
27167
27187
|
saveToken: async (token) => {
|
|
27168
27188
|
tokens.set(token.tokenHash, { ...token });
|
|
27169
27189
|
}
|
|
@@ -27584,6 +27604,13 @@ var createPostgresOidcRefreshTokenStore = (db) => ({
|
|
|
27584
27604
|
const rows = await db.selectDistinct({ client_id: oauthRefreshTokensTable.client_id }).from(oauthRefreshTokensTable).where(and(eq(oauthRefreshTokensTable.user_id, userId), gt(oauthRefreshTokensTable.expires_at_ms, Date.now())));
|
|
27585
27605
|
return rows.map((row) => row.client_id);
|
|
27586
27606
|
},
|
|
27607
|
+
listConnections: async () => {
|
|
27608
|
+
const rows = await db.selectDistinct({
|
|
27609
|
+
clientId: oauthRefreshTokensTable.client_id,
|
|
27610
|
+
userId: oauthRefreshTokensTable.user_id
|
|
27611
|
+
}).from(oauthRefreshTokensTable).where(gt(oauthRefreshTokensTable.expires_at_ms, Date.now()));
|
|
27612
|
+
return rows;
|
|
27613
|
+
},
|
|
27587
27614
|
saveToken: async (token) => {
|
|
27588
27615
|
await db.insert(oauthRefreshTokensTable).values(toRefreshValues(token));
|
|
27589
27616
|
}
|
|
@@ -29427,6 +29454,34 @@ var validatePositiveOptions = (prefix, options) => {
|
|
|
29427
29454
|
}
|
|
29428
29455
|
}
|
|
29429
29456
|
};
|
|
29457
|
+
var delegateAgentAuthorization = async (agentAuth, context, auditEmit) => {
|
|
29458
|
+
if (agentAuth === undefined)
|
|
29459
|
+
return;
|
|
29460
|
+
const registration2 = await agentAuth.registrationStore.findByClientId(context.clientId);
|
|
29461
|
+
if (registration2 === undefined || registration2.status !== "active")
|
|
29462
|
+
return;
|
|
29463
|
+
const now = Date.now();
|
|
29464
|
+
const existing = await agentAuth.delegationStore.findActiveDelegation({
|
|
29465
|
+
agentId: registration2.agentId,
|
|
29466
|
+
now,
|
|
29467
|
+
userId: context.userSub
|
|
29468
|
+
});
|
|
29469
|
+
await agentAuth.delegationStore.saveDelegation({
|
|
29470
|
+
agentId: registration2.agentId,
|
|
29471
|
+
createdAt: existing?.createdAt ?? now,
|
|
29472
|
+
delegationId: existing?.delegationId ?? `agd_${crypto.randomUUID()}`,
|
|
29473
|
+
scopes: context.scopes.filter((scope) => registration2.allowedScopes.includes(scope) && agentAuth.scopes.includes(scope)),
|
|
29474
|
+
status: "active",
|
|
29475
|
+
updatedAt: now,
|
|
29476
|
+
userId: context.userSub
|
|
29477
|
+
});
|
|
29478
|
+
await auditEmit?.({
|
|
29479
|
+
at: now,
|
|
29480
|
+
metadata: { agentId: registration2.agentId },
|
|
29481
|
+
type: "agent_delegated",
|
|
29482
|
+
userId: context.userSub
|
|
29483
|
+
});
|
|
29484
|
+
};
|
|
29430
29485
|
var buildAuthApplications = async (configuration) => {
|
|
29431
29486
|
const {
|
|
29432
29487
|
providersConfiguration,
|
|
@@ -29550,6 +29605,10 @@ var buildAuthApplications = async (configuration) => {
|
|
|
29550
29605
|
}
|
|
29551
29606
|
return handleAgentTokenGrant(resolvedAgentAuth, context.body);
|
|
29552
29607
|
},
|
|
29608
|
+
onAuthorizationCodeApproved: async (context) => {
|
|
29609
|
+
await oidc.onAuthorizationCodeApproved?.(context);
|
|
29610
|
+
await delegateAgentAuthorization(agentAuth, context, auditEmit);
|
|
29611
|
+
},
|
|
29553
29612
|
onClientRegistered: async (context) => {
|
|
29554
29613
|
await oidc.onClientRegistered?.(context);
|
|
29555
29614
|
if (agentAuth?.registerDynamicClients !== true)
|
|
@@ -29572,33 +29631,7 @@ var buildAuthApplications = async (configuration) => {
|
|
|
29572
29631
|
},
|
|
29573
29632
|
onDeviceAuthorizationApproved: async (context) => {
|
|
29574
29633
|
await oidc.onDeviceAuthorizationApproved?.(context);
|
|
29575
|
-
|
|
29576
|
-
return;
|
|
29577
|
-
const registration2 = await agentAuth.registrationStore.findByClientId(context.clientId);
|
|
29578
|
-
if (registration2 === undefined || registration2.status !== "active") {
|
|
29579
|
-
return;
|
|
29580
|
-
}
|
|
29581
|
-
const now = Date.now();
|
|
29582
|
-
const existing = await agentAuth.delegationStore.findActiveDelegation({
|
|
29583
|
-
agentId: registration2.agentId,
|
|
29584
|
-
now,
|
|
29585
|
-
userId: context.userSub
|
|
29586
|
-
});
|
|
29587
|
-
await agentAuth.delegationStore.saveDelegation({
|
|
29588
|
-
agentId: registration2.agentId,
|
|
29589
|
-
createdAt: existing?.createdAt ?? now,
|
|
29590
|
-
delegationId: existing?.delegationId ?? `agd_${crypto.randomUUID()}`,
|
|
29591
|
-
scopes: context.scopes.filter((scope) => registration2.allowedScopes.includes(scope) && agentAuth.scopes.includes(scope)),
|
|
29592
|
-
status: "active",
|
|
29593
|
-
updatedAt: now,
|
|
29594
|
-
userId: context.userSub
|
|
29595
|
-
});
|
|
29596
|
-
await auditEmit?.({
|
|
29597
|
-
at: now,
|
|
29598
|
-
metadata: { agentId: registration2.agentId },
|
|
29599
|
-
type: "agent_delegated",
|
|
29600
|
-
userId: context.userSub
|
|
29601
|
-
});
|
|
29634
|
+
await delegateAgentAuthorization(agentAuth, context, auditEmit);
|
|
29602
29635
|
}
|
|
29603
29636
|
} : undefined;
|
|
29604
29637
|
const credentialsConfig = credentials ? {
|
|
@@ -29771,5 +29804,5 @@ export {
|
|
|
29771
29804
|
auth2 as auth
|
|
29772
29805
|
};
|
|
29773
29806
|
|
|
29774
|
-
//# debugId=
|
|
29807
|
+
//# debugId=059E7E401823BC2864756E2164756E21
|
|
29775
29808
|
//# sourceMappingURL=server.js.map
|