@absolutejs/auth 0.56.12 → 0.56.13

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.
@@ -1,12 +1,20 @@
1
+ import { type SigningKeyIdentity } from '../oidc/keys';
1
2
  import type { AgentCredentialVerifier } from './types';
3
+ type OidcAgentCredentialVerifierKeys = {
4
+ publicJwk: JsonWebKey;
5
+ publicKeys?: never;
6
+ } | {
7
+ publicJwk?: never;
8
+ publicKeys: readonly SigningKeyIdentity[];
9
+ };
2
10
  /** Adapter for Absolute Auth's RFC 9068-style JWT access tokens. It validates
3
11
  * signature, issuer, audience, expiry, and extracts the OAuth client as the
4
12
  * agent identity while retaining `sub` as the authorizing user. */
5
- export declare const createOidcAgentCredentialVerifier: ({ issuer, isUsedDpopJti, maxDpopAgeMs, publicJwk, requireDpop, resource }: {
13
+ export declare const createOidcAgentCredentialVerifier: ({ issuer, isUsedDpopJti, maxDpopAgeMs, publicJwk, publicKeys, requireDpop, resource }: {
6
14
  issuer: string;
7
15
  isUsedDpopJti?: (jti: string) => boolean | Promise<boolean>;
8
16
  maxDpopAgeMs?: number;
9
- publicJwk: JsonWebKey;
10
17
  requireDpop?: boolean;
11
18
  resource: string;
12
- }) => AgentCredentialVerifier;
19
+ } & OidcAgentCredentialVerifierKeys) => AgentCredentialVerifier;
20
+ export {};
package/dist/index.d.ts CHANGED
@@ -3579,8 +3579,8 @@ export * from './oidc/config';
3579
3579
  export * from './oidc/clientIdMetadata';
3580
3580
  export * from './oidc/types';
3581
3581
  export { oidcProviderRoutes } from './oidc/routes';
3582
- export { generateSigningKey, jwkThumbprint, signJwt, toPublicJwk, verifyJwt } from './oidc/keys';
3583
- export type { SigningKey } from './oidc/keys';
3582
+ export { generateSigningKey, jwkThumbprint, signJwt, signingVerificationKeys, toPublicJwk, verifyJwt, verifyJwtWithKeys } from './oidc/keys';
3583
+ export type { SigningKey, SigningKeyIdentity } from './oidc/keys';
3584
3584
  export { extractDpopNonceClaim, mintDpopNonce, verifyDpopNonce, verifyDpopProof } from './oidc/dpop';
3585
3585
  export type { DpopResult } from './oidc/dpop';
3586
3586
  export { CLIENT_ASSERTION_TYPE, verifyClientAssertion, verifyJwtSignedByClient } from './oidc/clientAuth';
package/dist/index.js CHANGED
@@ -3289,6 +3289,26 @@ var verifyJwt = async (token, publicJwk) => {
3289
3289
  payload
3290
3290
  };
3291
3291
  };
3292
+ var signingVerificationKeys = (active, previous = []) => {
3293
+ const keys = [active, ...previous];
3294
+ const keyIds = new Set(keys.map(({ kid }) => kid));
3295
+ if (keyIds.size !== keys.length)
3296
+ throw new Error("OIDC signing key IDs must be unique");
3297
+ return keys;
3298
+ };
3299
+ var verifyJwtWithKeys = async (token, keys) => {
3300
+ const [headerSegment] = token.split(".");
3301
+ if (!headerSegment)
3302
+ return;
3303
+ const header = decodeSegment(headerSegment);
3304
+ const kid = header?.kid;
3305
+ if (typeof kid !== "string" || kid.length === 0)
3306
+ return;
3307
+ const key = keys.find((candidate) => candidate.kid === kid);
3308
+ if (!key)
3309
+ return;
3310
+ return verifyJwt(token, key.publicJwk);
3311
+ };
3292
3312
 
3293
3313
  // src/agents/registration.ts
3294
3314
  var AGENT_CLAIM_GRANT_TYPE = "urn:workos:agent-auth:grant-type:claim";
@@ -6086,7 +6106,7 @@ var exchangeToken = async ({
6086
6106
  requestedScopes,
6087
6107
  subjectToken
6088
6108
  }) => {
6089
- const verified = await verifyJwt(subjectToken, config.signingKey.publicJwk);
6109
+ const verified = await verifyJwtWithKeys(subjectToken, signingVerificationKeys(config.signingKey, config.previousSigningKeys));
6090
6110
  const payload = verified?.payload;
6091
6111
  if (payload === undefined || typeof payload.sub !== "string" || typeof payload.exp !== "number" || payload.exp <= nowSeconds(now)) {
6092
6112
  return { error: "invalid_grant", ok: false };
@@ -6207,7 +6227,7 @@ var introspectToken = async ({
6207
6227
  token
6208
6228
  }) => {
6209
6229
  if (hint !== "refresh_token") {
6210
- const verified = await verifyJwt(token, config.signingKey.publicJwk);
6230
+ const verified = await verifyJwtWithKeys(token, signingVerificationKeys(config.signingKey, config.previousSigningKeys));
6211
6231
  const payload = verified?.payload;
6212
6232
  if (payload !== undefined && typeof payload.sub === "string" && typeof payload.exp === "number" && payload.exp > nowSeconds(now)) {
6213
6233
  return {
@@ -7123,7 +7143,7 @@ var verifyIdTokenHint = async ({
7123
7143
  config,
7124
7144
  idTokenHint
7125
7145
  }) => {
7126
- const verified = await verifyJwt(idTokenHint, config.signingKey.publicJwk);
7146
+ const verified = await verifyJwtWithKeys(idTokenHint, signingVerificationKeys(config.signingKey, config.previousSigningKeys));
7127
7147
  const payload = verified?.payload;
7128
7148
  if (payload === undefined || typeof payload.sub !== "string" || typeof payload.aud !== "string" || payload.iss !== config.issuer) {
7129
7149
  return;
@@ -7353,7 +7373,7 @@ var fetchUserInfo = async ({
7353
7373
  ok: false
7354
7374
  };
7355
7375
  }
7356
- const verified = await verifyJwt(token, config.signingKey.publicJwk);
7376
+ const verified = await verifyJwtWithKeys(token, signingVerificationKeys(config.signingKey, config.previousSigningKeys));
7357
7377
  if (verified === undefined) {
7358
7378
  return {
7359
7379
  body: { error: "invalid_token" },
@@ -8694,7 +8714,9 @@ var oidcProviderRoutes = (config) => {
8694
8714
  headers: t15.Object({
8695
8715
  authorization: t15.Optional(t15.String())
8696
8716
  })
8697
- }).get(jwksRoute, () => ({ keys: [toPublicJwk(signingKey)] })).get("/.well-known/openid-configuration", () => discovery).get("/.well-known/oauth-authorization-server", () => discovery);
8717
+ }).get(jwksRoute, () => ({
8718
+ keys: signingVerificationKeys(signingKey, config.previousSigningKeys).map(toPublicJwk)
8719
+ })).get("/.well-known/openid-configuration", () => discovery).get("/.well-known/oauth-authorization-server", () => discovery);
8698
8720
  };
8699
8721
 
8700
8722
  // src/organizations/routes.ts
@@ -27033,6 +27055,7 @@ var createOidcAgentCredentialVerifier = ({
27033
27055
  isUsedDpopJti,
27034
27056
  maxDpopAgeMs,
27035
27057
  publicJwk,
27058
+ publicKeys,
27036
27059
  requireDpop = false,
27037
27060
  resource
27038
27061
  }) => {
@@ -27044,13 +27067,14 @@ var createOidcAgentCredentialVerifier = ({
27044
27067
  const token = authorization.slice(authorization.indexOf(" ") + 1).trim();
27045
27068
  if (token.length === 0)
27046
27069
  return;
27047
- const verified = await verifyJwt(token, publicJwk);
27070
+ const verified = publicKeys ? await verifyJwtWithKeys(token, publicKeys) : await verifyJwt(token, publicJwk);
27048
27071
  const payload = verified?.payload;
27049
27072
  if (payload === undefined || payload.iss !== issuer || typeof payload.exp !== "number" || payload.exp <= Math.floor(Date.now() / MS_PER_SECOND7) || !readAudience(payload.aud).includes(resource) || typeof payload.client_id !== "string") {
27050
27073
  return;
27051
27074
  }
27052
27075
  const confirmation = payload.cnf;
27053
- const boundJkt = typeof confirmation === "object" && confirmation !== null && typeof confirmation.jkt === "string" ? confirmation.jkt : undefined;
27076
+ const boundJktValue = typeof confirmation === "object" && confirmation !== null ? Reflect.get(confirmation, "jkt") : undefined;
27077
+ const boundJkt = typeof boundJktValue === "string" ? boundJktValue : undefined;
27054
27078
  if (boundJkt !== undefined || requireDpop) {
27055
27079
  if (!authorization.startsWith("DPoP "))
27056
27080
  return;
@@ -30590,6 +30614,7 @@ export {
30590
30614
  verifyPresentationResponse,
30591
30615
  verifyPkce,
30592
30616
  verifyPassword,
30617
+ verifyJwtWithKeys,
30593
30618
  verifyJwtSignedByClient,
30594
30619
  verifyJwt,
30595
30620
  verifyIdTokenHint,
@@ -30624,6 +30649,7 @@ export {
30624
30649
  startAgentRegistration,
30625
30650
  ssoDiscoveryRoute,
30626
30651
  ssoConnectionsTable,
30652
+ signingVerificationKeys,
30627
30653
  signWebhook,
30628
30654
  signStatusList,
30629
30655
  signJwt,
@@ -31057,5 +31083,5 @@ export {
31057
31083
  AGENT_CLAIM_GRANT_TYPE
31058
31084
  };
31059
31085
 
31060
- //# debugId=CEE9F9BEA5B2A4F264756E2164756E21
31086
+ //# debugId=EF4CB146B3B9999C64756E2164756E21
31061
31087
  //# sourceMappingURL=index.js.map