@keycardai/express 0.3.0 → 0.4.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/LICENSE +5 -17
- package/README.md +28 -3
- package/dist/cjs/wellKnown.d.ts +7 -0
- package/dist/cjs/wellKnown.d.ts.map +1 -1
- package/dist/cjs/wellKnown.js +25 -0
- package/dist/cjs/wellKnown.js.map +1 -1
- package/dist/esm/wellKnown.d.ts +7 -0
- package/dist/esm/wellKnown.d.ts.map +1 -1
- package/dist/esm/wellKnown.js +25 -0
- package/dist/esm/wellKnown.js.map +1 -1
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
MIT
|
|
1
|
+
MIT LICENSE
|
|
2
2
|
|
|
3
|
-
Copyright
|
|
3
|
+
Copyright © 2026 Keycard Labs, inc.
|
|
4
4
|
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
11
6
|
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
14
8
|
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ import { requireBearerAuth } from "@keycardai/express";
|
|
|
20
20
|
|
|
21
21
|
const app = express();
|
|
22
22
|
|
|
23
|
-
app.use(requireBearerAuth({
|
|
23
|
+
app.use(requireBearerAuth({ zoneUrl: "https://your-zone.keycard.cloud" }));
|
|
24
24
|
|
|
25
25
|
app.get("/api/data", (req, res) => {
|
|
26
26
|
// req.auth is AccessToken: { token, clientId, scopes, ... }
|
|
@@ -36,7 +36,7 @@ import { ClientSecret } from "@keycardai/oauth/server";
|
|
|
36
36
|
|
|
37
37
|
const credential = new ClientSecret("your-client-id", "your-client-secret");
|
|
38
38
|
|
|
39
|
-
app.use(requireBearerAuth({
|
|
39
|
+
app.use(requireBearerAuth({ zoneUrl: "https://your-zone.keycard.cloud" }));
|
|
40
40
|
app.use(grant(["https://graph.microsoft.com"], {
|
|
41
41
|
zoneUrl: "https://your-zone.keycard.cloud",
|
|
42
42
|
applicationCredential: credential,
|
|
@@ -49,6 +49,29 @@ app.get("/api/email", async (req, res) => {
|
|
|
49
49
|
});
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
For multi-zone deployments, pass a zone-keyed `ClientSecret` and resolve the zone from each request's verified token:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { requireBearerAuth, grant } from "@keycardai/express";
|
|
56
|
+
import { ClientSecret } from "@keycardai/oauth/server";
|
|
57
|
+
|
|
58
|
+
const credential = new ClientSecret({
|
|
59
|
+
"zone-a": ["client-id-a", "client-secret-a"],
|
|
60
|
+
"zone-b": ["client-id-b", "client-secret-b"],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
app.use(requireBearerAuth({ zoneUrl: "https://base-zone.keycard.cloud", enableMultiZone: true }));
|
|
64
|
+
|
|
65
|
+
// zoneId accepts a function that receives the verified AccessToken and
|
|
66
|
+
// returns the zone identifier for this request. AccessToken has no
|
|
67
|
+
// dedicated zone field — use whichever field encodes zone context in
|
|
68
|
+
// your deployment (e.g. a zone-prefixed clientId, or a custom claim).
|
|
69
|
+
app.use(grant(["https://api.example.com"], {
|
|
70
|
+
zoneId: (auth) => auth.clientId,
|
|
71
|
+
applicationCredential: credential,
|
|
72
|
+
}));
|
|
73
|
+
```
|
|
74
|
+
|
|
52
75
|
### Add OAuth discovery routes
|
|
53
76
|
|
|
54
77
|
```typescript
|
|
@@ -65,8 +88,9 @@ app.use(keycardMetadataRouter({ issuer: "https://your-zone.keycard.cloud" }));
|
|
|
65
88
|
| Export | Description |
|
|
66
89
|
|---|---|
|
|
67
90
|
| `requireBearerAuth(options)` | Middleware factory that validates a Bearer token and sets `req.auth: AccessToken`. Returns 401 with RFC 6750 `WWW-Authenticate` challenge on failure. |
|
|
68
|
-
| `grant(resources, options)` | Middleware factory that exchanges the bearer token for per-resource access tokens and sets `req.accessContext: AccessContext`. Must run after `requireBearerAuth`. |
|
|
91
|
+
| `grant(resources, options)` | Middleware factory that exchanges the bearer token for per-resource access tokens and sets `req.accessContext: AccessContext`. Must run after `requireBearerAuth`. `zoneId` accepts a static string or a function `(auth: AccessToken) => string` for per-request zone resolution. |
|
|
69
92
|
| `keycardMetadataRouter(options)` | Returns an Express Router with `/.well-known/oauth-protected-resource` and `/.well-known/oauth-authorization-server` routes. |
|
|
93
|
+
| `createKeycardMiddleware(options)` | Factory that returns pre-configured `{ requireBearerAuth(), grant() }` sharing a single zone config. You still need `keycardMetadataRouter` for discovery routes. |
|
|
70
94
|
| `AuthenticatedRequest` | `Request` extended with `auth: AccessToken`. |
|
|
71
95
|
| `GrantedRequest` | `Request` extended with `auth: AccessToken` and `accessContext: AccessContext`. |
|
|
72
96
|
|
|
@@ -74,4 +98,5 @@ app.use(keycardMetadataRouter({ issuer: "https://your-zone.keycard.cloud" }));
|
|
|
74
98
|
|
|
75
99
|
- [`@keycardai/oauth`](../oauth/) — Framework-free OAuth primitives this package builds on
|
|
76
100
|
- [`@keycardai/mcp`](../mcp/) — MCP-specific OAuth integration
|
|
101
|
+
- [`@keycardai/a2a`](../a2a/) — Agent-to-agent (A2A) protocol integration
|
|
77
102
|
- [Keycard TypeScript SDK](../../README.md) — Root documentation
|
package/dist/cjs/wellKnown.d.ts
CHANGED
|
@@ -22,6 +22,13 @@ export interface KeycardRouterOptions {
|
|
|
22
22
|
* Default: 10 000 ms.
|
|
23
23
|
*/
|
|
24
24
|
asMetadataTimeoutMs?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Public JWKS to serve at `GET /.well-known/jwks.json`.
|
|
27
|
+
* When omitted, no JWKS route is registered.
|
|
28
|
+
*/
|
|
29
|
+
publicJwks?: {
|
|
30
|
+
keys: Record<string, unknown>[];
|
|
31
|
+
};
|
|
25
32
|
}
|
|
26
33
|
/**
|
|
27
34
|
* Returns an Express Router that serves the two OAuth discovery endpoints
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wellKnown.d.ts","sourceRoot":"","sources":["../../src/wellKnown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGjC,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"wellKnown.d.ts","sourceRoot":"","sources":["../../src/wellKnown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGjC,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAAE,CAAC;CAClD;AAKD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CA4B3E"}
|
package/dist/cjs/wellKnown.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.keycardMetadataRouter = keycardMetadataRouter;
|
|
4
4
|
const express_1 = require("express");
|
|
5
|
+
const CORS_ALLOW_METHODS = "GET, OPTIONS";
|
|
6
|
+
const CORS_ALLOW_HEADERS = "Content-Type, MCP-Protocol-Version";
|
|
5
7
|
/**
|
|
6
8
|
* Returns an Express Router that serves the two OAuth discovery endpoints
|
|
7
9
|
* required by RFC 9728 and RFC 8414:
|
|
@@ -25,10 +27,33 @@ const express_1 = require("express");
|
|
|
25
27
|
*/
|
|
26
28
|
function keycardMetadataRouter(options) {
|
|
27
29
|
const router = (0, express_1.Router)();
|
|
30
|
+
const metadataPaths = [
|
|
31
|
+
"/.well-known/oauth-protected-resource",
|
|
32
|
+
"/.well-known/oauth-authorization-server",
|
|
33
|
+
];
|
|
28
34
|
router.get("/.well-known/oauth-protected-resource", protectedResourceHandler(options));
|
|
29
35
|
router.get("/.well-known/oauth-authorization-server", authorizationServerHandler(options.issuer, options.asMetadataTimeoutMs ?? 10_000));
|
|
36
|
+
if (options.publicJwks) {
|
|
37
|
+
metadataPaths.push("/.well-known/jwks.json");
|
|
38
|
+
router.get("/.well-known/jwks.json", jwksHandler(options.publicJwks));
|
|
39
|
+
}
|
|
40
|
+
// CORS preflight for the metadata endpoints. Browsers send OPTIONS before
|
|
41
|
+
// cross-origin GETs that include headers such as MCP-Protocol-Version.
|
|
42
|
+
router.options(metadataPaths, preflightHandler);
|
|
30
43
|
return router;
|
|
31
44
|
}
|
|
45
|
+
const preflightHandler = (_req, res) => {
|
|
46
|
+
res.set("Access-Control-Allow-Origin", "*");
|
|
47
|
+
res.set("Access-Control-Allow-Methods", CORS_ALLOW_METHODS);
|
|
48
|
+
res.set("Access-Control-Allow-Headers", CORS_ALLOW_HEADERS);
|
|
49
|
+
res.status(204).end();
|
|
50
|
+
};
|
|
51
|
+
function jwksHandler(publicJwks) {
|
|
52
|
+
return (_req, res) => {
|
|
53
|
+
res.set("Access-Control-Allow-Origin", "*");
|
|
54
|
+
res.status(200).json(publicJwks);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
32
57
|
function protectedResourceHandler(options) {
|
|
33
58
|
return (req, res) => {
|
|
34
59
|
const resource = `${req.protocol}://${req.host}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wellKnown.js","sourceRoot":"","sources":["../../src/wellKnown.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"wellKnown.js","sourceRoot":"","sources":["../../src/wellKnown.ts"],"names":[],"mappings":";;AAyDA,sDA4BC;AArFD,qCAAiC;AAiCjC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAC1C,MAAM,kBAAkB,GAAG,oCAAoC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,qBAAqB,CAAC,OAA6B;IACjE,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAC;IAExB,MAAM,aAAa,GAAG;QACpB,uCAAuC;QACvC,yCAAyC;KAC1C,CAAC;IAEF,MAAM,CAAC,GAAG,CACR,uCAAuC,EACvC,wBAAwB,CAAC,OAAO,CAAC,CAClC,CAAC;IAEF,MAAM,CAAC,GAAG,CACR,yCAAyC,EACzC,0BAA0B,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,mBAAmB,IAAI,MAAM,CAAC,CAClF,CAAC;IAEF,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,aAAa,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAC7C,MAAM,CAAC,GAAG,CAAC,wBAAwB,EAAE,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,0EAA0E;IAC1E,uEAAuE;IACvE,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;IAEhD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,gBAAgB,GAAmB,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;IACrD,GAAG,CAAC,GAAG,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;IAC5C,GAAG,CAAC,GA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utMs?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Public JWKS to serve at `GET /.well-known/jwks.json`.
|
|
27
|
+
* When omitted, no JWKS route is registered.
|
|
28
|
+
*/
|
|
29
|
+
publicJwks?: {
|
|
30
|
+
keys: Record<string, unknown>[];
|
|
31
|
+
};
|
|
25
32
|
}
|
|
26
33
|
/**
|
|
27
34
|
* Returns an Express Router that serves the two OAuth discovery endpoints
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wellKnown.d.ts","sourceRoot":"","sources":["../../src/wellKnown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGjC,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"wellKnown.d.ts","sourceRoot":"","sources":["../../src/wellKnown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGjC,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAAE,CAAC;CAClD;AAKD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CA4B3E"}
|
package/dist/esm/wellKnown.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Router } from "express";
|
|
2
|
+
const CORS_ALLOW_METHODS = "GET, OPTIONS";
|
|
3
|
+
const CORS_ALLOW_HEADERS = "Content-Type, MCP-Protocol-Version";
|
|
2
4
|
/**
|
|
3
5
|
* Returns an Express Router that serves the two OAuth discovery endpoints
|
|
4
6
|
* required by RFC 9728 and RFC 8414:
|
|
@@ -22,10 +24,33 @@ import { Router } from "express";
|
|
|
22
24
|
*/
|
|
23
25
|
export function keycardMetadataRouter(options) {
|
|
24
26
|
const router = Router();
|
|
27
|
+
const metadataPaths = [
|
|
28
|
+
"/.well-known/oauth-protected-resource",
|
|
29
|
+
"/.well-known/oauth-authorization-server",
|
|
30
|
+
];
|
|
25
31
|
router.get("/.well-known/oauth-protected-resource", protectedResourceHandler(options));
|
|
26
32
|
router.get("/.well-known/oauth-authorization-server", authorizationServerHandler(options.issuer, options.asMetadataTimeoutMs ?? 10_000));
|
|
33
|
+
if (options.publicJwks) {
|
|
34
|
+
metadataPaths.push("/.well-known/jwks.json");
|
|
35
|
+
router.get("/.well-known/jwks.json", jwksHandler(options.publicJwks));
|
|
36
|
+
}
|
|
37
|
+
// CORS preflight for the metadata endpoints. Browsers send OPTIONS before
|
|
38
|
+
// cross-origin GETs that include headers such as MCP-Protocol-Version.
|
|
39
|
+
router.options(metadataPaths, preflightHandler);
|
|
27
40
|
return router;
|
|
28
41
|
}
|
|
42
|
+
const preflightHandler = (_req, res) => {
|
|
43
|
+
res.set("Access-Control-Allow-Origin", "*");
|
|
44
|
+
res.set("Access-Control-Allow-Methods", CORS_ALLOW_METHODS);
|
|
45
|
+
res.set("Access-Control-Allow-Headers", CORS_ALLOW_HEADERS);
|
|
46
|
+
res.status(204).end();
|
|
47
|
+
};
|
|
48
|
+
function jwksHandler(publicJwks) {
|
|
49
|
+
return (_req, res) => {
|
|
50
|
+
res.set("Access-Control-Allow-Origin", "*");
|
|
51
|
+
res.status(200).json(publicJwks);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
29
54
|
function protectedResourceHandler(options) {
|
|
30
55
|
return (req, res) => {
|
|
31
56
|
const resource = `${req.protocol}://${req.host}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wellKnown.js","sourceRoot":"","sources":["../../src/wellKnown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"wellKnown.js","sourceRoot":"","sources":["../../src/wellKnown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAiCjC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAC1C,MAAM,kBAAkB,GAAG,oCAAoC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA6B;IACjE,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;IAExB,MAAM,aAAa,GAAG;QACpB,uCAAuC;QACvC,yCAAyC;KAC1C,CAAC;IAEF,MAAM,CAAC,GAAG,CACR,uCAAuC,EACvC,wBAAwB,CAAC,OAAO,CAAC,CAClC,CAAC;IAEF,MAAM,CAAC,GAAG,CACR,yCAAyC,EACzC,0BAA0B,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,mBAAmB,IAAI,MAAM,CAAC,CAClF,CAAC;IAEF,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,aAAa,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAC7C,MAAM,CAAC,GAAG,CAAC,wBAAwB,EAAE,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,0EAA0E;IAC1E,uEAAuE;IAC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C,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,CAAC,CAAC,CAAC;QACV,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keycardai/express",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "[Preview] Keycard auth middleware for Express: bearer token validation, RFC 6750 challenges, delegated token exchange, and OAuth discovery routes",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@keycardai/oauth": "0.
|
|
30
|
+
"@keycardai/oauth": "0.16.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"express": ">=4.0.0"
|