@absolutejs/auth 0.56.0 → 0.56.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/dist/index.d.ts CHANGED
@@ -1734,6 +1734,7 @@ export declare const createAuthApplications: <UserType>(configuration: AuthConfi
1734
1734
  scope?: string | undefined;
1735
1735
  nonce?: string | undefined;
1736
1736
  claims?: string | undefined;
1737
+ resource?: string | undefined;
1737
1738
  request?: string | undefined;
1738
1739
  redirect_uri?: string | undefined;
1739
1740
  acr_values?: string | undefined;
package/dist/index.js CHANGED
@@ -6123,6 +6123,7 @@ var exchangeToken = async ({
6123
6123
  };
6124
6124
  var issueTokenSet = async ({
6125
6125
  acr,
6126
+ audience,
6126
6127
  claims,
6127
6128
  clientCertThumbprint,
6128
6129
  clientId,
@@ -6137,11 +6138,13 @@ var issueTokenSet = async ({
6137
6138
  const idTtl = config.idTokenTtlMs ?? DEFAULT_ID_TOKEN_TTL_MS;
6138
6139
  const refreshTtl = config.refreshTokenTtlMs ?? DEFAULT_REFRESH_TOKEN_TTL_MS;
6139
6140
  const accessExtra = await config.getAccessTokenClaims?.({
6141
+ audience,
6140
6142
  clientId,
6141
6143
  scopes,
6142
6144
  sub
6143
6145
  });
6144
6146
  const accessPayload = buildAccessClaims({
6147
+ audience,
6145
6148
  clientCertThumbprint,
6146
6149
  clientId,
6147
6150
  dpopJkt,
@@ -6167,6 +6170,7 @@ var issueTokenSet = async ({
6167
6170
  const refreshToken = generateSecureToken(TOKEN_BYTES3);
6168
6171
  await config.refreshTokenStore.saveToken({
6169
6172
  acr,
6173
+ audience,
6170
6174
  claims,
6171
6175
  clientId,
6172
6176
  createdAt: now,
@@ -7784,6 +7788,9 @@ var oidcProviderRoutes = (config) => {
7784
7788
  if (record === undefined || record.expiresAt < Date.now() || record.clientId !== client.clientId || record.redirectUri !== redirectUri || !await verifyPkce(codeVerifier, record.codeChallenge)) {
7785
7789
  return oauthError2(HTTP_BAD_REQUEST3, "invalid_grant");
7786
7790
  }
7791
+ if (body.resource !== undefined && body.resource !== record.audience) {
7792
+ return oauthError2(HTTP_BAD_REQUEST3, "invalid_target");
7793
+ }
7787
7794
  const dpopResult = dpop === undefined ? undefined : await verifyDpopProof({
7788
7795
  htm: "POST",
7789
7796
  htu: tokenUrl,
@@ -7794,6 +7801,7 @@ var oidcProviderRoutes = (config) => {
7794
7801
  }
7795
7802
  return tokenResponse(await issueTokenSet({
7796
7803
  acr: record.acr,
7804
+ audience: record.audience,
7797
7805
  claims: record.claims,
7798
7806
  clientCertThumbprint,
7799
7807
  clientId: client.clientId,
@@ -7813,6 +7821,9 @@ var oidcProviderRoutes = (config) => {
7813
7821
  if (record === undefined || record.expiresAt < Date.now() || record.clientId !== client.clientId) {
7814
7822
  return oauthError2(HTTP_BAD_REQUEST3, "invalid_grant");
7815
7823
  }
7824
+ if (body.resource !== undefined && body.resource !== record.audience) {
7825
+ return oauthError2(HTTP_BAD_REQUEST3, "invalid_target");
7826
+ }
7816
7827
  if (record.dpopJkt !== undefined) {
7817
7828
  const proof = await verifyDpopProof({
7818
7829
  htm: "POST",
@@ -7825,6 +7836,7 @@ var oidcProviderRoutes = (config) => {
7825
7836
  }
7826
7837
  return tokenResponse(await issueTokenSet({
7827
7838
  acr: record.acr,
7839
+ audience: record.audience,
7828
7840
  claims: record.claims,
7829
7841
  clientCertThumbprint,
7830
7842
  clientId: client.clientId,
@@ -8183,6 +8195,7 @@ var oidcProviderRoutes = (config) => {
8183
8195
  const code = generateSecureToken(TOKEN_BYTES4);
8184
8196
  await authorizationCodeStore.saveCode({
8185
8197
  acr: userAcr,
8198
+ audience: effectiveQuery.resource,
8186
8199
  claims: getClaims?.(userSession.user),
8187
8200
  clientId: client.clientId,
8188
8201
  codeChallenge,
@@ -8218,6 +8231,7 @@ var oidcProviderRoutes = (config) => {
8218
8231
  redirect_uri: t15.Optional(t15.String()),
8219
8232
  request: t15.Optional(t15.String()),
8220
8233
  request_uri: t15.Optional(t15.String()),
8234
+ resource: t15.Optional(t15.String()),
8221
8235
  response_mode: t15.Optional(t15.String()),
8222
8236
  response_type: t15.Optional(t15.String()),
8223
8237
  scope: t15.Optional(t15.String()),
@@ -27146,6 +27160,28 @@ var createInMemoryPushedAuthorizationRequestStore = () => {
27146
27160
  var URL_LENGTH = 2048;
27147
27161
  var DEFAULT_LIST_LIMIT2 = 100;
27148
27162
  var ID_LENGTH9 = 255;
27163
+ var BACKCHANNEL_AUTH_STATUSES = new Set([
27164
+ "approved",
27165
+ "denied",
27166
+ "pending"
27167
+ ]);
27168
+ var DEVICE_AUTHORIZATION_STATUSES = new Set([
27169
+ "approved",
27170
+ "denied",
27171
+ "pending"
27172
+ ]);
27173
+ var backchannelAuthStatus = (value) => {
27174
+ for (const status of BACKCHANNEL_AUTH_STATUSES)
27175
+ if (status === value)
27176
+ return status;
27177
+ throw new Error(`Invalid persisted backchannel authorization status: ${value}`);
27178
+ };
27179
+ var deviceAuthorizationStatus = (value) => {
27180
+ for (const status of DEVICE_AUTHORIZATION_STATUSES)
27181
+ if (status === value)
27182
+ return status;
27183
+ throw new Error(`Invalid persisted device authorization status: ${value}`);
27184
+ };
27149
27185
  var oauthBackchannelAuthRequestsTable = pgTable("auth_oauth_backchannel_auth_requests", {
27150
27186
  auth_req_id: varchar("auth_req_id", { length: ID_LENGTH9 }).primaryKey(),
27151
27187
  binding_message: text("binding_message"),
@@ -27190,6 +27226,7 @@ var oauthClientsTable = pgTable("auth_oauth_clients", {
27190
27226
  });
27191
27227
  var oauthCodesTable = pgTable("auth_oauth_codes", {
27192
27228
  acr: varchar("acr", { length: ID_LENGTH9 }),
27229
+ audience: varchar("audience", { length: URL_LENGTH }),
27193
27230
  claims_json: jsonb("claims_json").$type(),
27194
27231
  client_id: varchar("client_id", { length: ID_LENGTH9 }).notNull(),
27195
27232
  code_challenge: varchar("code_challenge", { length: ID_LENGTH9 }).notNull(),
@@ -27242,6 +27279,7 @@ var oauthPushedAuthorizationRequestsTable = pgTable("auth_oauth_pushed_authoriza
27242
27279
  });
27243
27280
  var oauthRefreshTokensTable = pgTable("auth_oauth_refresh_tokens", {
27244
27281
  acr: varchar("acr", { length: ID_LENGTH9 }),
27282
+ audience: varchar("audience", { length: URL_LENGTH }),
27245
27283
  claims_json: jsonb("claims_json").$type(),
27246
27284
  client_id: varchar("client_id", { length: ID_LENGTH9 }).notNull(),
27247
27285
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
@@ -27277,6 +27315,7 @@ var toLogoutDelivery = (row) => ({
27277
27315
  });
27278
27316
  var toCode = (row) => ({
27279
27317
  acr: row.acr ?? undefined,
27318
+ audience: row.audience ?? undefined,
27280
27319
  claims: row.claims_json ?? undefined,
27281
27320
  clientId: row.client_id,
27282
27321
  codeChallenge: row.code_challenge,
@@ -27291,6 +27330,7 @@ var toCode = (row) => ({
27291
27330
  });
27292
27331
  var toCodeValues = (code) => ({
27293
27332
  acr: code.acr ?? null,
27333
+ audience: code.audience ?? null,
27294
27334
  claims_json: code.claims ?? null,
27295
27335
  client_id: code.clientId,
27296
27336
  code_challenge: code.codeChallenge,
@@ -27310,12 +27350,13 @@ var toDeviceAuth = (row) => ({
27310
27350
  expiresAt: row.expires_at_ms,
27311
27351
  intervalSeconds: row.interval_seconds,
27312
27352
  scopes: row.scopes,
27313
- status: row.status,
27353
+ status: deviceAuthorizationStatus(row.status),
27314
27354
  userCode: row.user_code,
27315
27355
  userSub: row.user_sub ?? undefined
27316
27356
  });
27317
27357
  var toRefresh = (row) => ({
27318
27358
  acr: row.acr ?? undefined,
27359
+ audience: row.audience ?? undefined,
27319
27360
  claims: row.claims_json ?? undefined,
27320
27361
  clientId: row.client_id,
27321
27362
  createdAt: row.created_at_ms,
@@ -27327,6 +27368,7 @@ var toRefresh = (row) => ({
27327
27368
  });
27328
27369
  var toRefreshValues = (token) => ({
27329
27370
  acr: token.acr ?? null,
27371
+ audience: token.audience ?? null,
27330
27372
  claims_json: token.claims ?? null,
27331
27373
  client_id: token.clientId,
27332
27374
  created_at_ms: token.createdAt,
@@ -27538,7 +27580,7 @@ var toBackchannelAuth = (row) => ({
27538
27580
  intervalSeconds: row.interval_seconds,
27539
27581
  lastPolledAt: row.last_polled_at_ms ?? undefined,
27540
27582
  scopes: row.scopes,
27541
- status: row.status,
27583
+ status: backchannelAuthStatus(row.status),
27542
27584
  userSub: row.user_sub ?? undefined
27543
27585
  });
27544
27586
  var createNeonBackchannelAuthStore = (databaseUrl) => createPostgresBackchannelAuthStore(createNeonDatabase(databaseUrl));
@@ -28836,6 +28878,14 @@ var mfaTotpLockoutMigration = {
28836
28878
  id: "0003_totp_lockout",
28837
28879
  sql: 'ALTER TABLE "auth_mfa_enrollments" ADD COLUMN IF NOT EXISTS "totp_failed_attempts" smallint NOT NULL DEFAULT 0;'
28838
28880
  };
28881
+ var oidcResourceAudienceMigration = {
28882
+ id: "0002_resource_audience",
28883
+ sql: [
28884
+ 'ALTER TABLE "auth_oauth_codes" ADD COLUMN IF NOT EXISTS "audience" varchar(2048);',
28885
+ 'ALTER TABLE "auth_oauth_refresh_tokens" ADD COLUMN IF NOT EXISTS "audience" varchar(2048);'
28886
+ ].join(`
28887
+ `)
28888
+ };
28839
28889
  var blockMigrations = {
28840
28890
  adaptive: initMigration("adaptive", [knownDevicesTable, loginHistoryTable]),
28841
28891
  agents: {
@@ -28877,18 +28927,24 @@ var blockMigrations = {
28877
28927
  mfaTotpLockoutMigration
28878
28928
  ]
28879
28929
  },
28880
- oidc: initMigration("oidc", [
28881
- oauthBackchannelAuthRequestsTable,
28882
- oauthClientAssertionJtisTable,
28883
- oauthClientRegistrationTokensTable,
28884
- oauthClientsTable,
28885
- oauthCodesTable,
28886
- oauthDeviceAuthorizationsTable,
28887
- oauthInitialAccessTokensTable,
28888
- oauthLogoutDeliveriesTable,
28889
- oauthPushedAuthorizationRequestsTable,
28890
- oauthRefreshTokensTable
28891
- ]),
28930
+ oidc: {
28931
+ block: "oidc",
28932
+ migrations: [
28933
+ ...initMigration("oidc", [
28934
+ oauthBackchannelAuthRequestsTable,
28935
+ oauthClientAssertionJtisTable,
28936
+ oauthClientRegistrationTokensTable,
28937
+ oauthClientsTable,
28938
+ oauthCodesTable,
28939
+ oauthDeviceAuthorizationsTable,
28940
+ oauthInitialAccessTokensTable,
28941
+ oauthLogoutDeliveriesTable,
28942
+ oauthPushedAuthorizationRequestsTable,
28943
+ oauthRefreshTokensTable
28944
+ ]).migrations,
28945
+ oidcResourceAudienceMigration
28946
+ ]
28947
+ },
28892
28948
  organizations: initMigration("organizations", [
28893
28949
  organizationsTable,
28894
28950
  organizationMembershipsTable,
@@ -30141,5 +30197,5 @@ export {
30141
30197
  AGENT_CLAIM_GRANT_TYPE
30142
30198
  };
30143
30199
 
30144
- //# debugId=C0233F9D8EBEC87464756E2164756E21
30200
+ //# debugId=08F44D063C89F47864756E2164756E21
30145
30201
  //# sourceMappingURL=index.js.map