@leanmcp/auth 0.3.1 → 0.4.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.
@@ -0,0 +1,181 @@
1
+ import { T as TokenStorage, O as OAuthTokens, C as ClientRegistration, S as StoredSession } from '../types-DMpGN530.mjs';
2
+ export { i as isTokenExpired, w as withExpiresAt } from '../types-DMpGN530.mjs';
3
+
4
+ /**
5
+ * In-memory token storage
6
+ *
7
+ * Fast, simple storage for development and short-lived sessions.
8
+ * Tokens are lost when the process exits.
9
+ */
10
+
11
+ /**
12
+ * In-memory token storage implementation
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const storage = new MemoryStorage();
17
+ * await storage.setTokens('https://mcp.example.com', tokens);
18
+ * ```
19
+ */
20
+ declare class MemoryStorage implements TokenStorage {
21
+ private tokens;
22
+ private clients;
23
+ /**
24
+ * Normalize server URL for consistent key lookup
25
+ */
26
+ private normalizeUrl;
27
+ /**
28
+ * Check if an entry is expired
29
+ */
30
+ private isExpired;
31
+ getTokens(serverUrl: string): Promise<OAuthTokens | null>;
32
+ setTokens(serverUrl: string, tokens: OAuthTokens): Promise<void>;
33
+ clearTokens(serverUrl: string): Promise<void>;
34
+ getClientInfo(serverUrl: string): Promise<ClientRegistration | null>;
35
+ setClientInfo(serverUrl: string, info: ClientRegistration): Promise<void>;
36
+ clearClientInfo(serverUrl: string): Promise<void>;
37
+ clearAll(): Promise<void>;
38
+ getAllSessions(): Promise<StoredSession[]>;
39
+ }
40
+
41
+ /**
42
+ * File-based token storage
43
+ *
44
+ * Persists tokens to a JSON file for survival across restarts.
45
+ * Optionally encrypts tokens for security.
46
+ */
47
+
48
+ interface FileStorageOptions {
49
+ /** Path to the storage file */
50
+ filePath: string;
51
+ /** Optional encryption key (if omitted, data stored in plaintext) */
52
+ encryptionKey?: string;
53
+ /** Whether to pretty-print JSON (default: false) */
54
+ prettyPrint?: boolean;
55
+ }
56
+ /**
57
+ * File-based token storage with optional encryption
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * // Plaintext storage
62
+ * const storage = new FileStorage({ filePath: '~/.leanmcp/tokens.json' });
63
+ *
64
+ * // Encrypted storage
65
+ * const storage = new FileStorage({
66
+ * filePath: '~/.leanmcp/tokens.enc',
67
+ * encryptionKey: process.env.TOKEN_ENCRYPTION_KEY
68
+ * });
69
+ * ```
70
+ */
71
+ declare class FileStorage implements TokenStorage {
72
+ private filePath;
73
+ private encryptionKey?;
74
+ private prettyPrint;
75
+ private cache;
76
+ private writePromise;
77
+ constructor(options: FileStorageOptions | string);
78
+ /**
79
+ * Expand ~ to home directory
80
+ */
81
+ private expandPath;
82
+ /**
83
+ * Normalize server URL for consistent key lookup
84
+ */
85
+ private normalizeUrl;
86
+ /**
87
+ * Encrypt data
88
+ */
89
+ private encrypt;
90
+ /**
91
+ * Decrypt data
92
+ */
93
+ private decrypt;
94
+ /**
95
+ * Read data from file
96
+ */
97
+ private readFile;
98
+ /**
99
+ * Write data to file (coalesced to avoid race conditions)
100
+ */
101
+ private writeFile;
102
+ getTokens(serverUrl: string): Promise<OAuthTokens | null>;
103
+ setTokens(serverUrl: string, tokens: OAuthTokens): Promise<void>;
104
+ clearTokens(serverUrl: string): Promise<void>;
105
+ getClientInfo(serverUrl: string): Promise<ClientRegistration | null>;
106
+ setClientInfo(serverUrl: string, info: ClientRegistration): Promise<void>;
107
+ clearClientInfo(serverUrl: string): Promise<void>;
108
+ clearAll(): Promise<void>;
109
+ getAllSessions(): Promise<StoredSession[]>;
110
+ }
111
+
112
+ /**
113
+ * OS Keychain Token Storage
114
+ *
115
+ * Secure storage using the operating system's credential manager:
116
+ * - macOS: Keychain
117
+ * - Windows: Credential Vault
118
+ * - Linux: libsecret (GNOME Keyring, KWallet, etc.)
119
+ *
120
+ * Requires the optional 'keytar' peer dependency.
121
+ */
122
+
123
+ /**
124
+ * Keychain storage options
125
+ */
126
+ interface KeychainStorageOptions {
127
+ /** Custom service name (default: 'leanmcp-auth') */
128
+ serviceName?: string;
129
+ }
130
+ /**
131
+ * OS Keychain-based token storage
132
+ *
133
+ * Uses the operating system's secure credential storage for maximum security.
134
+ * Tokens are encrypted at rest by the OS.
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * import { KeychainStorage } from '@leanmcp/auth/storage';
139
+ *
140
+ * // Requires 'keytar' to be installed
141
+ * const storage = new KeychainStorage();
142
+ *
143
+ * await storage.setTokens('https://mcp.example.com', tokens);
144
+ * ```
145
+ */
146
+ declare class KeychainStorage implements TokenStorage {
147
+ private serviceName;
148
+ private keytar;
149
+ private initPromise;
150
+ constructor(options?: KeychainStorageOptions);
151
+ /**
152
+ * Initialize keytar (lazy load)
153
+ */
154
+ private init;
155
+ /**
156
+ * Normalize server URL for consistent key lookup
157
+ */
158
+ private normalizeUrl;
159
+ /**
160
+ * Get account key for tokens
161
+ */
162
+ private getTokensAccount;
163
+ /**
164
+ * Get account key for client info
165
+ */
166
+ private getClientAccount;
167
+ getTokens(serverUrl: string): Promise<OAuthTokens | null>;
168
+ setTokens(serverUrl: string, tokens: OAuthTokens): Promise<void>;
169
+ clearTokens(serverUrl: string): Promise<void>;
170
+ getClientInfo(serverUrl: string): Promise<ClientRegistration | null>;
171
+ setClientInfo(serverUrl: string, info: ClientRegistration): Promise<void>;
172
+ clearClientInfo(serverUrl: string): Promise<void>;
173
+ clearAll(): Promise<void>;
174
+ getAllSessions(): Promise<StoredSession[]>;
175
+ }
176
+ /**
177
+ * Check if keychain storage is available
178
+ */
179
+ declare function isKeychainAvailable(): Promise<boolean>;
180
+
181
+ export { ClientRegistration, FileStorage, KeychainStorage, type KeychainStorageOptions, MemoryStorage, OAuthTokens, StoredSession, TokenStorage, isKeychainAvailable };
@@ -0,0 +1,181 @@
1
+ import { T as TokenStorage, O as OAuthTokens, C as ClientRegistration, S as StoredSession } from '../types-DMpGN530.js';
2
+ export { i as isTokenExpired, w as withExpiresAt } from '../types-DMpGN530.js';
3
+
4
+ /**
5
+ * In-memory token storage
6
+ *
7
+ * Fast, simple storage for development and short-lived sessions.
8
+ * Tokens are lost when the process exits.
9
+ */
10
+
11
+ /**
12
+ * In-memory token storage implementation
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const storage = new MemoryStorage();
17
+ * await storage.setTokens('https://mcp.example.com', tokens);
18
+ * ```
19
+ */
20
+ declare class MemoryStorage implements TokenStorage {
21
+ private tokens;
22
+ private clients;
23
+ /**
24
+ * Normalize server URL for consistent key lookup
25
+ */
26
+ private normalizeUrl;
27
+ /**
28
+ * Check if an entry is expired
29
+ */
30
+ private isExpired;
31
+ getTokens(serverUrl: string): Promise<OAuthTokens | null>;
32
+ setTokens(serverUrl: string, tokens: OAuthTokens): Promise<void>;
33
+ clearTokens(serverUrl: string): Promise<void>;
34
+ getClientInfo(serverUrl: string): Promise<ClientRegistration | null>;
35
+ setClientInfo(serverUrl: string, info: ClientRegistration): Promise<void>;
36
+ clearClientInfo(serverUrl: string): Promise<void>;
37
+ clearAll(): Promise<void>;
38
+ getAllSessions(): Promise<StoredSession[]>;
39
+ }
40
+
41
+ /**
42
+ * File-based token storage
43
+ *
44
+ * Persists tokens to a JSON file for survival across restarts.
45
+ * Optionally encrypts tokens for security.
46
+ */
47
+
48
+ interface FileStorageOptions {
49
+ /** Path to the storage file */
50
+ filePath: string;
51
+ /** Optional encryption key (if omitted, data stored in plaintext) */
52
+ encryptionKey?: string;
53
+ /** Whether to pretty-print JSON (default: false) */
54
+ prettyPrint?: boolean;
55
+ }
56
+ /**
57
+ * File-based token storage with optional encryption
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * // Plaintext storage
62
+ * const storage = new FileStorage({ filePath: '~/.leanmcp/tokens.json' });
63
+ *
64
+ * // Encrypted storage
65
+ * const storage = new FileStorage({
66
+ * filePath: '~/.leanmcp/tokens.enc',
67
+ * encryptionKey: process.env.TOKEN_ENCRYPTION_KEY
68
+ * });
69
+ * ```
70
+ */
71
+ declare class FileStorage implements TokenStorage {
72
+ private filePath;
73
+ private encryptionKey?;
74
+ private prettyPrint;
75
+ private cache;
76
+ private writePromise;
77
+ constructor(options: FileStorageOptions | string);
78
+ /**
79
+ * Expand ~ to home directory
80
+ */
81
+ private expandPath;
82
+ /**
83
+ * Normalize server URL for consistent key lookup
84
+ */
85
+ private normalizeUrl;
86
+ /**
87
+ * Encrypt data
88
+ */
89
+ private encrypt;
90
+ /**
91
+ * Decrypt data
92
+ */
93
+ private decrypt;
94
+ /**
95
+ * Read data from file
96
+ */
97
+ private readFile;
98
+ /**
99
+ * Write data to file (coalesced to avoid race conditions)
100
+ */
101
+ private writeFile;
102
+ getTokens(serverUrl: string): Promise<OAuthTokens | null>;
103
+ setTokens(serverUrl: string, tokens: OAuthTokens): Promise<void>;
104
+ clearTokens(serverUrl: string): Promise<void>;
105
+ getClientInfo(serverUrl: string): Promise<ClientRegistration | null>;
106
+ setClientInfo(serverUrl: string, info: ClientRegistration): Promise<void>;
107
+ clearClientInfo(serverUrl: string): Promise<void>;
108
+ clearAll(): Promise<void>;
109
+ getAllSessions(): Promise<StoredSession[]>;
110
+ }
111
+
112
+ /**
113
+ * OS Keychain Token Storage
114
+ *
115
+ * Secure storage using the operating system's credential manager:
116
+ * - macOS: Keychain
117
+ * - Windows: Credential Vault
118
+ * - Linux: libsecret (GNOME Keyring, KWallet, etc.)
119
+ *
120
+ * Requires the optional 'keytar' peer dependency.
121
+ */
122
+
123
+ /**
124
+ * Keychain storage options
125
+ */
126
+ interface KeychainStorageOptions {
127
+ /** Custom service name (default: 'leanmcp-auth') */
128
+ serviceName?: string;
129
+ }
130
+ /**
131
+ * OS Keychain-based token storage
132
+ *
133
+ * Uses the operating system's secure credential storage for maximum security.
134
+ * Tokens are encrypted at rest by the OS.
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * import { KeychainStorage } from '@leanmcp/auth/storage';
139
+ *
140
+ * // Requires 'keytar' to be installed
141
+ * const storage = new KeychainStorage();
142
+ *
143
+ * await storage.setTokens('https://mcp.example.com', tokens);
144
+ * ```
145
+ */
146
+ declare class KeychainStorage implements TokenStorage {
147
+ private serviceName;
148
+ private keytar;
149
+ private initPromise;
150
+ constructor(options?: KeychainStorageOptions);
151
+ /**
152
+ * Initialize keytar (lazy load)
153
+ */
154
+ private init;
155
+ /**
156
+ * Normalize server URL for consistent key lookup
157
+ */
158
+ private normalizeUrl;
159
+ /**
160
+ * Get account key for tokens
161
+ */
162
+ private getTokensAccount;
163
+ /**
164
+ * Get account key for client info
165
+ */
166
+ private getClientAccount;
167
+ getTokens(serverUrl: string): Promise<OAuthTokens | null>;
168
+ setTokens(serverUrl: string, tokens: OAuthTokens): Promise<void>;
169
+ clearTokens(serverUrl: string): Promise<void>;
170
+ getClientInfo(serverUrl: string): Promise<ClientRegistration | null>;
171
+ setClientInfo(serverUrl: string, info: ClientRegistration): Promise<void>;
172
+ clearClientInfo(serverUrl: string): Promise<void>;
173
+ clearAll(): Promise<void>;
174
+ getAllSessions(): Promise<StoredSession[]>;
175
+ }
176
+ /**
177
+ * Check if keychain storage is available
178
+ */
179
+ declare function isKeychainAvailable(): Promise<boolean>;
180
+
181
+ export { ClientRegistration, FileStorage, KeychainStorage, type KeychainStorageOptions, MemoryStorage, OAuthTokens, StoredSession, TokenStorage, isKeychainAvailable };