@absolutejs/auth 0.56.6 → 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/index.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: getUserId(userSession.user)
8214
+ userId: userSub
8209
8215
  });
8210
8216
  const params = {
8211
8217
  code,
@@ -29448,6 +29454,34 @@ var validatePositiveOptions = (prefix, options) => {
29448
29454
  }
29449
29455
  }
29450
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
+ };
29451
29485
  var buildAuthApplications = async (configuration) => {
29452
29486
  const {
29453
29487
  providersConfiguration,
@@ -29571,6 +29605,10 @@ var buildAuthApplications = async (configuration) => {
29571
29605
  }
29572
29606
  return handleAgentTokenGrant(resolvedAgentAuth, context.body);
29573
29607
  },
29608
+ onAuthorizationCodeApproved: async (context) => {
29609
+ await oidc.onAuthorizationCodeApproved?.(context);
29610
+ await delegateAgentAuthorization(agentAuth, context, auditEmit);
29611
+ },
29574
29612
  onClientRegistered: async (context) => {
29575
29613
  await oidc.onClientRegistered?.(context);
29576
29614
  if (agentAuth?.registerDynamicClients !== true)
@@ -29593,33 +29631,7 @@ var buildAuthApplications = async (configuration) => {
29593
29631
  },
29594
29632
  onDeviceAuthorizationApproved: async (context) => {
29595
29633
  await oidc.onDeviceAuthorizationApproved?.(context);
29596
- if (agentAuth === undefined)
29597
- return;
29598
- const registration2 = await agentAuth.registrationStore.findByClientId(context.clientId);
29599
- if (registration2 === undefined || registration2.status !== "active") {
29600
- return;
29601
- }
29602
- const now = Date.now();
29603
- const existing = await agentAuth.delegationStore.findActiveDelegation({
29604
- agentId: registration2.agentId,
29605
- now,
29606
- userId: context.userSub
29607
- });
29608
- await agentAuth.delegationStore.saveDelegation({
29609
- agentId: registration2.agentId,
29610
- createdAt: existing?.createdAt ?? now,
29611
- delegationId: existing?.delegationId ?? `agd_${crypto.randomUUID()}`,
29612
- scopes: context.scopes.filter((scope) => registration2.allowedScopes.includes(scope) && agentAuth.scopes.includes(scope)),
29613
- status: "active",
29614
- updatedAt: now,
29615
- userId: context.userSub
29616
- });
29617
- await auditEmit?.({
29618
- at: now,
29619
- metadata: { agentId: registration2.agentId },
29620
- type: "agent_delegated",
29621
- userId: context.userSub
29622
- });
29634
+ await delegateAgentAuthorization(agentAuth, context, auditEmit);
29623
29635
  }
29624
29636
  } : undefined;
29625
29637
  const credentialsConfig = credentials ? {
@@ -30262,5 +30274,5 @@ export {
30262
30274
  AGENT_CLAIM_GRANT_TYPE
30263
30275
  };
30264
30276
 
30265
- //# debugId=6D5EA8306E36581E64756E2164756E21
30277
+ //# debugId=76D3175D5506623864756E2164756E21
30266
30278
  //# sourceMappingURL=index.js.map