oauth-callback 2.1.1 → 2.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 +21 -8
- package/dist/auth/browser-auth.d.ts +1 -1
- package/dist/auth/browser-auth.d.ts.map +1 -1
- package/dist/index.js +5359 -234
- package/dist/mcp-types.d.ts +25 -15
- package/dist/mcp-types.d.ts.map +1 -1
- package/dist/mcp.d.ts +2 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +105 -86
- package/dist/storage/file.d.ts +1 -1
- package/dist/storage/file.d.ts.map +1 -1
- package/dist/storage/memory.d.ts +1 -1
- package/dist/storage/memory.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/auth/browser-auth.test.ts +175 -65
- package/src/auth/browser-auth.ts +160 -116
- package/src/mcp-types.ts +29 -16
- package/src/mcp.ts +1 -1
- package/src/storage/file.ts +4 -7
- package/src/storage/memory.ts +1 -5
package/README.md
CHANGED
|
@@ -127,6 +127,8 @@ import { browserAuth, inMemoryStore } from "oauth-callback/mcp";
|
|
|
127
127
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
128
128
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
129
129
|
|
|
130
|
+
const serverUrl = new URL("https://mcp.notion.com/mcp");
|
|
131
|
+
|
|
130
132
|
// Create MCP-compatible OAuth provider
|
|
131
133
|
const authProvider = browserAuth({
|
|
132
134
|
port: 3000,
|
|
@@ -135,18 +137,29 @@ const authProvider = browserAuth({
|
|
|
135
137
|
store: inMemoryStore(), // Or fileStore() for persistence
|
|
136
138
|
});
|
|
137
139
|
|
|
138
|
-
// Use with MCP SDK transport
|
|
139
|
-
const transport = new StreamableHTTPClientTransport(
|
|
140
|
-
new URL("https://mcp.notion.com/mcp"),
|
|
141
|
-
{ authProvider },
|
|
142
|
-
);
|
|
143
|
-
|
|
144
140
|
const client = new Client(
|
|
145
141
|
{ name: "my-app", version: "1.0.0" },
|
|
146
142
|
{ capabilities: {} },
|
|
147
143
|
);
|
|
148
144
|
|
|
149
|
-
|
|
145
|
+
// Connect with OAuth retry: first attempt completes OAuth and saves tokens,
|
|
146
|
+
// but SDK returns before checking them. Second attempt succeeds.
|
|
147
|
+
async function connectWithOAuthRetry() {
|
|
148
|
+
const transport = new StreamableHTTPClientTransport(serverUrl, {
|
|
149
|
+
authProvider,
|
|
150
|
+
});
|
|
151
|
+
try {
|
|
152
|
+
await client.connect(transport);
|
|
153
|
+
} catch (error: any) {
|
|
154
|
+
if (error.message === "Unauthorized") {
|
|
155
|
+
await client.connect(
|
|
156
|
+
new StreamableHTTPClientTransport(serverUrl, { authProvider }),
|
|
157
|
+
);
|
|
158
|
+
} else throw error;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
await connectWithOAuthRetry();
|
|
150
163
|
```
|
|
151
164
|
|
|
152
165
|
#### Token Storage Options
|
|
@@ -275,7 +288,7 @@ class OAuthError extends Error {
|
|
|
275
288
|
|
|
276
289
|
### `browserAuth(options)`
|
|
277
290
|
|
|
278
|
-
Available from `oauth-callback/mcp`. Creates an MCP SDK-compatible OAuth provider for browser-based flows. Handles Dynamic Client Registration (DCR)
|
|
291
|
+
Available from `oauth-callback/mcp`. Creates an MCP SDK-compatible OAuth provider for browser-based flows. Handles Dynamic Client Registration (DCR) and token storage. Expired tokens trigger re-authentication.
|
|
279
292
|
|
|
280
293
|
#### Parameters
|
|
281
294
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type BrowserAuthOptions } from "../mcp-types";
|
|
2
2
|
import type { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
3
3
|
/**
|
|
4
4
|
* Factory for MCP SDK-compatible OAuth provider using browser flow.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-auth.d.ts","sourceRoot":"","sources":["../../src/auth/browser-auth.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"browser-auth.d.ts","sourceRoot":"","sources":["../../src/auth/browser-auth.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,kBAAkB,EAKxB,MAAM,cAAc,CAAC;AAItB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAYpF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,OAAO,GAAE,kBAAuB,GAC/B,mBAAmB,CAErB"}
|