oauth-callback 1.2.0 β 1.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/README.md +26 -38
- package/dist/error.test.d.ts +2 -0
- package/dist/error.test.d.ts.map +1 -0
- package/dist/index.js +310 -389
- package/dist/mcp.js +310 -389
- package/dist/server.d.ts +6 -6
- package/dist/server.d.ts.map +1 -1
- package/package.json +21 -10
- package/src/error.test.ts +204 -0
- package/src/server.ts +190 -450
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://npmjs.com/package/oauth-callback)
|
|
5
5
|
[](https://github.com/kriasoft/oauth-callback/blob/main/LICENSE)
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://replit.com/@kriasoft/oauth-callback)
|
|
7
8
|
|
|
8
9
|
A lightweight OAuth 2.0 callback handler for Node.js, Deno, and Bun with built-in browser flow and MCP SDK integration. Perfect for CLI tools, desktop applications, and development environments that need to capture OAuth authorization codes.
|
|
9
10
|
|
|
@@ -16,7 +17,7 @@ A lightweight OAuth 2.0 callback handler for Node.js, Deno, and Bun with built-i
|
|
|
16
17
|
- π **Multi-runtime support** - Works with Node.js 18+, Deno, and Bun
|
|
17
18
|
- π **Secure localhost-only server** for OAuth callbacks
|
|
18
19
|
- π€ **MCP SDK integration** - Built-in OAuth provider for Model Context Protocol
|
|
19
|
-
- β‘ **
|
|
20
|
+
- β‘ **Single dependency** - Only requires `open` for browser launching
|
|
20
21
|
- π― **TypeScript support** out of the box
|
|
21
22
|
- π‘οΈ **Comprehensive OAuth error handling** with detailed error classes
|
|
22
23
|
- π **Automatic server cleanup** after callback
|
|
@@ -106,34 +107,6 @@ const result = await getAuthCode({
|
|
|
106
107
|
});
|
|
107
108
|
```
|
|
108
109
|
|
|
109
|
-
### Handling Different OAuth Providers
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
// Google OAuth
|
|
113
|
-
const googleAuth = await getAuthCode(
|
|
114
|
-
"https://accounts.google.com/o/oauth2/v2/auth?" +
|
|
115
|
-
new URLSearchParams({
|
|
116
|
-
client_id: process.env.GOOGLE_CLIENT_ID,
|
|
117
|
-
redirect_uri: "http://localhost:3000/callback",
|
|
118
|
-
response_type: "code",
|
|
119
|
-
scope: "openid email profile",
|
|
120
|
-
access_type: "offline",
|
|
121
|
-
}),
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
// Microsoft OAuth
|
|
125
|
-
const microsoftAuth = await getAuthCode(
|
|
126
|
-
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize?" +
|
|
127
|
-
new URLSearchParams({
|
|
128
|
-
client_id: process.env.MICROSOFT_CLIENT_ID,
|
|
129
|
-
redirect_uri: "http://localhost:3000/callback",
|
|
130
|
-
response_type: "code",
|
|
131
|
-
scope: "user.read",
|
|
132
|
-
response_mode: "query",
|
|
133
|
-
}),
|
|
134
|
-
);
|
|
135
|
-
```
|
|
136
|
-
|
|
137
110
|
### MCP SDK Integration
|
|
138
111
|
|
|
139
112
|
The `browserAuth()` function provides a drop-in OAuth provider for the Model Context Protocol SDK:
|
|
@@ -327,18 +300,30 @@ TokenStore implementation for persistent token storage.
|
|
|
327
300
|
|
|
328
301
|
## How It Works
|
|
329
302
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
303
|
+
```
|
|
304
|
+
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
|
|
305
|
+
β Your App ββββββΆβLocal Server ββββββΆβ Browser ββββββΆβOAuth Server β
|
|
306
|
+
β β β :3000 β β β β β
|
|
307
|
+
β getAuthCode β β βββββββ Callback βββββββ Redirect β
|
|
308
|
+
β βΌ βββββββ Returns β β /callback β β with code β
|
|
309
|
+
β {code} β β auth code β β β β β
|
|
310
|
+
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
1. **Server Creation** β Spins up a temporary localhost HTTP server
|
|
314
|
+
2. **Browser Launch** β Opens the authorization URL in the default browser
|
|
315
|
+
3. **User Authorization** β User grants permission on the OAuth provider's page
|
|
316
|
+
4. **Callback Capture** β Provider redirects to localhost with the authorization code
|
|
317
|
+
5. **Cleanup** β Server closes automatically, code is returned to your app
|
|
335
318
|
|
|
336
319
|
## Security Considerations
|
|
337
320
|
|
|
338
|
-
-
|
|
339
|
-
-
|
|
340
|
-
- No
|
|
341
|
-
- State parameter
|
|
321
|
+
- **Localhost-only binding** β Server rejects non-local connections
|
|
322
|
+
- **Ephemeral server** β Shuts down immediately after receiving the callback
|
|
323
|
+
- **No credential logging** β Tokens and codes are never written to logs
|
|
324
|
+
- **State parameter support** β Pass and validate state to prevent CSRF attacks
|
|
325
|
+
- **Configurable timeouts** β Server auto-terminates if callback isn't received
|
|
326
|
+
- **PKCE compatible** β Works with authorization servers that require PKCE
|
|
342
327
|
|
|
343
328
|
## Running the Examples
|
|
344
329
|
|
|
@@ -413,6 +398,9 @@ bun test
|
|
|
413
398
|
# Build
|
|
414
399
|
bun run build
|
|
415
400
|
|
|
401
|
+
# Run documentation locally
|
|
402
|
+
bun run docs:dev # Start VitePress dev server at http://localhost:5173
|
|
403
|
+
|
|
416
404
|
# Run examples
|
|
417
405
|
bun run example:demo # Interactive demo
|
|
418
406
|
bun run example:github # GitHub OAuth example
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.test.d.ts","sourceRoot":"","sources":["../src/error.test.ts"],"names":[],"mappings":""}
|