@absolutejs/mcp 0.10.1 → 0.10.3

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/README.md CHANGED
@@ -108,6 +108,7 @@ const server = new Elysia().use(
108
108
  // access-token checks; add your own (billing, role, MFA) on top.
109
109
  authorize: async (request) => {
110
110
  const token = await verifyBearer({
111
+ audience: "https://your.app/mcp",
111
112
  request,
112
113
  issuer: "https://your.app",
113
114
  requiredScope: "mcp",
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ var isRecord = (value) => typeof value === "object" && value !== null && !Array.
20
20
  // src/auth.ts
21
21
  var MS_PER_SECOND = 1000;
22
22
  var verifyBearer = async (config) => {
23
- const { issuer, request, verify, requiredScope } = config;
23
+ const { audience, issuer, request, verify, requiredScope } = config;
24
24
  const header = request.headers.get("authorization");
25
25
  if (!header?.startsWith("Bearer "))
26
26
  return { error: "Missing bearer token" };
@@ -32,6 +32,9 @@ var verifyBearer = async (config) => {
32
32
  return { error: "Not an access token" };
33
33
  if (payload.iss !== issuer)
34
34
  return { error: "Wrong issuer" };
35
+ const audiences = Array.isArray(payload.aud) ? payload.aud : [payload.aud];
36
+ if (audience !== undefined && !audiences.some((candidate) => candidate === audience))
37
+ return { error: "Wrong audience" };
35
38
  const expires = typeof payload.exp === "number" ? payload.exp : 0;
36
39
  if (expires * MS_PER_SECOND <= Date.now())
37
40
  return { error: "Token expired" };
@@ -5,6 +5,8 @@ export type VerifiedJwt = {
5
5
  };
6
6
  export type BearerVerifier = (token: string) => Promise<VerifiedJwt | undefined> | VerifiedJwt | undefined;
7
7
  export type VerifyBearerConfig = {
8
+ /** Require the access token to name this protected resource in `aud`. */
9
+ audience?: string;
8
10
  issuer: string;
9
11
  request: Request;
10
12
  /** Verify the JWT signature and decode it (e.g. `@absolutejs/auth`'s
@@ -20,7 +22,7 @@ export type BearerResult = {
20
22
  subject: string;
21
23
  };
22
24
  /** Verify the `Authorization: Bearer` token: signature (via your `verify`),
23
- * `token_use: access`, issuer, expiry, the required scope, and a subject.
25
+ * `token_use: access`, issuer, optional audience, expiry, required scope, and a subject.
24
26
  * Returns the decoded payload + parsed scopes + subject, or a reason string.
25
27
  * The reason is safe to surface in the 401 (never why the signature failed). */
26
28
  export declare const verifyBearer: (config: VerifyBearerConfig) => Promise<BearerResult>;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "elysia": ">=1.1.0"
12
12
  },
13
13
  "dependencies": {
14
- "@absolutejs/agency": "^0.4.0",
14
+ "@absolutejs/agency": "^0.5.0",
15
15
  "@absolutejs/manifest": "^0.3.0",
16
16
  "@sinclair/typebox": "^0.34.0"
17
17
  },
@@ -58,5 +58,5 @@
58
58
  "typecheck": "tsc --noEmit --project tsconfig.json"
59
59
  },
60
60
  "types": "./dist/src/index.d.ts",
61
- "version": "0.10.1"
61
+ "version": "0.10.3"
62
62
  }