@canopy-io/node 0.26.1 → 0.27.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/CHANGELOG.md +13 -0
- package/README.md +31 -10
- package/dist/index.cjs +14 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +106 -38
- package/dist/index.d.ts +106 -38
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @canopy-io/node
|
|
2
2
|
|
|
3
|
+
## 0.27.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f1fca62: Types for the API as deployed with the embedded sign-in form: `direct_api_permissions_claim_enabled` on the sign-in settings, `hosted_product_name` and `hosted_logo` on the branding, and the embedded form's verification code screen in the branding preview. The SSO sign-in coverage list's `items` change shape, from Environment id strings to objects with `environment_id` and `apps_without_sso`; a caller reading the ids reads `item.environment_id` instead.
|
|
8
|
+
- eaee2f6: Follows Canopy's release that gives Direct API tokens an audience: a Direct API access token names the id of the Environment that issued it in `aud`, as a Hosted Login token names its OAuth client. `TokenVerifier`'s `audience` (and `verify.audience` in `CanopyModule`) now takes a list as well as one value, and accepts a token whose `aud` includes any of them, so one verifier with `[clientId, environmentId]` accepts both sign-in kinds of one Environment and refuses a token for another client. A verifier with no `audience` still refuses a token that carries `aud` (`token.audience_unverified`), and its message now names what to set for each sign-in kind; a token with no `aud` is still refused when an audience is set. Machine tokens are still held to `serviceAudience` alone.
|
|
9
|
+
|
|
10
|
+
## 0.26.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 658e24d: Follows Canopy's release that splits the Console's Authentication page and lets a directory refuse clearing its roles. The generated types add `environment_grantable_roles_set` to an organization's directory (whether the Environment sets a list the organization falls back to; without one, clearing the organization's list while its directory is connected is refused), add `sample` to each branding preview state and `client_id` to the preview, and say that the single-client OAuth routes take the client's `client_id` in their path.
|
|
15
|
+
|
|
3
16
|
## 0.26.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
# @canopy-io/node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Call [Canopy](https://canopy-io.com)'s API from your server, verify the access tokens Canopy issues, and answer permission checks in your own process.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Which package
|
|
6
|
+
|
|
7
|
+
- **A server in Node.js, or anywhere `fetch` runs:** this package.
|
|
8
|
+
- **A NestJS app:** [`@canopy-io/nestjs`](https://www.npmjs.com/package/@canopy-io/nestjs), which installs this one and turns a permission check into a decorator on the route.
|
|
9
|
+
- **A Next.js app:** [`@canopy-io/nextjs`](https://www.npmjs.com/package/@canopy-io/nextjs), which installs this one and signs people in on your server.
|
|
10
|
+
- **A single-page app with no backend:** [`@canopy-io/browser`](https://www.npmjs.com/package/@canopy-io/browser), or its React and Angular packages.
|
|
6
11
|
|
|
7
12
|
## Install
|
|
8
13
|
|
|
@@ -175,13 +180,28 @@ verifier keeps verifying with the keys it holds; only a verifier that has never
|
|
|
175
180
|
loaded a key set, or a token signed by a key it has never seen, answers
|
|
176
181
|
`token.jwks_unavailable`.
|
|
177
182
|
|
|
178
|
-
|
|
179
|
-
Direct API
|
|
180
|
-
|
|
181
|
-
token
|
|
183
|
+
Every person's token carries an audience: a Hosted Login token your
|
|
184
|
+
`client_id`, a Direct API token the id of the Environment that issued it. Name
|
|
185
|
+
the one your sign-in issues, or both, as a list, when one backend accepts
|
|
186
|
+
both; a token is accepted when its `aud` includes any of them. A token that
|
|
187
|
+
has an `aud` is refused rather than ignored when you have not said which
|
|
188
|
+
audience you are, so a token minted for another client is never accepted by
|
|
189
|
+
accident:
|
|
182
190
|
|
|
183
191
|
```ts
|
|
192
|
+
// Hosted Login
|
|
184
193
|
new TokenVerifier({ audience: process.env.CANOPY_OAUTH_CLIENT_ID });
|
|
194
|
+
|
|
195
|
+
// Direct API
|
|
196
|
+
new TokenVerifier({ audience: process.env.CANOPY_ENVIRONMENT_ID });
|
|
197
|
+
|
|
198
|
+
// Both
|
|
199
|
+
new TokenVerifier({
|
|
200
|
+
audience: [
|
|
201
|
+
process.env.CANOPY_OAUTH_CLIENT_ID ?? "",
|
|
202
|
+
process.env.CANOPY_ENVIRONMENT_ID ?? "",
|
|
203
|
+
],
|
|
204
|
+
});
|
|
185
205
|
```
|
|
186
206
|
|
|
187
207
|
Every Environment is its own issuer, so name yours:
|
|
@@ -652,11 +672,12 @@ Writing a `fetch` call against a documented REST API is easy, and an LLM will do
|
|
|
652
672
|
**Zero runtime dependencies.**
|
|
653
673
|
The client is `fetch` and nothing else, so it runs unchanged on Node, in browsers, on Cloudflare Workers, and on Deno — and it adds no supply-chain surface to anything that installs it. CI fails if a runtime dependency appears.
|
|
654
674
|
|
|
655
|
-
##
|
|
675
|
+
## Learn more
|
|
656
676
|
|
|
657
|
-
[
|
|
658
|
-
|
|
659
|
-
|
|
677
|
+
- [SDKs and Libraries](https://canopy-io.com/docs/sdks-and-libraries)
|
|
678
|
+
- [Authorization caching](https://canopy-io.com/docs/authorization-caching)
|
|
679
|
+
- [API reference](https://canopy-io.com/docs/api-reference)
|
|
680
|
+
- [Changelog](./CHANGELOG.md): the package is pre-1.0, so a minor version may carry a breaking change. Read the entry before upgrading.
|
|
660
681
|
|
|
661
682
|
## License
|
|
662
683
|
|
package/dist/index.cjs
CHANGED
|
@@ -2467,9 +2467,16 @@ function decodeJsonSegment(segment, what) {
|
|
|
2467
2467
|
);
|
|
2468
2468
|
}
|
|
2469
2469
|
}
|
|
2470
|
+
function audienceList(audience) {
|
|
2471
|
+
if (audience === void 0) {
|
|
2472
|
+
return void 0;
|
|
2473
|
+
}
|
|
2474
|
+
const list = typeof audience === "string" ? [audience] : [...audience];
|
|
2475
|
+
return list.length > 0 ? list : void 0;
|
|
2476
|
+
}
|
|
2470
2477
|
var TokenVerifier = class {
|
|
2471
2478
|
issuer;
|
|
2472
|
-
|
|
2479
|
+
audiences;
|
|
2473
2480
|
serviceAudience;
|
|
2474
2481
|
jwksUri;
|
|
2475
2482
|
jwksCacheMaxAgeMs;
|
|
@@ -2489,7 +2496,7 @@ var TokenVerifier = class {
|
|
|
2489
2496
|
inFlight = null;
|
|
2490
2497
|
constructor(options = {}) {
|
|
2491
2498
|
this.issuer = resolveIssuer(options);
|
|
2492
|
-
this.
|
|
2499
|
+
this.audiences = audienceList(options.audience);
|
|
2493
2500
|
this.serviceAudience = options.serviceAudience;
|
|
2494
2501
|
this.jwksUri = options.jwksUri ?? `${this.issuer}/.well-known/jwks.json`;
|
|
2495
2502
|
this.jwksCacheMaxAgeMs = options.jwksCacheMaxAgeMs ?? DEFAULT_JWKS_CACHE_MAX_AGE_MS;
|
|
@@ -2659,19 +2666,20 @@ var TokenVerifier = class {
|
|
|
2659
2666
|
}
|
|
2660
2667
|
return;
|
|
2661
2668
|
}
|
|
2662
|
-
if (this.
|
|
2669
|
+
if (this.audiences === void 0) {
|
|
2663
2670
|
if (audiences.length > 0) {
|
|
2664
2671
|
throw new CanopyTokenError(
|
|
2665
2672
|
"token.audience_unverified",
|
|
2666
|
-
"Token carries an `aud` claim but the verifier has no `audience` configured. Set `audience` to your OAuth client id
|
|
2673
|
+
"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."
|
|
2667
2674
|
);
|
|
2668
2675
|
}
|
|
2669
2676
|
return;
|
|
2670
2677
|
}
|
|
2671
|
-
|
|
2678
|
+
const expected = this.audiences;
|
|
2679
|
+
if (!audiences.some((audience) => expected.includes(audience))) {
|
|
2672
2680
|
throw new CanopyTokenError(
|
|
2673
2681
|
"token.audience_mismatch",
|
|
2674
|
-
`Token audience does not include
|
|
2682
|
+
`Token audience does not include ${expected.map((audience) => `"${audience}"`).join(" or ")}.`
|
|
2675
2683
|
);
|
|
2676
2684
|
}
|
|
2677
2685
|
}
|