oauth-callback 1.1.0 → 1.2.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/README.md +12 -12
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +68 -53
- package/dist/mcp.d.ts +11 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +1381 -0
- package/package.json +6 -2
- package/src/index.ts +4 -6
- package/src/mcp.ts +23 -0
package/README.md
CHANGED
|
@@ -42,12 +42,7 @@ npm install oauth-callback
|
|
|
42
42
|
## Quick Start
|
|
43
43
|
|
|
44
44
|
```typescript
|
|
45
|
-
import {
|
|
46
|
-
getAuthCode,
|
|
47
|
-
OAuthError,
|
|
48
|
-
browserAuth,
|
|
49
|
-
fileStore,
|
|
50
|
-
} from "oauth-callback";
|
|
45
|
+
import { getAuthCode, OAuthError } from "oauth-callback";
|
|
51
46
|
|
|
52
47
|
// Simple usage
|
|
53
48
|
const result = await getAuthCode(
|
|
@@ -55,8 +50,13 @@ const result = await getAuthCode(
|
|
|
55
50
|
);
|
|
56
51
|
console.log("Authorization code:", result.code);
|
|
57
52
|
|
|
58
|
-
// MCP SDK integration
|
|
53
|
+
// MCP SDK integration - use specific import
|
|
54
|
+
import { browserAuth, fileStore } from "oauth-callback/mcp";
|
|
59
55
|
const authProvider = browserAuth({ store: fileStore() });
|
|
56
|
+
|
|
57
|
+
// Or via namespace import
|
|
58
|
+
import { mcp } from "oauth-callback";
|
|
59
|
+
const authProvider = mcp.browserAuth({ store: mcp.fileStore() });
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
## Usage Examples
|
|
@@ -139,7 +139,7 @@ const microsoftAuth = await getAuthCode(
|
|
|
139
139
|
The `browserAuth()` function provides a drop-in OAuth provider for the Model Context Protocol SDK:
|
|
140
140
|
|
|
141
141
|
```typescript
|
|
142
|
-
import { browserAuth, inMemoryStore } from "oauth-callback";
|
|
142
|
+
import { browserAuth, inMemoryStore } from "oauth-callback/mcp";
|
|
143
143
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
144
144
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
145
145
|
|
|
@@ -167,7 +167,7 @@ await client.connect(transport);
|
|
|
167
167
|
#### Token Storage Options
|
|
168
168
|
|
|
169
169
|
```typescript
|
|
170
|
-
import { browserAuth, inMemoryStore, fileStore } from "oauth-callback";
|
|
170
|
+
import { browserAuth, inMemoryStore, fileStore } from "oauth-callback/mcp";
|
|
171
171
|
|
|
172
172
|
// Ephemeral storage (tokens lost on restart)
|
|
173
173
|
const ephemeralAuth = browserAuth({
|
|
@@ -283,7 +283,7 @@ class OAuthError extends Error {
|
|
|
283
283
|
|
|
284
284
|
### `browserAuth(options)`
|
|
285
285
|
|
|
286
|
-
Creates an MCP SDK-compatible OAuth provider for browser-based flows. Handles Dynamic Client Registration (DCR), token storage, and automatic refresh.
|
|
286
|
+
Available from `oauth-callback/mcp`. Creates an MCP SDK-compatible OAuth provider for browser-based flows. Handles Dynamic Client Registration (DCR), token storage, and automatic refresh.
|
|
287
287
|
|
|
288
288
|
#### Parameters
|
|
289
289
|
|
|
@@ -307,7 +307,7 @@ OAuthClientProvider compatible with MCP SDK transports.
|
|
|
307
307
|
|
|
308
308
|
### `inMemoryStore()`
|
|
309
309
|
|
|
310
|
-
Creates an ephemeral in-memory token store. Tokens are lost when the process exits.
|
|
310
|
+
Available from `oauth-callback/mcp`. Creates an ephemeral in-memory token store. Tokens are lost when the process exits.
|
|
311
311
|
|
|
312
312
|
#### Returns
|
|
313
313
|
|
|
@@ -315,7 +315,7 @@ TokenStore implementation for temporary token storage.
|
|
|
315
315
|
|
|
316
316
|
### `fileStore(filepath?)`
|
|
317
317
|
|
|
318
|
-
Creates a persistent file-based token store.
|
|
318
|
+
Available from `oauth-callback/mcp`. Creates a persistent file-based token store.
|
|
319
319
|
|
|
320
320
|
#### Parameters
|
|
321
321
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ import type { GetAuthCodeOptions } from "./types";
|
|
|
3
3
|
export type { CallbackResult, CallbackServer, ServerOptions } from "./server";
|
|
4
4
|
export { OAuthError } from "./errors";
|
|
5
5
|
export type { GetAuthCodeOptions } from "./types";
|
|
6
|
-
export { browserAuth } from "./auth/browser-auth";
|
|
7
6
|
export { inMemoryStore } from "./storage/memory";
|
|
8
7
|
export { fileStore } from "./storage/file";
|
|
9
|
-
|
|
8
|
+
import * as mcp from "./mcp";
|
|
9
|
+
export { mcp };
|
|
10
10
|
/**
|
|
11
11
|
* Captures OAuth authorization code via localhost callback.
|
|
12
12
|
* Opens browser to auth URL, waits for provider redirect to localhost.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGlD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAE,CAAC;AAEf;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,kBAAkB,GAAG,MAAM,GACjC,OAAO,CAAC,cAAc,CAAC,CA8DzB"}
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,15 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
15
15
|
});
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
+
var __export = (target, all) => {
|
|
19
|
+
for (var name in all)
|
|
20
|
+
__defProp(target, name, {
|
|
21
|
+
get: all[name],
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
set: (newValue) => all[name] = () => newValue
|
|
25
|
+
});
|
|
26
|
+
};
|
|
18
27
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
19
28
|
|
|
20
29
|
// node_modules/open/index.js
|
|
@@ -946,16 +955,6 @@ function createCallbackServer() {
|
|
|
946
955
|
}
|
|
947
956
|
return new NodeCallbackServer;
|
|
948
957
|
}
|
|
949
|
-
// src/auth/browser-auth.ts
|
|
950
|
-
import { randomBytes } from "node:crypto";
|
|
951
|
-
|
|
952
|
-
// src/utils/token.ts
|
|
953
|
-
function calculateExpiry(expiresIn) {
|
|
954
|
-
if (!expiresIn)
|
|
955
|
-
return;
|
|
956
|
-
return Date.now() + expiresIn * 1000;
|
|
957
|
-
}
|
|
958
|
-
|
|
959
958
|
// src/storage/memory.ts
|
|
960
959
|
function inMemoryStore() {
|
|
961
960
|
const store = new Map;
|
|
@@ -974,6 +973,64 @@ function inMemoryStore() {
|
|
|
974
973
|
}
|
|
975
974
|
};
|
|
976
975
|
}
|
|
976
|
+
// src/storage/file.ts
|
|
977
|
+
import * as fs6 from "node:fs/promises";
|
|
978
|
+
import * as path2 from "node:path";
|
|
979
|
+
import * as os2 from "node:os";
|
|
980
|
+
function fileStore(filepath) {
|
|
981
|
+
const file = filepath ?? path2.join(os2.homedir(), ".mcp", "tokens.json");
|
|
982
|
+
async function ensureDir() {
|
|
983
|
+
await fs6.mkdir(path2.dirname(file), { recursive: true });
|
|
984
|
+
}
|
|
985
|
+
async function readStore() {
|
|
986
|
+
try {
|
|
987
|
+
const data = await fs6.readFile(file, "utf-8");
|
|
988
|
+
return JSON.parse(data);
|
|
989
|
+
} catch {
|
|
990
|
+
return {};
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
async function writeStore(data) {
|
|
994
|
+
await ensureDir();
|
|
995
|
+
await fs6.writeFile(file, JSON.stringify(data, null, 2), "utf-8");
|
|
996
|
+
}
|
|
997
|
+
return {
|
|
998
|
+
async get(key) {
|
|
999
|
+
const store = await readStore();
|
|
1000
|
+
return store[key] ?? null;
|
|
1001
|
+
},
|
|
1002
|
+
async set(key, tokens) {
|
|
1003
|
+
const store = await readStore();
|
|
1004
|
+
store[key] = tokens;
|
|
1005
|
+
await writeStore(store);
|
|
1006
|
+
},
|
|
1007
|
+
async delete(key) {
|
|
1008
|
+
const store = await readStore();
|
|
1009
|
+
delete store[key];
|
|
1010
|
+
await writeStore(store);
|
|
1011
|
+
},
|
|
1012
|
+
async clear() {
|
|
1013
|
+
await writeStore({});
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
// src/mcp.ts
|
|
1018
|
+
var exports_mcp = {};
|
|
1019
|
+
__export(exports_mcp, {
|
|
1020
|
+
inMemoryStore: () => inMemoryStore,
|
|
1021
|
+
fileStore: () => fileStore,
|
|
1022
|
+
browserAuth: () => browserAuth
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
// src/auth/browser-auth.ts
|
|
1026
|
+
import { randomBytes } from "node:crypto";
|
|
1027
|
+
|
|
1028
|
+
// src/utils/token.ts
|
|
1029
|
+
function calculateExpiry(expiresIn) {
|
|
1030
|
+
if (!expiresIn)
|
|
1031
|
+
return;
|
|
1032
|
+
return Date.now() + expiresIn * 1000;
|
|
1033
|
+
}
|
|
977
1034
|
|
|
978
1035
|
// src/auth/browser-auth.ts
|
|
979
1036
|
function browserAuth(options = {}) {
|
|
@@ -1286,48 +1343,6 @@ class BrowserOAuthProvider {
|
|
|
1286
1343
|
throw new Error("Token refresh not yet implemented - requires token endpoint URL");
|
|
1287
1344
|
}
|
|
1288
1345
|
}
|
|
1289
|
-
// src/storage/file.ts
|
|
1290
|
-
import * as fs6 from "node:fs/promises";
|
|
1291
|
-
import * as path2 from "node:path";
|
|
1292
|
-
import * as os2 from "node:os";
|
|
1293
|
-
function fileStore(filepath) {
|
|
1294
|
-
const file = filepath ?? path2.join(os2.homedir(), ".mcp", "tokens.json");
|
|
1295
|
-
async function ensureDir() {
|
|
1296
|
-
await fs6.mkdir(path2.dirname(file), { recursive: true });
|
|
1297
|
-
}
|
|
1298
|
-
async function readStore() {
|
|
1299
|
-
try {
|
|
1300
|
-
const data = await fs6.readFile(file, "utf-8");
|
|
1301
|
-
return JSON.parse(data);
|
|
1302
|
-
} catch {
|
|
1303
|
-
return {};
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
async function writeStore(data) {
|
|
1307
|
-
await ensureDir();
|
|
1308
|
-
await fs6.writeFile(file, JSON.stringify(data, null, 2), "utf-8");
|
|
1309
|
-
}
|
|
1310
|
-
return {
|
|
1311
|
-
async get(key) {
|
|
1312
|
-
const store = await readStore();
|
|
1313
|
-
return store[key] ?? null;
|
|
1314
|
-
},
|
|
1315
|
-
async set(key, tokens) {
|
|
1316
|
-
const store = await readStore();
|
|
1317
|
-
store[key] = tokens;
|
|
1318
|
-
await writeStore(store);
|
|
1319
|
-
},
|
|
1320
|
-
async delete(key) {
|
|
1321
|
-
const store = await readStore();
|
|
1322
|
-
delete store[key];
|
|
1323
|
-
await writeStore(store);
|
|
1324
|
-
},
|
|
1325
|
-
async clear() {
|
|
1326
|
-
await writeStore({});
|
|
1327
|
-
}
|
|
1328
|
-
};
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
1346
|
// src/index.ts
|
|
1332
1347
|
async function getAuthCode(input) {
|
|
1333
1348
|
const options = typeof input === "string" ? { authorizationUrl: input } : input;
|
|
@@ -1375,9 +1390,9 @@ async function getAuthCode(input) {
|
|
|
1375
1390
|
}
|
|
1376
1391
|
}
|
|
1377
1392
|
export {
|
|
1393
|
+
exports_mcp as mcp,
|
|
1378
1394
|
inMemoryStore,
|
|
1379
1395
|
getAuthCode,
|
|
1380
1396
|
fileStore,
|
|
1381
|
-
browserAuth,
|
|
1382
1397
|
OAuthError
|
|
1383
1398
|
};
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP SDK-specific OAuth providers and utilities.
|
|
3
|
+
* For Model Context Protocol integration.
|
|
4
|
+
*
|
|
5
|
+
* @module oauth-callback/mcp
|
|
6
|
+
*/
|
|
7
|
+
export { browserAuth } from "./auth/browser-auth";
|
|
8
|
+
export { inMemoryStore } from "./storage/memory";
|
|
9
|
+
export { fileStore } from "./storage/file";
|
|
10
|
+
export type { BrowserAuthOptions, Tokens, TokenStore, ClientInfo, OAuthSession, OAuthStore, } from "./mcp-types";
|
|
11
|
+
//# sourceMappingURL=mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,YAAY,EACV,kBAAkB,EAClB,MAAM,EACN,UAAU,EACV,UAAU,EACV,YAAY,EACZ,UAAU,GACX,MAAM,aAAa,CAAC"}
|