desearch-mcp-server 0.2.0 → 0.2.2
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 +19 -1
- package/README.md +58 -4
- package/build/http.d.ts +2 -8
- package/build/http.d.ts.map +1 -1
- package/build/http.js +126 -37
- package/build/oauth/client-ip.d.ts +10 -0
- package/build/oauth/client-ip.d.ts.map +1 -0
- package/build/oauth/client-ip.js +28 -0
- package/build/oauth/crypto.d.ts +20 -0
- package/build/oauth/crypto.d.ts.map +1 -0
- package/build/oauth/crypto.js +89 -0
- package/build/oauth/errors.d.ts +9 -0
- package/build/oauth/errors.d.ts.map +1 -0
- package/build/oauth/errors.js +13 -0
- package/build/oauth/flow.d.ts +8 -0
- package/build/oauth/flow.d.ts.map +1 -0
- package/build/oauth/flow.js +424 -0
- package/build/oauth/http.d.ts +25 -0
- package/build/oauth/http.d.ts.map +1 -0
- package/build/oauth/http.js +160 -0
- package/build/oauth/metadata.d.ts +19 -0
- package/build/oauth/metadata.d.ts.map +1 -0
- package/build/oauth/metadata.js +86 -0
- package/build/oauth/page.d.ts +14 -0
- package/build/oauth/page.d.ts.map +1 -0
- package/build/oauth/page.js +92 -0
- package/build/oauth/rate-limit.d.ts +14 -0
- package/build/oauth/rate-limit.d.ts.map +1 -0
- package/build/oauth/rate-limit.js +19 -0
- package/build/oauth/redirects.d.ts +14 -0
- package/build/oauth/redirects.d.ts.map +1 -0
- package/build/oauth/redirects.js +78 -0
- package/build/oauth/store.d.ts +139 -0
- package/build/oauth/store.d.ts.map +1 -0
- package/build/oauth/store.js +606 -0
- package/build/oauth/validate-key.d.ts +21 -0
- package/build/oauth/validate-key.d.ts.map +1 -0
- package/build/oauth/validate-key.js +61 -0
- package/build/request-key.d.ts +9 -0
- package/build/request-key.d.ts.map +1 -0
- package/build/request-key.js +24 -0
- package/build/server.d.ts +1 -1
- package/build/server.d.ts.map +1 -1
- package/build/server.js +151 -5
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
OAuth discovery and sign-in answer on the rewritten `/api/*` paths as well as the public paths.
|
|
6
|
+
|
|
7
|
+
Vercel rewrites `/.well-known/oauth-protected-resource`, `/.well-known/oauth-protected-resource/mcp`, `/.well-known/oauth-authorization-server`, `/.well-known/openid-configuration`, `/register`, `/authorize`, and `/token` to `/api/oauth-protected-resource`, `/api/oauth-protected-resource-mcp`, `/api/oauth-authorization-server`, `/api/openid-configuration`, `/api/oauth-register`, `/api/oauth-authorize`, and `/api/oauth-token`. A Node framework project serves `index.ts` and does not run the `api/*.js` wrappers, so those rewritten paths were 404. The handler now treats each rewritten path as the matching public route. Issuer, resource, and metadata URLs stay on the public paths.
|
|
8
|
+
|
|
9
|
+
## 0.2.1
|
|
10
|
+
|
|
11
|
+
Remote MCP OAuth 2.1 and per-IP rate limits, on top of the 0.2.0 People Search tools. `search` and `fetch` are included for clients that look up a page by query and then read it.
|
|
12
|
+
|
|
13
|
+
- Protected resource metadata, authorization server metadata, dynamic client registration, authorization code with PKCE S256, and rotating refresh tokens. Refresh rotation is atomic. Replaying an authorization code revokes tokens already issued from that code.
|
|
14
|
+
- The sign-in page asks for a Desearch API key and checks it before issuing a code. Only HTTP 422 counts as a valid key. Access tokens are opaque. The key is encrypted at rest and is not placed in the token.
|
|
15
|
+
- A raw Desearch API key in `Authorization` or `x-api-key` still works. `tools/list` without a key still returns tools. `tools/call` without a key returns HTTP 401 with `WWW-Authenticate`, and the body is a tool error with `_meta["mcp/www_authenticate"]`.
|
|
16
|
+
- Production (`NODE_ENV=production` or `VERCEL`) requires `OAUTH_ISSUER` and `OAUTH_STORE=redis`. The issuer is not taken from forwarded host headers. Access tokens must match this server's resource. A bad or expired token challenge includes `error="invalid_token"`. `OAUTH_REQUIRE_AUTH_ON_INITIALIZE=true` makes keyless `initialize` return 401. The sign-in form rejects a cross-site `Origin` or `Referer`, and rejects a POST that sends none of those or `Sec-Fetch-Site`.
|
|
17
|
+
- `POST /register` allows 10 requests an hour per IP. The sign-in key check allows 20 requests every 10 minutes per IP. A request past the limit returns 429 with `Retry-After`.
|
|
18
|
+
- `search` takes `query` and returns titles and links. `fetch` takes a URL and returns the page text.
|
|
19
|
+
- Tool annotations are not all read-only. Lookup tools, including `search` and `fetch`, keep `readOnlyHint: true`, `destructiveHint: false`, and `openWorldHint: true`. `people-search` starts a billed job, so `readOnlyHint` is false and `destructiveHint` is false. `people-search-control` can cancel a search, so `readOnlyHint` is false and `destructiveHint` is true. `openWorldHint` is true on every tool.
|
|
20
|
+
|
|
3
21
|
## 0.2.0
|
|
4
22
|
|
|
5
23
|
People Search tools. Release this version only after People Search is live on `api.desearch.ai`; until then the new tools return the API's HTTP error.
|
|
@@ -84,7 +102,7 @@ Node.js `>=20.18.1`. Node 22 is supported. Node 18 is not. `desearch-js` loads `
|
|
|
84
102
|
|
|
85
103
|
### Tool annotations
|
|
86
104
|
|
|
87
|
-
`tools/list`
|
|
105
|
+
In 0.1.2, `tools/list` set MCP tool annotations on every tool in that release:
|
|
88
106
|
|
|
89
107
|
- `readOnlyHint: true` — the tool reads Desearch, the web, or X and does not write caller state
|
|
90
108
|
- `destructiveHint: false` — it does not perform a destructive update
|
package/README.md
CHANGED
|
@@ -55,10 +55,14 @@ AI search, X search and web search for AI agents, plus page extraction, X data t
|
|
|
55
55
|
|
|
56
56
|
## Tools
|
|
57
57
|
|
|
58
|
-
The Desearch MCP server includes the following tools
|
|
58
|
+
The Desearch MCP server includes the following tools.
|
|
59
|
+
|
|
60
|
+
Lookup tools, including `search` and `fetch`, set `readOnlyHint: true`, `destructiveHint: false`, and `openWorldHint: true`. `people-search` starts a billed background job, so `readOnlyHint` is false and `destructiveHint` is false. `people-search-control` can cancel a search, so `readOnlyHint` is false and `destructiveHint` is true. `openWorldHint` is true on every tool because the call reaches a live external source.
|
|
59
61
|
|
|
60
62
|
- **AI Search** (`ai-search`): Performs AI Twitter and web searches with relevant links and summary. `tools` uses short source ids (`web`, `twitter`, `arxiv`, `wikipedia`, `hackernews`, `reddit`). Older labels such as `Web Search`, `ArXiv Search`, `Wikipedia Search`, `Hacker News Search`, and `Reddit Search` are still accepted and sent as the short id. `youtube` is not accepted. Default is `["web", "twitter"]`.
|
|
61
63
|
- **X Search** (`x-search`): Tweet search on X. Arguments: `query` (required), `count` (optional, default 20). Sort stays Top. Optional filters: `user`, `start_date`, `end_date` (YYYY-MM-DD), `lang`, `verified`, `blue_verified`, `is_quote`, `is_video`, `is_image`, `min_retweets`, `min_replies`, `min_likes`.
|
|
64
|
+
- **Search** (`search`): Web search that returns `{ results: [{ id, title, url }] }`. Argument: `query` (required). `id` is the result URL.
|
|
65
|
+
- **Fetch Page** (`fetch`): Read a public page as text. Argument: `id` (required, an `http` or `https` URL from `search`).
|
|
62
66
|
- **Web Search** (`web-search`): SERP-style web search. Arguments: `query` (required), `start` (optional pagination offset).
|
|
63
67
|
- **Web Links Search** (`web-links-search`): Web link search. Arguments: `prompt` (required), `tools` (optional, only `web`, default `["web"]`; `Web Search` is accepted and rewritten to `web`), `count` (optional, 10–200). The links/web API rejects other sources, so they are not in the enum.
|
|
64
68
|
- **Extract** (`extract`): Read a public URL as text or HTML. Preferred over crawl. Arguments: `url` (required), `format` (optional, `html` or `text`), `js` (optional), `wait` (optional milliseconds).
|
|
@@ -403,8 +407,9 @@ Remote requests do not use that environment variable. Discovery does not need a
|
|
|
403
407
|
|
|
404
408
|
- `Authorization: Bearer <DESEARCH_API_KEY>` (preferred)
|
|
405
409
|
- `x-api-key: <DESEARCH_API_KEY>`
|
|
410
|
+
- `Authorization: Bearer <oauth access token>` after the OAuth sign-in below
|
|
406
411
|
|
|
407
|
-
A bare `Authorization: <DESEARCH_API_KEY>` value is also accepted. The key is not read from the query string. There is no shared server secret
|
|
412
|
+
A bare `Authorization: <DESEARCH_API_KEY>` value is also accepted. The key is not read from the query string. There is no shared server secret. A protected call without a valid key or access token returns 401 with a `WWW-Authenticate` header pointing at `/.well-known/oauth-protected-resource/mcp`. The hosted process forwards the per-request Desearch API key to the Desearch API only when a call needs it. An OAuth access token is opaque: the server looks up the key stored for that token and does not put the raw key in the token.
|
|
408
413
|
|
|
409
414
|
The MCP endpoint is `POST /mcp`. Responses are JSON (stateless Streamable HTTP). `GET` and `DELETE` on `/mcp` return `405` because the server does not keep a session or push server-to-client messages. `GET /`, `GET /health`, and `GET /api/health` are unauthenticated health checks.
|
|
410
415
|
|
|
@@ -427,9 +432,54 @@ Cursor, or any remote MCP client:
|
|
|
427
432
|
}
|
|
428
433
|
```
|
|
429
434
|
|
|
435
|
+
### OAuth sign-in
|
|
436
|
+
|
|
437
|
+
Clients that follow the MCP authorization spec (2025-06-18) can sign in instead of sending a key on every request. Discovery documents:
|
|
438
|
+
|
|
439
|
+
- `GET /.well-known/oauth-protected-resource`
|
|
440
|
+
- `GET /.well-known/oauth-protected-resource/mcp`
|
|
441
|
+
- `GET /.well-known/oauth-authorization-server`
|
|
442
|
+
- `GET /.well-known/openid-configuration` (same authorization server document)
|
|
443
|
+
|
|
444
|
+
`POST /register` is dynamic client registration. `GET /authorize` is the Desearch page where the user pastes an API key. `POST /token` exchanges the authorization code and rotates refresh tokens. PKCE S256 is required. Public clients use `token_endpoint_auth_method` `none`.
|
|
445
|
+
|
|
446
|
+
Allowed callback URLs:
|
|
447
|
+
|
|
448
|
+
- `https://claude.ai/api/mcp/auth_callback`
|
|
449
|
+
- `https://claude.com/api/mcp/auth_callback`
|
|
450
|
+
- `https://chatgpt.com/connector_platform_oauth_redirect`
|
|
451
|
+
- `https://chatgpt.com/connector/oauth/{callback_id}`
|
|
452
|
+
- Loopback `http://localhost`, `http://127.0.0.1`, and `http://[::1]` on any port (host and path must match the registered callback)
|
|
453
|
+
|
|
454
|
+
The connector URL is `https://mcp.desearch.ai/mcp`. On the sign-in page, paste a key from [console.desearch.ai/api-keys](https://console.desearch.ai/api-keys). Leave a client id blank when the client can register itself.
|
|
455
|
+
|
|
456
|
+
Environment variables for the host:
|
|
457
|
+
|
|
458
|
+
| Variable | Required | Purpose |
|
|
459
|
+
| --- | --- | --- |
|
|
460
|
+
| `OAUTH_ISSUER` | Production | Canonical origin with no trailing slash, for example `https://mcp.desearch.ai`. Required when `NODE_ENV=production` or `VERCEL` is set. The process refuses OAuth and bearer challenges if it is unset. The issuer is never taken from `X-Forwarded-Host`. Locally, the request URL is used. |
|
|
461
|
+
| `OAUTH_RESOURCE` | No | Canonical MCP URL. Default is `{OAUTH_ISSUER}/mcp`. Access tokens are rejected when their stored audience does not match this resource. |
|
|
462
|
+
| `OAUTH_STORE` | Production | `memory` (local default) or `redis`. Production (`NODE_ENV=production` or `VERCEL`) refuses to start unless this is `redis`. |
|
|
463
|
+
| `REDIS_URL` | When `OAUTH_STORE=redis` | Redis connection string (`redis://` or `rediss://`). |
|
|
464
|
+
| `OAUTH_ENCRYPTION_KEY` | When `OAUTH_STORE=redis` | 32-byte key, base64 or hex. Generate with `openssl rand -base64 32`. Encrypts stored API keys. |
|
|
465
|
+
| `OAUTH_ACCESS_TTL_SEC` | No | Access token lifetime. Default 3600. Range 60 to 86400. |
|
|
466
|
+
| `OAUTH_REFRESH_TTL_SEC` | No | Refresh token lifetime. Default 30 days. Range 300 to 90 days. |
|
|
467
|
+
| `OAUTH_CODE_TTL_SEC` | No | Authorization code lifetime. Default 300. Range 30 to 600. |
|
|
468
|
+
| `OAUTH_CLIENT_TTL_SEC` | No | Dynamic client lifetime. Default 90 days. Range 3600 to 5 years. |
|
|
469
|
+
| `OAUTH_REGISTER_RATE_LIMIT` | No | Registration attempts per IP per window. Default 10. Range 1 to 10000. |
|
|
470
|
+
| `OAUTH_REGISTER_RATE_WINDOW_SEC` | No | Registration rate-limit window in seconds. Default 3600 (1 hour). Range 1 to 86400. |
|
|
471
|
+
| `OAUTH_AUTHORIZE_RATE_LIMIT` | No | Sign-in key checks per IP per window. Default 20. Range 1 to 10000. |
|
|
472
|
+
| `OAUTH_AUTHORIZE_RATE_WINDOW_SEC` | No | Sign-in key-check window in seconds. Default 600 (10 minutes). Range 1 to 86400. |
|
|
473
|
+
| `DESEARCH_API_BASE` | No | Key check host. Default `https://api.desearch.ai`. |
|
|
474
|
+
| `OAUTH_REQUIRE_AUTH_ON_INITIALIZE` | No | Set to `true` to require a key or access token on `initialize`. Default is off, so keyless `initialize` stays public. `tools/list` stays public either way. |
|
|
475
|
+
|
|
476
|
+
The key check calls `GET /twitter/trends?woeid=1&count=1`. A real key is authenticated and then rejected as invalid input (HTTP 422), so the check does not run a full trends query. Only 422 counts as a valid key. `401` and `403` reject the key. Any other status, including a 2xx, is a verification error and is not treated as valid.
|
|
477
|
+
|
|
478
|
+
`POST /register` allows 10 requests an hour per IP. The sign-in key check allows 20 requests every 10 minutes per IP. A request past the limit returns 429 with `Retry-After`. On Vercel the address is the first `X-Forwarded-For` hop. The sign-in form accepts a same-origin `Origin` or `Referer`, and rejects a POST that sends none of `Origin`, `Referer`, and `Sec-Fetch-Site`.
|
|
479
|
+
|
|
430
480
|
### Use with Claude (custom connector)
|
|
431
481
|
|
|
432
|
-
Desearch is not in the Claude Connectors Directory yet. You can add the hosted server as a custom connector with your Desearch API key.
|
|
482
|
+
Desearch is not in the Claude Connectors Directory yet. You can add the hosted server as a custom connector with your Desearch API key, or with OAuth sign-in.
|
|
433
483
|
|
|
434
484
|
Sources: [Custom remote MCP connectors](https://claude.com/docs/connectors/custom/remote-mcp) and [connector authentication](https://claude.com/docs/connectors/building/authentication). Request-header authentication is a beta feature in Claude.
|
|
435
485
|
|
|
@@ -444,6 +494,8 @@ Sources: [Custom remote MCP connectors](https://claude.com/docs/connectors/custo
|
|
|
444
494
|
|
|
445
495
|
The header value is stored once and shared by everyone in the organization who uses the connector.
|
|
446
496
|
|
|
497
|
+
OAuth alternative: choose sign-in instead of a request header, leave the OAuth client id empty so the client can register itself, and paste a Desearch API key on the Desearch page. The callback URL for hosted Claude apps is `https://claude.ai/api/mcp/auth_callback`. Claude Code uses a loopback callback, which this server accepts on any port.
|
|
498
|
+
|
|
447
499
|
**Claude Code**
|
|
448
500
|
|
|
449
501
|
```bash
|
|
@@ -500,7 +552,9 @@ docker run --rm -e MCP_TRANSPORT=http -p 3000:3000 desearch-mcp
|
|
|
500
552
|
|
|
501
553
|
### Deploy on Vercel
|
|
502
554
|
|
|
503
|
-
Vercel fits
|
|
555
|
+
Vercel fits the MCP handler because each JSON-RPC call is one response. `vercel.json` builds the project, serves `POST /mcp`, and sets the function duration to 60 seconds. The same file rewrites the public OAuth paths to `/api/*`. The server accepts those rewritten paths and the public paths, and the metadata documents still advertise the public paths. Hobby plans cap function duration lower than that, so AI Search tool calls need a plan that allows at least 60 seconds. `initialize` and `tools/list` are short either way.
|
|
556
|
+
|
|
557
|
+
OAuth codes and tokens need shared storage. On Vercel set `OAUTH_STORE=redis`, `REDIS_URL`, `OAUTH_ENCRYPTION_KEY`, and `OAUTH_ISSUER=https://mcp.desearch.ai`. The server refuses OAuth when `OAUTH_ISSUER` is unset or `OAUTH_STORE` is not `redis`, because Vercel sets `VERCEL` on every function. `OAUTH_REQUIRE_AUTH_ON_INITIALIZE=true` is optional. Leave it unset unless a client treats public `initialize` as a reason to skip sign-in.
|
|
504
558
|
|
|
505
559
|
No server-side Desearch API key is required in the Vercel project. After deploy, the endpoint is:
|
|
506
560
|
|
package/build/http.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { extractDesearchApiKey } from "./request-key.js";
|
|
2
|
+
export { extractDesearchApiKey };
|
|
1
3
|
export interface HttpListenOptions {
|
|
2
4
|
port?: number;
|
|
3
5
|
host?: string;
|
|
@@ -7,19 +9,11 @@ export interface RunningHttpServer {
|
|
|
7
9
|
host: string;
|
|
8
10
|
close: () => Promise<void>;
|
|
9
11
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Desearch API key from the remote client.
|
|
12
|
-
* Prefer `Authorization: Bearer <key>` (what MCP clients send). `x-api-key` is
|
|
13
|
-
* accepted as well. A bare `Authorization: <key>` value is accepted so the same
|
|
14
|
-
* string used as `DESEARCH_API_KEY` for stdio can be sent without a scheme.
|
|
15
|
-
* Query strings are ignored so keys do not land in access logs.
|
|
16
|
-
*/
|
|
17
12
|
/**
|
|
18
13
|
* Copy a request onto another path. Used by the Vercel functions, which see
|
|
19
14
|
* the rewritten URL (`/api/mcp`) rather than the public path (`/mcp`).
|
|
20
15
|
*/
|
|
21
16
|
export declare function requestWithPathname(request: Request, pathname: string): Request;
|
|
22
|
-
export declare function extractDesearchApiKey(request: Request): string | undefined;
|
|
23
17
|
/**
|
|
24
18
|
* Stateless Streamable HTTP handler.
|
|
25
19
|
* Each POST builds a fresh MCP server tied to that request's API key.
|
package/build/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../http.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAoBjC,MAAM,WAAW,iBAAiB;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAa/E;AAiOD;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAgF9E;AA2DD,wBAAgB,eAAe,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAiD3F"}
|
package/build/http.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { createServer } from "node:http";
|
|
2
2
|
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
3
|
+
import { DIRECT_CLIENT_IP_HEADER } from "./oauth/client-ip.js";
|
|
4
|
+
import { OAuthConfigError } from "./oauth/errors.js";
|
|
5
|
+
import { handleOAuthHttp, resolveRequestCredential } from "./oauth/http.js";
|
|
6
|
+
import { wwwAuthenticate } from "./oauth/metadata.js";
|
|
7
|
+
import { extractDesearchApiKey } from "./request-key.js";
|
|
3
8
|
import { createDesearchMcpServer, SERVER_NAME, SERVER_VERSION } from "./server.js";
|
|
9
|
+
export { extractDesearchApiKey };
|
|
4
10
|
const CORS_HEADERS = {
|
|
5
11
|
"Access-Control-Allow-Origin": "*",
|
|
6
12
|
"Access-Control-Allow-Methods": "GET, POST, DELETE, OPTIONS",
|
|
7
13
|
"Access-Control-Allow-Headers": "Content-Type, Accept, Authorization, x-api-key, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID",
|
|
8
|
-
"Access-Control-Expose-Headers": "Mcp-Session-Id",
|
|
14
|
+
"Access-Control-Expose-Headers": "Mcp-Session-Id, WWW-Authenticate",
|
|
9
15
|
"Access-Control-Max-Age": "86400",
|
|
10
16
|
};
|
|
11
17
|
const HOP_BY_HOP = new Set([
|
|
@@ -16,13 +22,6 @@ const HOP_BY_HOP = new Set([
|
|
|
16
22
|
"host",
|
|
17
23
|
"content-length",
|
|
18
24
|
]);
|
|
19
|
-
/**
|
|
20
|
-
* Desearch API key from the remote client.
|
|
21
|
-
* Prefer `Authorization: Bearer <key>` (what MCP clients send). `x-api-key` is
|
|
22
|
-
* accepted as well. A bare `Authorization: <key>` value is accepted so the same
|
|
23
|
-
* string used as `DESEARCH_API_KEY` for stdio can be sent without a scheme.
|
|
24
|
-
* Query strings are ignored so keys do not land in access logs.
|
|
25
|
-
*/
|
|
26
25
|
/**
|
|
27
26
|
* Copy a request onto another path. Used by the Vercel functions, which see
|
|
28
27
|
* the rewritten URL (`/api/mcp`) rather than the public path (`/mcp`).
|
|
@@ -41,23 +40,6 @@ export function requestWithPathname(request, pathname) {
|
|
|
41
40
|
}
|
|
42
41
|
return new Request(url, init);
|
|
43
42
|
}
|
|
44
|
-
export function extractDesearchApiKey(request) {
|
|
45
|
-
const authorization = request.headers.get("authorization")?.trim();
|
|
46
|
-
if (authorization) {
|
|
47
|
-
const bearer = /^Bearer\s+(\S+)$/i.exec(authorization);
|
|
48
|
-
if (bearer?.[1]) {
|
|
49
|
-
return bearer[1];
|
|
50
|
-
}
|
|
51
|
-
if (!/^Bearer\b/i.test(authorization) && !/\s/.test(authorization)) {
|
|
52
|
-
return authorization;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const headerKey = request.headers.get("x-api-key")?.trim();
|
|
56
|
-
if (headerKey) {
|
|
57
|
-
return headerKey;
|
|
58
|
-
}
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
43
|
function normalizePath(pathname) {
|
|
62
44
|
if (pathname.length > 1 && pathname.endsWith("/")) {
|
|
63
45
|
return pathname.slice(0, -1);
|
|
@@ -99,16 +81,95 @@ function healthResponse() {
|
|
|
99
81
|
version: SERVER_VERSION,
|
|
100
82
|
transport: "streamable-http",
|
|
101
83
|
endpoint: "/mcp",
|
|
102
|
-
auth: "initialize and tools/list are public. tools/call requires Authorization: Bearer <DESEARCH_API_KEY
|
|
84
|
+
auth: "initialize and tools/list are public. tools/call requires Authorization: Bearer <DESEARCH_API_KEY>, x-api-key, or an OAuth access token.",
|
|
103
85
|
}), {
|
|
104
86
|
status: 200,
|
|
105
87
|
headers: { "Content-Type": "application/json" },
|
|
106
88
|
});
|
|
107
89
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
90
|
+
const INVALID_TOKEN_CHALLENGE = {
|
|
91
|
+
error: "invalid_token",
|
|
92
|
+
error_description: "The access token is invalid or expired.",
|
|
93
|
+
};
|
|
94
|
+
const LOGIN_CHALLENGE = {
|
|
95
|
+
error: "insufficient_scope",
|
|
96
|
+
error_description: "You need to login to continue",
|
|
97
|
+
};
|
|
98
|
+
const UNAUTHORIZED_MESSAGE = "Unauthorized. Send your Desearch API key in the Authorization: Bearer <key> header or the x-api-key header.";
|
|
99
|
+
function challengeHeader(request, challenge) {
|
|
100
|
+
try {
|
|
101
|
+
return wwwAuthenticate(request, challenge);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (error instanceof OAuthConfigError) {
|
|
105
|
+
return jsonRpcError(500, -32603, "Authorization storage is unavailable.");
|
|
106
|
+
}
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function unauthorized(request, invalidToken = false) {
|
|
111
|
+
const header = challengeHeader(request, invalidToken ? INVALID_TOKEN_CHALLENGE : undefined);
|
|
112
|
+
if (header instanceof Response) {
|
|
113
|
+
return header;
|
|
114
|
+
}
|
|
115
|
+
return jsonRpcError(401, -32001, UNAUTHORIZED_MESSAGE, { "WWW-Authenticate": header });
|
|
116
|
+
}
|
|
117
|
+
function readToolsCalls(raw) {
|
|
118
|
+
let parsed;
|
|
119
|
+
try {
|
|
120
|
+
parsed = JSON.parse(raw);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const batched = Array.isArray(parsed);
|
|
126
|
+
const messages = batched ? parsed : [parsed];
|
|
127
|
+
if (messages.length === 0) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
const calls = [];
|
|
131
|
+
for (const message of messages) {
|
|
132
|
+
if (typeof message !== "object" || message === null) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
if (message.method !== "tools/call") {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
calls.push(message);
|
|
139
|
+
}
|
|
140
|
+
return { batched, calls };
|
|
141
|
+
}
|
|
142
|
+
function authFailure(request, raw, invalidToken) {
|
|
143
|
+
const header = challengeHeader(request, invalidToken ? INVALID_TOKEN_CHALLENGE : undefined);
|
|
144
|
+
if (header instanceof Response) {
|
|
145
|
+
return header;
|
|
146
|
+
}
|
|
147
|
+
const metaHeader = invalidToken ? header : challengeHeader(request, LOGIN_CHALLENGE);
|
|
148
|
+
if (metaHeader instanceof Response) {
|
|
149
|
+
return metaHeader;
|
|
150
|
+
}
|
|
151
|
+
const tools = readToolsCalls(raw);
|
|
152
|
+
if (!tools) {
|
|
153
|
+
return jsonRpcError(401, -32001, UNAUTHORIZED_MESSAGE, { "WWW-Authenticate": header });
|
|
154
|
+
}
|
|
155
|
+
const results = tools.calls.map((call) => ({
|
|
156
|
+
jsonrpc: "2.0",
|
|
157
|
+
id: call.id ?? null,
|
|
158
|
+
result: {
|
|
159
|
+
content: [{ type: "text", text: UNAUTHORIZED_MESSAGE }],
|
|
160
|
+
isError: true,
|
|
161
|
+
_meta: {
|
|
162
|
+
"mcp/www_authenticate": [`'${metaHeader}'`],
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
}));
|
|
166
|
+
return new Response(JSON.stringify(tools.batched ? results : results[0]), {
|
|
167
|
+
status: 401,
|
|
168
|
+
headers: {
|
|
169
|
+
"Content-Type": "application/json",
|
|
170
|
+
"WWW-Authenticate": header,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
112
173
|
}
|
|
113
174
|
/**
|
|
114
175
|
* Methods a marketplace scanner can call with no Desearch API key.
|
|
@@ -124,6 +185,15 @@ const KEYLESS_METHODS = new Set([
|
|
|
124
185
|
"resources/list",
|
|
125
186
|
"resources/templates/list",
|
|
126
187
|
]);
|
|
188
|
+
function authRequiredOnInitialize() {
|
|
189
|
+
return /^(1|true|yes)$/i.test((process.env.OAUTH_REQUIRE_AUTH_ON_INITIALIZE ?? "").trim());
|
|
190
|
+
}
|
|
191
|
+
function isKeylessMethod(method) {
|
|
192
|
+
if (method === "initialize" && authRequiredOnInitialize()) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
return KEYLESS_METHODS.has(method);
|
|
196
|
+
}
|
|
127
197
|
function isKeylessDiscovery(raw) {
|
|
128
198
|
let parsed;
|
|
129
199
|
try {
|
|
@@ -139,7 +209,7 @@ function isKeylessDiscovery(raw) {
|
|
|
139
209
|
return false;
|
|
140
210
|
}
|
|
141
211
|
const method = message.method;
|
|
142
|
-
return typeof method === "string" &&
|
|
212
|
+
return typeof method === "string" && isKeylessMethod(method);
|
|
143
213
|
}));
|
|
144
214
|
}
|
|
145
215
|
function copyRequestHeaders(headers) {
|
|
@@ -178,6 +248,10 @@ export async function handleMcpHttpRequest(request) {
|
|
|
178
248
|
return withCors(new Response(null, { status: 204 }));
|
|
179
249
|
}
|
|
180
250
|
const pathname = normalizePath(new URL(request.url).pathname);
|
|
251
|
+
const oauthResponse = await handleOAuthHttp(request);
|
|
252
|
+
if (oauthResponse) {
|
|
253
|
+
return withCors(oauthResponse);
|
|
254
|
+
}
|
|
181
255
|
if (isHealthPath(pathname)) {
|
|
182
256
|
if (request.method === "GET") {
|
|
183
257
|
return withCors(healthResponse());
|
|
@@ -190,20 +264,31 @@ export async function handleMcpHttpRequest(request) {
|
|
|
190
264
|
headers: { "Content-Type": "application/json" },
|
|
191
265
|
}));
|
|
192
266
|
}
|
|
267
|
+
const credential = await resolveRequestCredential(request);
|
|
268
|
+
if (credential.kind === "unavailable") {
|
|
269
|
+
return withCors(jsonRpcError(500, -32603, "Authorization storage is unavailable."));
|
|
270
|
+
}
|
|
193
271
|
if (request.method === "GET" || request.method === "DELETE") {
|
|
194
|
-
if (
|
|
195
|
-
return withCors(unauthorized());
|
|
272
|
+
if (credential.kind !== "key") {
|
|
273
|
+
return withCors(unauthorized(request, credential.kind === "unauthorized"));
|
|
196
274
|
}
|
|
197
275
|
return withCors(jsonRpcError(405, -32000, "Method not allowed. This server is stateless; use POST.", { Allow: "POST" }));
|
|
198
276
|
}
|
|
199
277
|
if (request.method !== "POST") {
|
|
200
278
|
return withCors(jsonRpcError(405, -32000, "Method not allowed.", { Allow: "POST" }));
|
|
201
279
|
}
|
|
202
|
-
let apiKey
|
|
203
|
-
if (
|
|
280
|
+
let apiKey;
|
|
281
|
+
if (credential.kind === "key") {
|
|
282
|
+
apiKey = credential.apiKey;
|
|
283
|
+
}
|
|
284
|
+
else if (credential.kind === "unauthorized") {
|
|
285
|
+
const raw = await request.text();
|
|
286
|
+
return withCors(authFailure(request, raw, true));
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
204
289
|
const raw = await request.text();
|
|
205
290
|
if (!isKeylessDiscovery(raw)) {
|
|
206
|
-
return withCors(
|
|
291
|
+
return withCors(authFailure(request, raw, false));
|
|
207
292
|
}
|
|
208
293
|
request = requestWithJsonBody(request, raw);
|
|
209
294
|
apiKey = "";
|
|
@@ -247,7 +332,7 @@ async function toWebRequest(req) {
|
|
|
247
332
|
const url = `http://${host}${req.url ?? "/"}`;
|
|
248
333
|
const headers = new Headers();
|
|
249
334
|
for (const [key, value] of Object.entries(req.headers)) {
|
|
250
|
-
if (value === undefined || HOP_BY_HOP.has(key.toLowerCase())) {
|
|
335
|
+
if (value === undefined || HOP_BY_HOP.has(key.toLowerCase()) || key.toLowerCase() === DIRECT_CLIENT_IP_HEADER) {
|
|
251
336
|
continue;
|
|
252
337
|
}
|
|
253
338
|
if (Array.isArray(value)) {
|
|
@@ -259,6 +344,10 @@ async function toWebRequest(req) {
|
|
|
259
344
|
headers.set(key, value);
|
|
260
345
|
}
|
|
261
346
|
}
|
|
347
|
+
const remote = req.socket?.remoteAddress;
|
|
348
|
+
if (remote) {
|
|
349
|
+
headers.set(DIRECT_CLIENT_IP_HEADER, remote);
|
|
350
|
+
}
|
|
262
351
|
const method = req.method ?? "GET";
|
|
263
352
|
const hasBody = method !== "GET" && method !== "HEAD";
|
|
264
353
|
const body = hasBody ? await readRawBody(req) : undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Stamped by the Node HTTP server from the socket. Ignored when `VERCEL` is set. */
|
|
2
|
+
export declare const DIRECT_CLIENT_IP_HEADER = "x-desearch-remote-address";
|
|
3
|
+
/**
|
|
4
|
+
* Address used for per-IP limits.
|
|
5
|
+
* On Vercel the platform puts the client first in `X-Forwarded-For` and appends
|
|
6
|
+
* proxies, so the first hop is the caller. Off Vercel that header is chosen by
|
|
7
|
+
* the client and is ignored. The Node server stamps the socket address instead.
|
|
8
|
+
*/
|
|
9
|
+
export declare function clientIp(request: Request): string;
|
|
10
|
+
//# sourceMappingURL=client-ip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-ip.d.ts","sourceRoot":"","sources":["../../oauth/client-ip.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,eAAO,MAAM,uBAAuB,8BAA8B,CAAC;AAEnE;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CASjD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Stamped by the Node HTTP server from the socket. Ignored when `VERCEL` is set. */
|
|
2
|
+
export const DIRECT_CLIENT_IP_HEADER = "x-desearch-remote-address";
|
|
3
|
+
/**
|
|
4
|
+
* Address used for per-IP limits.
|
|
5
|
+
* On Vercel the platform puts the client first in `X-Forwarded-For` and appends
|
|
6
|
+
* proxies, so the first hop is the caller. Off Vercel that header is chosen by
|
|
7
|
+
* the client and is ignored. The Node server stamps the socket address instead.
|
|
8
|
+
*/
|
|
9
|
+
export function clientIp(request) {
|
|
10
|
+
if (process.env.VERCEL) {
|
|
11
|
+
return firstForwardedHop(request.headers.get("x-forwarded-for")) ?? "unknown";
|
|
12
|
+
}
|
|
13
|
+
const direct = request.headers.get(DIRECT_CLIENT_IP_HEADER)?.trim();
|
|
14
|
+
if (direct) {
|
|
15
|
+
return direct.slice(0, 128);
|
|
16
|
+
}
|
|
17
|
+
return "unknown";
|
|
18
|
+
}
|
|
19
|
+
function firstForwardedHop(value) {
|
|
20
|
+
if (!value) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const first = value.split(",")[0]?.trim().replace(/^"|"$/g, "");
|
|
24
|
+
if (!first) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return first.slice(0, 128);
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const ACCESS_TOKEN_PREFIX = "dsoat_";
|
|
2
|
+
export declare const REFRESH_TOKEN_PREFIX = "dsort_";
|
|
3
|
+
export declare const AUTH_CODE_PREFIX = "dsoc_";
|
|
4
|
+
export declare const CLIENT_ID_PREFIX = "dsocid_";
|
|
5
|
+
export declare function randomToken(prefix: string, bytes?: number): string;
|
|
6
|
+
export declare function sha256(value: string): string;
|
|
7
|
+
export declare function s256Challenge(verifier: string): string;
|
|
8
|
+
export declare function challengesMatch(actual: string, expected: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* AES-256-GCM key for API keys at rest.
|
|
11
|
+
* Redis mode refuses to start without OAUTH_ENCRYPTION_KEY so two instances
|
|
12
|
+
* cannot encrypt with different process-local keys.
|
|
13
|
+
*/
|
|
14
|
+
export declare function encryptionKey(options?: {
|
|
15
|
+
requireConfigured?: boolean;
|
|
16
|
+
}): Buffer;
|
|
17
|
+
export declare function encryptSecret(plaintext: string, key?: Buffer): string;
|
|
18
|
+
export declare function decryptSecret(payload: string, key?: Buffer): string;
|
|
19
|
+
export declare function positiveInt(raw: string | undefined, fallback: number, min: number, max: number): number;
|
|
20
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../oauth/crypto.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAC5C,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAC7C,eAAO,MAAM,gBAAgB,UAAU,CAAC;AACxC,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAQ1C,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM,CAE9D;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAOzE;AAkBD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,MAAM,CAenF;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,GAAE,MAAwB,GAAG,MAAM,CAMtF;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,MAAwB,GAAG,MAAM,CAWpF;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CASvG"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes, timingSafeEqual, } from "node:crypto";
|
|
2
|
+
export const ACCESS_TOKEN_PREFIX = "dsoat_";
|
|
3
|
+
export const REFRESH_TOKEN_PREFIX = "dsort_";
|
|
4
|
+
export const AUTH_CODE_PREFIX = "dsoc_";
|
|
5
|
+
export const CLIENT_ID_PREFIX = "dsocid_";
|
|
6
|
+
const KEY_BYTES = 32;
|
|
7
|
+
const IV_BYTES = 12;
|
|
8
|
+
const TAG_BYTES = 16;
|
|
9
|
+
const globalKey = globalThis;
|
|
10
|
+
export function randomToken(prefix, bytes = 32) {
|
|
11
|
+
return prefix + randomBytes(bytes).toString("base64url");
|
|
12
|
+
}
|
|
13
|
+
export function sha256(value) {
|
|
14
|
+
return createHash("sha256").update(value).digest("hex");
|
|
15
|
+
}
|
|
16
|
+
export function s256Challenge(verifier) {
|
|
17
|
+
return createHash("sha256").update(verifier).digest("base64url");
|
|
18
|
+
}
|
|
19
|
+
export function challengesMatch(actual, expected) {
|
|
20
|
+
const left = Buffer.from(actual);
|
|
21
|
+
const right = Buffer.from(expected);
|
|
22
|
+
if (left.length !== right.length) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return timingSafeEqual(left, right);
|
|
26
|
+
}
|
|
27
|
+
function decodeConfiguredKey(raw) {
|
|
28
|
+
const trimmed = raw.trim();
|
|
29
|
+
if (/^[0-9a-fA-F]{64}$/.test(trimmed)) {
|
|
30
|
+
return Buffer.from(trimmed, "hex");
|
|
31
|
+
}
|
|
32
|
+
const decoded = Buffer.from(trimmed, "base64url");
|
|
33
|
+
if (decoded.length === KEY_BYTES) {
|
|
34
|
+
return decoded;
|
|
35
|
+
}
|
|
36
|
+
const standard = Buffer.from(trimmed, "base64");
|
|
37
|
+
if (standard.length === KEY_BYTES) {
|
|
38
|
+
return standard;
|
|
39
|
+
}
|
|
40
|
+
throw new Error("OAUTH_ENCRYPTION_KEY must decode to 32 bytes (base64 or hex)");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* AES-256-GCM key for API keys at rest.
|
|
44
|
+
* Redis mode refuses to start without OAUTH_ENCRYPTION_KEY so two instances
|
|
45
|
+
* cannot encrypt with different process-local keys.
|
|
46
|
+
*/
|
|
47
|
+
export function encryptionKey(options = {}) {
|
|
48
|
+
const configured = process.env.OAUTH_ENCRYPTION_KEY?.trim();
|
|
49
|
+
if (configured) {
|
|
50
|
+
return decodeConfiguredKey(configured);
|
|
51
|
+
}
|
|
52
|
+
if (options.requireConfigured) {
|
|
53
|
+
throw new Error("OAUTH_ENCRYPTION_KEY is required when OAUTH_STORE=redis");
|
|
54
|
+
}
|
|
55
|
+
if (!globalKey.__desearchOAuthKey) {
|
|
56
|
+
globalKey.__desearchOAuthKey = randomBytes(KEY_BYTES);
|
|
57
|
+
console.error("OAUTH_ENCRYPTION_KEY is unset. OAuth token storage is using a process-local key.");
|
|
58
|
+
}
|
|
59
|
+
return globalKey.__desearchOAuthKey;
|
|
60
|
+
}
|
|
61
|
+
export function encryptSecret(plaintext, key = encryptionKey()) {
|
|
62
|
+
const iv = randomBytes(IV_BYTES);
|
|
63
|
+
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
64
|
+
const ciphertext = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
65
|
+
const tag = cipher.getAuthTag();
|
|
66
|
+
return Buffer.concat([iv, tag, ciphertext]).toString("base64url");
|
|
67
|
+
}
|
|
68
|
+
export function decryptSecret(payload, key = encryptionKey()) {
|
|
69
|
+
const raw = Buffer.from(payload, "base64url");
|
|
70
|
+
if (raw.length <= IV_BYTES + TAG_BYTES) {
|
|
71
|
+
throw new Error("ciphertext is truncated");
|
|
72
|
+
}
|
|
73
|
+
const iv = raw.subarray(0, IV_BYTES);
|
|
74
|
+
const tag = raw.subarray(IV_BYTES, IV_BYTES + TAG_BYTES);
|
|
75
|
+
const ciphertext = raw.subarray(IV_BYTES + TAG_BYTES);
|
|
76
|
+
const decipher = createDecipheriv("aes-256-gcm", key, iv);
|
|
77
|
+
decipher.setAuthTag(tag);
|
|
78
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString("utf8");
|
|
79
|
+
}
|
|
80
|
+
export function positiveInt(raw, fallback, min, max) {
|
|
81
|
+
if (raw === undefined || raw.trim() === "") {
|
|
82
|
+
return fallback;
|
|
83
|
+
}
|
|
84
|
+
const value = Number(raw);
|
|
85
|
+
if (!Number.isInteger(value) || value < min || value > max) {
|
|
86
|
+
throw new Error(`expected an integer from ${min} to ${max}`);
|
|
87
|
+
}
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class OAuthConfigError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Hosted runtimes must not fall open on process-local OAuth settings.
|
|
6
|
+
* Vercel sets `VERCEL` even when `NODE_ENV` is missing.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isProductionHost(): boolean;
|
|
9
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../oauth/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,gBAAiB,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI9B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class OAuthConfigError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = "OAuthConfigError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Hosted runtimes must not fall open on process-local OAuth settings.
|
|
9
|
+
* Vercel sets `VERCEL` even when `NODE_ENV` is missing.
|
|
10
|
+
*/
|
|
11
|
+
export function isProductionHost() {
|
|
12
|
+
return process.env.NODE_ENV === "production" || Boolean(process.env.VERCEL);
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function htmlResponse(status: number, html: string): Response;
|
|
2
|
+
export declare function oauthError(status: number, error: string, description: string): Response;
|
|
3
|
+
export declare function registerClient(request: Request): Promise<Response>;
|
|
4
|
+
export declare function showAuthorize(request: Request): Promise<Response>;
|
|
5
|
+
export declare function submitAuthorize(request: Request): Promise<Response>;
|
|
6
|
+
export declare function exchangeToken(request: Request): Promise<Response>;
|
|
7
|
+
export declare function lookupAccessApiKey(token: string, request: Request): Promise<string | null>;
|
|
8
|
+
//# sourceMappingURL=flow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../oauth/flow.ts"],"names":[],"mappings":"AAqCA,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAEnE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,QAAQ,CAQvF;AAyDD,wBAAsB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqFxE;AAwFD,wBAAsB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAOvE;AAgCD,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0DzE;AAgED,wBAAsB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmBvE;AAoDD,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAUhG"}
|