@canopy-io/node 0.26.2 → 0.28.0

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
@@ -2465,9 +2465,16 @@ function decodeJsonSegment(segment, what) {
2465
2465
  );
2466
2466
  }
2467
2467
  }
2468
+ function audienceList(audience) {
2469
+ if (audience === void 0) {
2470
+ return void 0;
2471
+ }
2472
+ const list = typeof audience === "string" ? [audience] : [...audience];
2473
+ return list.length > 0 ? list : void 0;
2474
+ }
2468
2475
  var TokenVerifier = class {
2469
2476
  issuer;
2470
- audience;
2477
+ audiences;
2471
2478
  serviceAudience;
2472
2479
  jwksUri;
2473
2480
  jwksCacheMaxAgeMs;
@@ -2487,7 +2494,7 @@ var TokenVerifier = class {
2487
2494
  inFlight = null;
2488
2495
  constructor(options = {}) {
2489
2496
  this.issuer = resolveIssuer(options);
2490
- this.audience = options.audience;
2497
+ this.audiences = audienceList(options.audience);
2491
2498
  this.serviceAudience = options.serviceAudience;
2492
2499
  this.jwksUri = options.jwksUri ?? `${this.issuer}/.well-known/jwks.json`;
2493
2500
  this.jwksCacheMaxAgeMs = options.jwksCacheMaxAgeMs ?? DEFAULT_JWKS_CACHE_MAX_AGE_MS;
@@ -2657,19 +2664,20 @@ var TokenVerifier = class {
2657
2664
  }
2658
2665
  return;
2659
2666
  }
2660
- if (this.audience === void 0) {
2667
+ if (this.audiences === void 0) {
2661
2668
  if (audiences.length > 0) {
2662
2669
  throw new CanopyTokenError(
2663
2670
  "token.audience_unverified",
2664
- "Token carries an `aud` claim but the verifier has no `audience` configured. Set `audience` to your OAuth client id; Direct API tokens carry no audience and need no option."
2671
+ "Token carries an `aud` claim but the verifier has no `audience` configured. Set `audience` to your OAuth client id for Hosted Login tokens, to your Environment id for Direct API tokens, or to both, as a list, to accept either."
2665
2672
  );
2666
2673
  }
2667
2674
  return;
2668
2675
  }
2669
- if (!audiences.includes(this.audience)) {
2676
+ const expected = this.audiences;
2677
+ if (!audiences.some((audience) => expected.includes(audience))) {
2670
2678
  throw new CanopyTokenError(
2671
2679
  "token.audience_mismatch",
2672
- `Token audience does not include "${this.audience}".`
2680
+ `Token audience does not include ${expected.map((audience) => `"${audience}"`).join(" or ")}.`
2673
2681
  );
2674
2682
  }
2675
2683
  }