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 CHANGED
@@ -4,6 +4,7 @@
4
4
  [![npm downloads](https://img.shields.io/npm/dm/oauth-callback.svg)](https://npmjs.com/package/oauth-callback)
5
5
  [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/kriasoft/oauth-callback/blob/main/LICENSE)
6
6
  [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
7
+ [![Run on Replit](https://img.shields.io/badge/Run%20on-Replit-orange.svg)](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
- - ⚑ **Minimal dependencies** - Only requires `open` package
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
- 1. **Server Creation**: Creates a temporary HTTP server on the specified port
331
- 2. **Browser Launch**: Opens the authorization URL in the user's default browser
332
- 3. **Callback Handling**: Waits for the OAuth provider to redirect back with the authorization code
333
- 4. **Cleanup**: Automatically closes the server after receiving the callback
334
- 5. **Result**: Returns the authorization code and any additional parameters
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
- - The server only accepts connections from localhost
339
- - Server is closed immediately after receiving the callback
340
- - No data is stored persistently
341
- - State parameter validation should be implemented by the application
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=error.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.test.d.ts","sourceRoot":"","sources":["../src/error.test.ts"],"names":[],"mappings":""}