oauth-callback 1.2.4 → 2.0.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 +33 -19
- package/dist/auth/browser-auth.d.ts +3 -1
- package/dist/auth/browser-auth.d.ts.map +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +66 -720
- package/dist/mcp-types.d.ts +3 -2
- package/dist/mcp-types.d.ts.map +1 -1
- package/dist/mcp.js +67 -720
- package/dist/server.d.ts.map +1 -1
- package/dist/types.d.ts +14 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +13 -11
- package/src/auth/browser-auth.ts +56 -116
- package/src/index.ts +13 -28
- package/src/mcp-types.ts +4 -4
- package/src/server.ts +25 -31
- package/src/types.ts +14 -5
package/README.md
CHANGED
|
@@ -31,33 +31,38 @@ A lightweight OAuth 2.0 callback handler for Node.js, Deno, and Bun with built-i
|
|
|
31
31
|
## Installation
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
-
bun add oauth-callback
|
|
34
|
+
bun add oauth-callback open
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
Or with npm:
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
|
-
npm install oauth-callback
|
|
40
|
+
npm install oauth-callback open
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
> **Note:** The `open` package is optional but recommended for browser launching. If using pnpm, install it explicitly: `pnpm add open`
|
|
44
|
+
|
|
43
45
|
## Quick Start
|
|
44
46
|
|
|
45
47
|
```typescript
|
|
48
|
+
import open from "open";
|
|
46
49
|
import { getAuthCode, OAuthError } from "oauth-callback";
|
|
47
50
|
|
|
48
|
-
// Simple usage
|
|
49
|
-
const result = await getAuthCode(
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
// Simple usage - pass `open` to launch browser
|
|
52
|
+
const result = await getAuthCode({
|
|
53
|
+
authorizationUrl:
|
|
54
|
+
"https://example.com/oauth/authorize?client_id=xxx&redirect_uri=http://localhost:3000/callback",
|
|
55
|
+
launch: open,
|
|
56
|
+
});
|
|
52
57
|
console.log("Authorization code:", result.code);
|
|
53
58
|
|
|
54
59
|
// MCP SDK integration - use specific import
|
|
55
60
|
import { browserAuth, fileStore } from "oauth-callback/mcp";
|
|
56
|
-
const authProvider = browserAuth({ store: fileStore() });
|
|
61
|
+
const authProvider = browserAuth({ launch: open, store: fileStore() });
|
|
57
62
|
|
|
58
63
|
// Or via namespace import
|
|
59
64
|
import { mcp } from "oauth-callback";
|
|
60
|
-
const authProvider = mcp.browserAuth({ store: mcp.fileStore() });
|
|
65
|
+
const authProvider = mcp.browserAuth({ launch: open, store: mcp.fileStore() });
|
|
61
66
|
```
|
|
62
67
|
|
|
63
68
|
## Usage Examples
|
|
@@ -65,6 +70,7 @@ const authProvider = mcp.browserAuth({ store: mcp.fileStore() });
|
|
|
65
70
|
### Basic OAuth Flow
|
|
66
71
|
|
|
67
72
|
```typescript
|
|
73
|
+
import open from "open";
|
|
68
74
|
import { getAuthCode, OAuthError } from "oauth-callback";
|
|
69
75
|
|
|
70
76
|
async function authenticate() {
|
|
@@ -78,7 +84,10 @@ async function authenticate() {
|
|
|
78
84
|
});
|
|
79
85
|
|
|
80
86
|
try {
|
|
81
|
-
const result = await getAuthCode(
|
|
87
|
+
const result = await getAuthCode({
|
|
88
|
+
authorizationUrl: authUrl,
|
|
89
|
+
launch: open,
|
|
90
|
+
});
|
|
82
91
|
console.log("Authorization code:", result.code);
|
|
83
92
|
console.log("State:", result.state);
|
|
84
93
|
|
|
@@ -98,10 +107,12 @@ async function authenticate() {
|
|
|
98
107
|
### Custom Port Configuration
|
|
99
108
|
|
|
100
109
|
```typescript
|
|
110
|
+
import open from "open";
|
|
101
111
|
import { getAuthCode } from "oauth-callback";
|
|
102
112
|
|
|
103
113
|
const result = await getAuthCode({
|
|
104
114
|
authorizationUrl: authUrl,
|
|
115
|
+
launch: open,
|
|
105
116
|
port: 8080, // Use custom port (default: 3000)
|
|
106
117
|
timeout: 60000, // Custom timeout in ms (default: 30000)
|
|
107
118
|
});
|
|
@@ -175,9 +186,12 @@ const authProvider = browserAuth({
|
|
|
175
186
|
### Advanced Usage
|
|
176
187
|
|
|
177
188
|
```typescript
|
|
189
|
+
import open from "open";
|
|
190
|
+
|
|
178
191
|
// With custom HTML templates and logging
|
|
179
192
|
const result = await getAuthCode({
|
|
180
193
|
authorizationUrl: authUrl,
|
|
194
|
+
launch: open,
|
|
181
195
|
port: 3000,
|
|
182
196
|
hostname: "127.0.0.1", // Bind to specific IP
|
|
183
197
|
successHtml: "<h1>Success! You can close this window.</h1>",
|
|
@@ -209,7 +223,7 @@ try {
|
|
|
209
223
|
|
|
210
224
|
### `getAuthCode(input)`
|
|
211
225
|
|
|
212
|
-
Starts a local HTTP server
|
|
226
|
+
Starts a local HTTP server to capture OAuth callbacks. Optionally launches the authorization URL via the `launch` callback.
|
|
213
227
|
|
|
214
228
|
#### Parameters
|
|
215
229
|
|
|
@@ -219,7 +233,7 @@ Starts a local HTTP server and opens the authorization URL in the user's browser
|
|
|
219
233
|
- `hostname` (string): Hostname to bind the server to (default: "localhost")
|
|
220
234
|
- `callbackPath` (string): URL path for the OAuth callback (default: "/callback")
|
|
221
235
|
- `timeout` (number): Timeout in milliseconds (default: 30000)
|
|
222
|
-
- `
|
|
236
|
+
- `launch` (function): Optional callback to launch the authorization URL (e.g., `open`)
|
|
223
237
|
- `successHtml` (string): Custom HTML to display on successful authorization
|
|
224
238
|
- `errorHtml` (string): Custom HTML to display on authorization error
|
|
225
239
|
- `signal` (AbortSignal): AbortSignal for cancellation support
|
|
@@ -311,7 +325,7 @@ TokenStore implementation for persistent token storage.
|
|
|
311
325
|
```
|
|
312
326
|
|
|
313
327
|
1. **Server Creation** — Spins up a temporary localhost HTTP server
|
|
314
|
-
2. **Browser Launch** — Opens the authorization URL
|
|
328
|
+
2. **Browser Launch** — Opens the authorization URL (if `launch` callback provided)
|
|
315
329
|
3. **User Authorization** — User grants permission on the OAuth provider's page
|
|
316
330
|
4. **Callback Capture** — Provider redirects to localhost with the authorization code
|
|
317
331
|
5. **Cleanup** — Server closes automatically, code is returned to your app
|
|
@@ -420,7 +434,11 @@ bun run example:notion # Notion MCP example with Dynamic Client Registration
|
|
|
420
434
|
If port 3000 is already in use, specify a different port:
|
|
421
435
|
|
|
422
436
|
```typescript
|
|
423
|
-
const result = await getAuthCode({
|
|
437
|
+
const result = await getAuthCode({
|
|
438
|
+
authorizationUrl: authUrl,
|
|
439
|
+
launch: open,
|
|
440
|
+
port: 8080,
|
|
441
|
+
});
|
|
424
442
|
```
|
|
425
443
|
|
|
426
444
|
### Firewall Warnings
|
|
@@ -433,13 +451,9 @@ If the browser doesn't open automatically, manually navigate to the authorizatio
|
|
|
433
451
|
|
|
434
452
|
## Contributing
|
|
435
453
|
|
|
436
|
-
Contributions are welcome!
|
|
454
|
+
Contributions are welcome! See [CONTRIBUTING.md](.github/CONTRIBUTING.md) for setup instructions.
|
|
437
455
|
|
|
438
|
-
|
|
439
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
440
|
-
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
441
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
442
|
-
5. Open a Pull Request
|
|
456
|
+
**Maintainers wanted** — we're looking for people to help maintain this project. If interested, reach out on [Discord](https://discord.gg/bSsv7XM) or open an issue.
|
|
443
457
|
|
|
444
458
|
## License
|
|
445
459
|
|
|
@@ -8,9 +8,11 @@ import type { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.
|
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```typescript
|
|
11
|
+
* import open from "open";
|
|
12
|
+
*
|
|
11
13
|
* const transport = new StreamableHTTPClientTransport(
|
|
12
14
|
* new URL("https://mcp.notion.com/mcp"),
|
|
13
|
-
* { authProvider: browserAuth() }
|
|
15
|
+
* { authProvider: browserAuth({ launch: open }) }
|
|
14
16
|
* );
|
|
15
17
|
* ```
|
|
16
18
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-auth.d.ts","sourceRoot":"","sources":["../../src/auth/browser-auth.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,kBAAkB,EAMnB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"browser-auth.d.ts","sourceRoot":"","sources":["../../src/auth/browser-auth.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,kBAAkB,EAMnB,MAAM,cAAc,CAAC;AAItB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAQpF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,OAAO,GAAE,kBAAuB,GAC/B,mBAAmB,CAErB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type CallbackResult } from "./server";
|
|
2
2
|
import type { GetAuthCodeOptions } from "./types";
|
|
3
3
|
export type { CallbackResult, CallbackServer, ServerOptions } from "./server";
|
|
4
|
-
export { OAuthError } from "./errors";
|
|
4
|
+
export { OAuthError, TimeoutError } from "./errors";
|
|
5
5
|
export type { GetAuthCodeOptions } from "./types";
|
|
6
6
|
export { inMemoryStore } from "./storage/memory";
|
|
7
7
|
export { fileStore } from "./storage/file";
|
|
@@ -9,7 +9,7 @@ import * as mcp from "./mcp";
|
|
|
9
9
|
export { mcp };
|
|
10
10
|
/**
|
|
11
11
|
* Captures OAuth authorization code via localhost callback.
|
|
12
|
-
*
|
|
12
|
+
* Starts a temporary server, optionally launches auth URL, waits for redirect.
|
|
13
13
|
*
|
|
14
14
|
* @param input - Auth URL string or GetAuthCodeOptions with config
|
|
15
15
|
* @returns Promise<CallbackResult> with code and params
|
|
@@ -18,17 +18,18 @@ export { mcp };
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```typescript
|
|
21
|
-
*
|
|
22
|
-
* const result = await getAuthCode('https://oauth.example.com/authorize?...');
|
|
23
|
-
* console.log('Code:', result.code);
|
|
21
|
+
* import open from "open";
|
|
24
22
|
*
|
|
25
|
-
* //
|
|
23
|
+
* // With browser launch
|
|
26
24
|
* const result = await getAuthCode({
|
|
27
25
|
* authorizationUrl: 'https://oauth.example.com/authorize?...',
|
|
28
|
-
*
|
|
29
|
-
* timeout: 60000,
|
|
30
|
-
* onRequest: (req) => console.log('Request:', req.url)
|
|
26
|
+
* launch: open,
|
|
31
27
|
* });
|
|
28
|
+
*
|
|
29
|
+
* // Headless (print URL, let user open manually)
|
|
30
|
+
* const url = 'https://oauth.example.com/authorize?...';
|
|
31
|
+
* console.log('Open:', url);
|
|
32
|
+
* const result = await getAuthCode({ authorizationUrl: url });
|
|
32
33
|
* ```
|
|
33
34
|
*/
|
|
34
35
|
export declare function getAuthCode(input: GetAuthCodeOptions | string): Promise<CallbackResult>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,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,YAAY,EAAE,MAAM,UAAU,CAAC;AACpD,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;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,kBAAkB,GAAG,MAAM,GACjC,OAAO,CAAC,cAAc,CAAC,CA+CzB"}
|