oauth-callback 2.0.0 → 2.1.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 +6 -0
- package/dist/index.d.ts +29 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +668 -9
- package/dist/mcp.js +668 -9
- package/dist/types.d.ts +36 -21
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/auth/browser-auth.ts +13 -4
- package/src/index.ts +55 -11
- package/src/types.ts +41 -23
package/README.md
CHANGED
|
@@ -131,6 +131,7 @@ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/
|
|
|
131
131
|
const authProvider = browserAuth({
|
|
132
132
|
port: 3000,
|
|
133
133
|
scope: "read write",
|
|
134
|
+
launch: open, // Opens browser for OAuth consent
|
|
134
135
|
store: inMemoryStore(), // Or fileStore() for persistence
|
|
135
136
|
});
|
|
136
137
|
|
|
@@ -155,17 +156,20 @@ import { browserAuth, inMemoryStore, fileStore } from "oauth-callback/mcp";
|
|
|
155
156
|
|
|
156
157
|
// Ephemeral storage (tokens lost on restart)
|
|
157
158
|
const ephemeralAuth = browserAuth({
|
|
159
|
+
launch: open,
|
|
158
160
|
store: inMemoryStore(),
|
|
159
161
|
});
|
|
160
162
|
|
|
161
163
|
// Persistent file storage (default: ~/.mcp/tokens.json)
|
|
162
164
|
const persistentAuth = browserAuth({
|
|
165
|
+
launch: open,
|
|
163
166
|
store: fileStore(),
|
|
164
167
|
storeKey: "my-app-tokens", // Namespace for multiple apps
|
|
165
168
|
});
|
|
166
169
|
|
|
167
170
|
// Custom file location
|
|
168
171
|
const customAuth = browserAuth({
|
|
172
|
+
launch: open,
|
|
169
173
|
store: fileStore("/path/to/tokens.json"),
|
|
170
174
|
});
|
|
171
175
|
```
|
|
@@ -179,6 +183,7 @@ const authProvider = browserAuth({
|
|
|
179
183
|
clientId: "your-client-id",
|
|
180
184
|
clientSecret: "your-client-secret",
|
|
181
185
|
scope: "read write",
|
|
186
|
+
launch: open, // Opens browser for OAuth consent
|
|
182
187
|
store: fileStore(), // Persist tokens across sessions
|
|
183
188
|
});
|
|
184
189
|
```
|
|
@@ -283,6 +288,7 @@ Available from `oauth-callback/mcp`. Creates an MCP SDK-compatible OAuth provide
|
|
|
283
288
|
- `clientSecret` (string): Pre-registered client secret (optional)
|
|
284
289
|
- `store` (TokenStore): Token storage implementation (default: inMemoryStore())
|
|
285
290
|
- `storeKey` (string): Storage key for tokens (default: "mcp-tokens")
|
|
291
|
+
- `launch` (function): Callback to launch auth URL (e.g., `open`)
|
|
286
292
|
- `authTimeout` (number): Authorization timeout in ms (default: 300000)
|
|
287
293
|
- `successHtml` (string): Custom success page HTML
|
|
288
294
|
- `errorHtml` (string): Custom error page HTML
|
package/dist/index.d.ts
CHANGED
|
@@ -7,11 +7,34 @@ export { inMemoryStore } from "./storage/memory";
|
|
|
7
7
|
export { fileStore } from "./storage/file";
|
|
8
8
|
import * as mcp from "./mcp";
|
|
9
9
|
export { mcp };
|
|
10
|
+
/**
|
|
11
|
+
* Builds the redirect URI for OAuth configuration.
|
|
12
|
+
* Use this to construct the redirect_uri parameter for your authorization URL.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const redirectUri = getRedirectUrl({ port: 3000 });
|
|
17
|
+
* // => "http://localhost:3000/callback"
|
|
18
|
+
*
|
|
19
|
+
* const authUrl = `https://oauth.example.com/authorize?redirect_uri=${encodeURIComponent(redirectUri)}`;
|
|
20
|
+
* console.log('Open:', authUrl);
|
|
21
|
+
* await getAuthCode({ port: 3000 });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function getRedirectUrl(options?: {
|
|
25
|
+
port?: number;
|
|
26
|
+
hostname?: string;
|
|
27
|
+
callbackPath?: string;
|
|
28
|
+
}): string;
|
|
10
29
|
/**
|
|
11
30
|
* Captures OAuth authorization code via localhost callback.
|
|
12
31
|
* Starts a temporary server, optionally launches auth URL, waits for redirect.
|
|
13
32
|
*
|
|
14
|
-
*
|
|
33
|
+
* Two modes:
|
|
34
|
+
* - **Managed**: Pass both `authorizationUrl` and `launch` — library opens browser
|
|
35
|
+
* - **Headless**: Pass neither — caller handles URL display (CI/SSH/custom UI)
|
|
36
|
+
*
|
|
37
|
+
* @param input - Auth URL string (auto-launches browser) or GetAuthCodeOptions
|
|
15
38
|
* @returns Promise<CallbackResult> with code and params
|
|
16
39
|
* @throws {OAuthError} Provider errors (access_denied, invalid_scope)
|
|
17
40
|
* @throws {Error} Timeout, network failures, port conflicts
|
|
@@ -20,16 +43,16 @@ export { mcp };
|
|
|
20
43
|
* ```typescript
|
|
21
44
|
* import open from "open";
|
|
22
45
|
*
|
|
23
|
-
* //
|
|
46
|
+
* // Managed mode: library launches browser
|
|
24
47
|
* const result = await getAuthCode({
|
|
25
48
|
* authorizationUrl: 'https://oauth.example.com/authorize?...',
|
|
26
49
|
* launch: open,
|
|
27
50
|
* });
|
|
28
51
|
*
|
|
29
|
-
* // Headless
|
|
30
|
-
* const
|
|
31
|
-
* console.log('Open:',
|
|
32
|
-
* const result = await getAuthCode({
|
|
52
|
+
* // Headless mode: caller handles URL display
|
|
53
|
+
* const authUrl = 'https://oauth.example.com/authorize?...';
|
|
54
|
+
* console.log('Open this URL:', authUrl);
|
|
55
|
+
* const result = await getAuthCode({ port: 3000, timeout: 60000 });
|
|
33
56
|
* ```
|
|
34
57
|
*/
|
|
35
58
|
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":"AASA,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,YAAY,EAAE,cAAc,EAAE,cAAc,EAA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