@mcp-z/oauth 1.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/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/cjs/account-utils.d.cts +107 -0
- package/dist/cjs/account-utils.d.ts +107 -0
- package/dist/cjs/account-utils.js +481 -0
- package/dist/cjs/account-utils.js.map +1 -0
- package/dist/cjs/index.d.cts +19 -0
- package/dist/cjs/index.d.ts +19 -0
- package/dist/cjs/index.js +149 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/jwt-auth.d.cts +53 -0
- package/dist/cjs/jwt-auth.d.ts +53 -0
- package/dist/cjs/jwt-auth.js +417 -0
- package/dist/cjs/jwt-auth.js.map +1 -0
- package/dist/cjs/key-utils.d.cts +131 -0
- package/dist/cjs/key-utils.d.ts +131 -0
- package/dist/cjs/key-utils.js +421 -0
- package/dist/cjs/key-utils.js.map +1 -0
- package/dist/cjs/lib/account-server/index.d.cts +45 -0
- package/dist/cjs/lib/account-server/index.d.ts +45 -0
- package/dist/cjs/lib/account-server/index.js +67 -0
- package/dist/cjs/lib/account-server/index.js.map +1 -0
- package/dist/cjs/lib/account-server/loopback.d.cts +22 -0
- package/dist/cjs/lib/account-server/loopback.d.ts +22 -0
- package/dist/cjs/lib/account-server/loopback.js +778 -0
- package/dist/cjs/lib/account-server/loopback.js.map +1 -0
- package/dist/cjs/lib/account-server/me.d.cts +23 -0
- package/dist/cjs/lib/account-server/me.d.ts +23 -0
- package/dist/cjs/lib/account-server/me.js +412 -0
- package/dist/cjs/lib/account-server/me.js.map +1 -0
- package/dist/cjs/lib/account-server/shared-utils.d.cts +6 -0
- package/dist/cjs/lib/account-server/shared-utils.d.ts +6 -0
- package/dist/cjs/lib/account-server/shared-utils.js +235 -0
- package/dist/cjs/lib/account-server/shared-utils.js.map +1 -0
- package/dist/cjs/lib/account-server/stateless.d.cts +20 -0
- package/dist/cjs/lib/account-server/stateless.d.ts +20 -0
- package/dist/cjs/lib/account-server/stateless.js +32 -0
- package/dist/cjs/lib/account-server/stateless.js.map +1 -0
- package/dist/cjs/lib/account-server/types.d.cts +32 -0
- package/dist/cjs/lib/account-server/types.d.ts +32 -0
- package/dist/cjs/lib/account-server/types.js +7 -0
- package/dist/cjs/lib/account-server/types.js.map +1 -0
- package/dist/cjs/lib/dcr-types.d.cts +126 -0
- package/dist/cjs/lib/dcr-types.d.ts +126 -0
- package/dist/cjs/lib/dcr-types.js +12 -0
- package/dist/cjs/lib/dcr-types.js.map +1 -0
- package/dist/cjs/lib/rfc-metadata-types.d.cts +46 -0
- package/dist/cjs/lib/rfc-metadata-types.d.ts +46 -0
- package/dist/cjs/lib/rfc-metadata-types.js +8 -0
- package/dist/cjs/lib/rfc-metadata-types.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pkce.d.cts +36 -0
- package/dist/cjs/pkce.d.ts +36 -0
- package/dist/cjs/pkce.js +25 -0
- package/dist/cjs/pkce.js.map +1 -0
- package/dist/cjs/sanitizer.d.cts +37 -0
- package/dist/cjs/sanitizer.d.ts +37 -0
- package/dist/cjs/sanitizer.js +407 -0
- package/dist/cjs/sanitizer.js.map +1 -0
- package/dist/cjs/schemas/index.d.cts +36 -0
- package/dist/cjs/schemas/index.d.ts +36 -0
- package/dist/cjs/schemas/index.js +28 -0
- package/dist/cjs/schemas/index.js.map +1 -0
- package/dist/cjs/session-auth.d.cts +79 -0
- package/dist/cjs/session-auth.d.ts +79 -0
- package/dist/cjs/session-auth.js +354 -0
- package/dist/cjs/session-auth.js.map +1 -0
- package/dist/cjs/templates.d.cts +18 -0
- package/dist/cjs/templates.d.ts +18 -0
- package/dist/cjs/templates.js +38 -0
- package/dist/cjs/templates.js.map +1 -0
- package/dist/cjs/types.d.cts +343 -0
- package/dist/cjs/types.d.ts +343 -0
- package/dist/cjs/types.js +210 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/account-utils.d.ts +107 -0
- package/dist/esm/account-utils.js +179 -0
- package/dist/esm/account-utils.js.map +1 -0
- package/dist/esm/index.d.ts +19 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/jwt-auth.d.ts +53 -0
- package/dist/esm/jwt-auth.js +164 -0
- package/dist/esm/jwt-auth.js.map +1 -0
- package/dist/esm/key-utils.d.ts +131 -0
- package/dist/esm/key-utils.js +143 -0
- package/dist/esm/key-utils.js.map +1 -0
- package/dist/esm/lib/account-server/index.d.ts +45 -0
- package/dist/esm/lib/account-server/index.js +41 -0
- package/dist/esm/lib/account-server/index.js.map +1 -0
- package/dist/esm/lib/account-server/loopback.d.ts +22 -0
- package/dist/esm/lib/account-server/loopback.js +372 -0
- package/dist/esm/lib/account-server/loopback.js.map +1 -0
- package/dist/esm/lib/account-server/me.d.ts +23 -0
- package/dist/esm/lib/account-server/me.js +170 -0
- package/dist/esm/lib/account-server/me.js.map +1 -0
- package/dist/esm/lib/account-server/shared-utils.d.ts +6 -0
- package/dist/esm/lib/account-server/shared-utils.js +24 -0
- package/dist/esm/lib/account-server/shared-utils.js.map +1 -0
- package/dist/esm/lib/account-server/stateless.d.ts +20 -0
- package/dist/esm/lib/account-server/stateless.js +25 -0
- package/dist/esm/lib/account-server/stateless.js.map +1 -0
- package/dist/esm/lib/account-server/types.d.ts +32 -0
- package/dist/esm/lib/account-server/types.js +6 -0
- package/dist/esm/lib/account-server/types.js.map +1 -0
- package/dist/esm/lib/dcr-types.d.ts +126 -0
- package/dist/esm/lib/dcr-types.js +13 -0
- package/dist/esm/lib/dcr-types.js.map +1 -0
- package/dist/esm/lib/rfc-metadata-types.d.ts +46 -0
- package/dist/esm/lib/rfc-metadata-types.js +7 -0
- package/dist/esm/lib/rfc-metadata-types.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/pkce.d.ts +36 -0
- package/dist/esm/pkce.js +33 -0
- package/dist/esm/pkce.js.map +1 -0
- package/dist/esm/sanitizer.d.ts +37 -0
- package/dist/esm/sanitizer.js +256 -0
- package/dist/esm/sanitizer.js.map +1 -0
- package/dist/esm/schemas/index.d.ts +36 -0
- package/dist/esm/schemas/index.js +19 -0
- package/dist/esm/schemas/index.js.map +1 -0
- package/dist/esm/session-auth.d.ts +79 -0
- package/dist/esm/session-auth.js +141 -0
- package/dist/esm/session-auth.js.map +1 -0
- package/dist/esm/templates.d.ts +18 -0
- package/dist/esm/templates.js +132 -0
- package/dist/esm/templates.js.map +1 -0
- package/dist/esm/types.d.ts +343 -0
- package/dist/esm/types.js +34 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for multi-account management and OAuth integration
|
|
3
|
+
*/ "use strict";
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
function _export(target, all) {
|
|
8
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
_export(exports, {
|
|
14
|
+
get AccountManagerError () {
|
|
15
|
+
return AccountManagerError;
|
|
16
|
+
},
|
|
17
|
+
get AccountNotFoundError () {
|
|
18
|
+
return AccountNotFoundError;
|
|
19
|
+
},
|
|
20
|
+
get AuthRequiredError () {
|
|
21
|
+
return AuthRequiredError;
|
|
22
|
+
},
|
|
23
|
+
get ConfigurationError () {
|
|
24
|
+
return ConfigurationError;
|
|
25
|
+
},
|
|
26
|
+
get RequiresAuthenticationError () {
|
|
27
|
+
return RequiresAuthenticationError;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
function _assert_this_initialized(self) {
|
|
31
|
+
if (self === void 0) {
|
|
32
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
33
|
+
}
|
|
34
|
+
return self;
|
|
35
|
+
}
|
|
36
|
+
function _call_super(_this, derived, args) {
|
|
37
|
+
derived = _get_prototype_of(derived);
|
|
38
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
39
|
+
}
|
|
40
|
+
function _class_call_check(instance, Constructor) {
|
|
41
|
+
if (!(instance instanceof Constructor)) {
|
|
42
|
+
throw new TypeError("Cannot call a class as a function");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function _construct(Parent, args, Class) {
|
|
46
|
+
if (_is_native_reflect_construct()) {
|
|
47
|
+
_construct = Reflect.construct;
|
|
48
|
+
} else {
|
|
49
|
+
_construct = function construct(Parent, args, Class) {
|
|
50
|
+
var a = [
|
|
51
|
+
null
|
|
52
|
+
];
|
|
53
|
+
a.push.apply(a, args);
|
|
54
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
55
|
+
var instance = new Constructor();
|
|
56
|
+
if (Class) _set_prototype_of(instance, Class.prototype);
|
|
57
|
+
return instance;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return _construct.apply(null, arguments);
|
|
61
|
+
}
|
|
62
|
+
function _get_prototype_of(o) {
|
|
63
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
64
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
65
|
+
};
|
|
66
|
+
return _get_prototype_of(o);
|
|
67
|
+
}
|
|
68
|
+
function _inherits(subClass, superClass) {
|
|
69
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
70
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
71
|
+
}
|
|
72
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
73
|
+
constructor: {
|
|
74
|
+
value: subClass,
|
|
75
|
+
writable: true,
|
|
76
|
+
configurable: true
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
80
|
+
}
|
|
81
|
+
function _is_native_function(fn) {
|
|
82
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
83
|
+
}
|
|
84
|
+
function _possible_constructor_return(self, call) {
|
|
85
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
86
|
+
return call;
|
|
87
|
+
}
|
|
88
|
+
return _assert_this_initialized(self);
|
|
89
|
+
}
|
|
90
|
+
function _set_prototype_of(o, p) {
|
|
91
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
92
|
+
o.__proto__ = p;
|
|
93
|
+
return o;
|
|
94
|
+
};
|
|
95
|
+
return _set_prototype_of(o, p);
|
|
96
|
+
}
|
|
97
|
+
function _type_of(obj) {
|
|
98
|
+
"@swc/helpers - typeof";
|
|
99
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
100
|
+
}
|
|
101
|
+
function _wrap_native_super(Class) {
|
|
102
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
103
|
+
_wrap_native_super = function wrapNativeSuper(Class) {
|
|
104
|
+
if (Class === null || !_is_native_function(Class)) return Class;
|
|
105
|
+
if (typeof Class !== "function") {
|
|
106
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
107
|
+
}
|
|
108
|
+
if (typeof _cache !== "undefined") {
|
|
109
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
110
|
+
_cache.set(Class, Wrapper);
|
|
111
|
+
}
|
|
112
|
+
function Wrapper() {
|
|
113
|
+
return _construct(Class, arguments, _get_prototype_of(this).constructor);
|
|
114
|
+
}
|
|
115
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
|
116
|
+
constructor: {
|
|
117
|
+
value: Wrapper,
|
|
118
|
+
enumerable: false,
|
|
119
|
+
writable: true,
|
|
120
|
+
configurable: true
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return _set_prototype_of(Wrapper, Class);
|
|
124
|
+
};
|
|
125
|
+
return _wrap_native_super(Class);
|
|
126
|
+
}
|
|
127
|
+
function _is_native_reflect_construct() {
|
|
128
|
+
try {
|
|
129
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
130
|
+
} catch (_) {}
|
|
131
|
+
return (_is_native_reflect_construct = function() {
|
|
132
|
+
return !!result;
|
|
133
|
+
})();
|
|
134
|
+
}
|
|
135
|
+
var AccountManagerError = /*#__PURE__*/ function(Error1) {
|
|
136
|
+
"use strict";
|
|
137
|
+
_inherits(AccountManagerError, Error1);
|
|
138
|
+
function AccountManagerError(message, code) {
|
|
139
|
+
var retryable = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
|
|
140
|
+
_class_call_check(this, AccountManagerError);
|
|
141
|
+
var _this;
|
|
142
|
+
_this = _call_super(this, AccountManagerError, [
|
|
143
|
+
message
|
|
144
|
+
]);
|
|
145
|
+
_this.name = 'AccountManagerError';
|
|
146
|
+
_this.code = code;
|
|
147
|
+
_this.retryable = retryable;
|
|
148
|
+
return _this;
|
|
149
|
+
}
|
|
150
|
+
return AccountManagerError;
|
|
151
|
+
}(_wrap_native_super(Error));
|
|
152
|
+
var AccountNotFoundError = /*#__PURE__*/ function(AccountManagerError) {
|
|
153
|
+
"use strict";
|
|
154
|
+
_inherits(AccountNotFoundError, AccountManagerError);
|
|
155
|
+
function AccountNotFoundError(accountRef) {
|
|
156
|
+
_class_call_check(this, AccountNotFoundError);
|
|
157
|
+
return _call_super(this, AccountNotFoundError, [
|
|
158
|
+
"Account '".concat(accountRef, "' not found"),
|
|
159
|
+
'ACCOUNT_NOT_FOUND',
|
|
160
|
+
false
|
|
161
|
+
]);
|
|
162
|
+
}
|
|
163
|
+
return AccountNotFoundError;
|
|
164
|
+
}(AccountManagerError);
|
|
165
|
+
var ConfigurationError = /*#__PURE__*/ function(AccountManagerError) {
|
|
166
|
+
"use strict";
|
|
167
|
+
_inherits(ConfigurationError, AccountManagerError);
|
|
168
|
+
function ConfigurationError(message) {
|
|
169
|
+
_class_call_check(this, ConfigurationError);
|
|
170
|
+
return _call_super(this, ConfigurationError, [
|
|
171
|
+
"Configuration error: ".concat(message),
|
|
172
|
+
'CONFIGURATION_ERROR',
|
|
173
|
+
false
|
|
174
|
+
]);
|
|
175
|
+
}
|
|
176
|
+
return ConfigurationError;
|
|
177
|
+
}(AccountManagerError);
|
|
178
|
+
var RequiresAuthenticationError = /*#__PURE__*/ function(AccountManagerError) {
|
|
179
|
+
"use strict";
|
|
180
|
+
_inherits(RequiresAuthenticationError, AccountManagerError);
|
|
181
|
+
function RequiresAuthenticationError(service, accountId) {
|
|
182
|
+
_class_call_check(this, RequiresAuthenticationError);
|
|
183
|
+
var _this;
|
|
184
|
+
var message = accountId ? "No account found for ".concat(service, " (account: ").concat(accountId, "). Use account-add to connect one.") : "No account found for ".concat(service, ". Use account-add to connect one.");
|
|
185
|
+
_this = _call_super(this, RequiresAuthenticationError, [
|
|
186
|
+
message,
|
|
187
|
+
'REQUIRES_AUTHENTICATION',
|
|
188
|
+
false
|
|
189
|
+
]);
|
|
190
|
+
_this.accountId = accountId;
|
|
191
|
+
return _this;
|
|
192
|
+
}
|
|
193
|
+
return RequiresAuthenticationError;
|
|
194
|
+
}(AccountManagerError);
|
|
195
|
+
var AuthRequiredError = /*#__PURE__*/ function(Error1) {
|
|
196
|
+
"use strict";
|
|
197
|
+
_inherits(AuthRequiredError, Error1);
|
|
198
|
+
function AuthRequiredError(descriptor, message) {
|
|
199
|
+
_class_call_check(this, AuthRequiredError);
|
|
200
|
+
var _this;
|
|
201
|
+
_this = _call_super(this, AuthRequiredError, [
|
|
202
|
+
message || "Authentication required: ".concat(descriptor.kind)
|
|
203
|
+
]);
|
|
204
|
+
_this.name = 'AuthRequiredError';
|
|
205
|
+
_this.descriptor = descriptor;
|
|
206
|
+
return _this;
|
|
207
|
+
}
|
|
208
|
+
return AuthRequiredError;
|
|
209
|
+
}(_wrap_native_super(Error));
|
|
210
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth/src/types.ts"],"sourcesContent":["/**\n * Type definitions for multi-account management and OAuth integration\n */\n\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { AnySchema, ZodRawShapeCompat } from '@modelcontextprotocol/sdk/server/zod-compat.js';\nimport type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport type { CallToolResult, GetPromptResult, ServerNotification, ServerRequest, ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';\n\nexport type Logger = Pick<Console, 'info' | 'error' | 'warn' | 'debug'>;\n\nexport interface AccountInfo {\n email: string;\n alias?: string;\n addedAt: string;\n lastUsed?: string;\n metadata?: {\n name?: string;\n picture?: string;\n [key: string]: unknown;\n };\n}\n\n/**\n * MCP tool module definition with configuration and handler function.\n *\n * Represents a registered tool in the Model Context Protocol server that can be\n * invoked by MCP clients. Tools are the primary mechanism for executing operations\n * in response to client requests.\n *\n * @property name - Unique tool identifier (e.g., \"gmail-message-send\", \"sheets-values-get\")\n * @property config - Tool configuration including description and schemas\n * @property config.description - Human-readable description shown to MCP clients\n * @property config.inputSchema - Zod schema defining tool arguments (JSON-serializable)\n * @property config.outputSchema - Zod schema defining tool response structure\n * @property handler - Async function that executes the tool operation\n *\n * @remarks\n * This is the runtime representation of an MCP tool after registration. The handler\n * receives JSON-serializable arguments validated against inputSchema and returns\n * a CallToolResult validated against outputSchema.\n *\n * Tools are typically created using tool factory functions and registered with the\n * MCP server during initialization.\n *\n * @example\n * ```typescript\n * const tool: McpTool = {\n * name: \"gmail-message-send\",\n * config: {\n * description: \"Send an email message\",\n * inputSchema: { to: { type: \"string\" }, subject: { type: \"string\" } },\n * outputSchema: { result: { type: \"object\" } }\n * },\n * handler: async (args, context) => {\n * // Implementation\n * return { content: [{ type: \"text\", text: \"Message sent\" }] };\n * }\n * };\n * ```\n *\n * @see {@link McpPrompt} for prompt module definition\n */\nexport interface McpTool {\n name: string;\n config: {\n description: string;\n inputSchema: Record<string, unknown>;\n outputSchema: Record<string, unknown>;\n };\n handler: (args: unknown, context?: unknown) => Promise<CallToolResult>;\n}\n\n/**\n * MCP prompt module definition with configuration and handler function.\n *\n * Represents a registered prompt template in the Model Context Protocol server that\n * can be retrieved and rendered by MCP clients. Prompts provide reusable templates\n * for common interaction patterns.\n *\n * @property name - Unique prompt identifier (e.g., \"draft-email\", \"summarize-thread\")\n * @property config - Prompt configuration (schema and metadata are prompt-specific)\n * @property handler - Async function that generates the prompt content\n *\n * @remarks\n * This is the runtime representation of an MCP prompt after registration. Unlike\n * {@link McpTool} which executes operations, prompts generate templated content\n * that clients can use to structure interactions.\n *\n * The handler receives optional arguments and returns a GetPromptResult containing\n * the rendered prompt messages.\n *\n * @example\n * ```typescript\n * const prompt: McpPrompt = {\n * name: \"draft-email\",\n * config: {\n * description: \"Generate email draft from key points\",\n * arguments: [{ name: \"points\", description: \"Key points to include\" }]\n * },\n * handler: async (args) => {\n * const points = args?.points || [];\n * return {\n * messages: [{\n * role: \"user\",\n * content: { type: \"text\", text: `Draft email covering: ${points.join(\", \")}` }\n * }]\n * };\n * }\n * };\n * ```\n *\n * @see {@link McpTool} for tool module definition\n */\nexport interface McpPrompt {\n name: string;\n config: unknown;\n handler: (args: unknown) => Promise<GetPromptResult>;\n}\n\nexport class AccountManagerError extends Error {\n public code: string;\n public retryable: boolean;\n\n constructor(message: string, code: string, retryable = false) {\n super(message);\n this.name = 'AccountManagerError';\n this.code = code;\n this.retryable = retryable;\n }\n}\n\nexport class AccountNotFoundError extends AccountManagerError {\n constructor(accountRef: string) {\n super(`Account '${accountRef}' not found`, 'ACCOUNT_NOT_FOUND', false);\n }\n}\n\nexport class ConfigurationError extends AccountManagerError {\n constructor(message: string) {\n super(`Configuration error: ${message}`, 'CONFIGURATION_ERROR', false);\n }\n}\n\nexport class RequiresAuthenticationError extends AccountManagerError {\n public accountId: string | undefined;\n\n constructor(service: string, accountId?: string) {\n const message = accountId ? `No account found for ${service} (account: ${accountId}). Use account-add to connect one.` : `No account found for ${service}. Use account-add to connect one.`;\n super(message, 'REQUIRES_AUTHENTICATION', false);\n this.accountId = accountId;\n }\n}\n\nexport interface AuthEmailProvider {\n getUserEmail(accountId?: string): Promise<string>;\n authenticateNewAccount?(): Promise<string>;\n}\n\nexport interface UserAuthProvider {\n getUserId(req: unknown): Promise<string>; // Throws if auth invalid\n}\n\nexport interface JWTUserAuthConfig {\n secret?: string; // HS256 - MUST be at least 32 characters\n publicKey?: string | object; // RS256/ES256 - PEM string, JWK object, or JWKS URL\n jwksUrl?: string; // Alternative to publicKey\n issuer?: string | string[];\n audience?: string | string[];\n userIdClaim?: string; // Default: 'sub'\n algorithms?: string[]; // Default: auto-detect\n clockTolerance?: number; // Default: 0\n}\n\nexport interface SessionUserAuthConfig {\n sessionSecret: string; // MUST be at least 32 characters\n cookieName?: string; // Default: 'session'\n algorithm?: 'sha256' | 'sha512'; // Default: 'sha256'\n}\n\nexport interface Credentials {\n accessToken: string;\n expiresAt?: number;\n refreshToken?: string;\n scope?: string;\n tokenType?: string;\n idToken?: string;\n}\n\nexport type AuthFlowDescriptor =\n | { kind: 'credentials'; connection?: string; provider?: string; credentials: Credentials }\n | { kind: 'auth_url'; connection?: string; provider?: string; url: string; txn?: string; state?: string; codeVerifier?: string; poll?: { statusUrl: string; interval?: number }; hint?: string }\n | { kind: 'device_code'; connection?: string; provider?: string; txn?: string; device: { userCode: string; verificationUri: string; verificationUriComplete?: string; expiresIn: number; interval: number }; poll?: { statusUrl: string; interval?: number }; hint?: string }\n | { kind: 'error'; error: string; code?: number };\n\nexport class AuthRequiredError extends Error {\n public descriptor: AuthFlowDescriptor;\n\n constructor(descriptor: AuthFlowDescriptor, message?: string) {\n super(message || `Authentication required: ${descriptor.kind}`);\n this.name = 'AuthRequiredError';\n this.descriptor = descriptor;\n }\n}\n\nexport interface CachedToken {\n accessToken: string;\n refreshToken?: string;\n expiresAt?: number;\n scope?: string;\n}\n\n/**\n * Tool config signature - explicit structural type mirroring SDK registerTool config\n *\n * Uses explicit structure instead of Parameters<> extraction to avoid TypeScript inference\n * collapse to 'never' when using ToolModule[] arrays. The deep conditional types from\n * Parameters<> cannot be unified across array elements.\n *\n * Validated against SDK signature for compatibility - compile errors if SDK changes.\n *\n * NOTE: This type is duplicated in @mcp-z/server for architectural independence.\n * Keep these definitions synchronized manually when updating.\n */\nexport type ToolConfig = {\n title?: string;\n description?: string;\n inputSchema?: ZodRawShapeCompat | AnySchema;\n outputSchema?: ZodRawShapeCompat | AnySchema;\n annotations?: ToolAnnotations;\n _meta?: Record<string, unknown>;\n};\n\n// Compile-time validation that ToolConfig is compatible with SDK\ntype _ValidateToolConfigAssignable = ToolConfig extends Parameters<McpServer['registerTool']>[1] ? true : never;\ntype _ValidateToolConfigReceivable = Parameters<McpServer['registerTool']>[1] extends ToolConfig ? true : never;\n\n/**\n * Tool handler signature with generic support for middleware.\n *\n * @template TArgs - Tool arguments type (default: unknown for SDK compatibility)\n * @template TExtra - Request handler extra type (default: RequestHandlerExtra from SDK)\n *\n * Defaults provide SDK-extracted types for compatibility with MCP SDK.\n * Generic parameters enable type-safe middleware transformation.\n *\n * NOTE: This interface is duplicated in @mcp-z/server for architectural independence.\n * Keep these definitions synchronized manually when updating.\n */\nexport type ToolHandler<TArgs = unknown, TExtra = RequestHandlerExtra<ServerRequest, ServerNotification>> = (args: TArgs, extra: TExtra) => Promise<CallToolResult>;\n\n/**\n * Tool module interface with bounded generics.\n *\n * @template TConfig - Tool config type (default: SDK ToolConfig)\n * @template THandler - Handler function type (default: SDK ToolHandler)\n *\n * Use without generics for SDK-typed tools:\n * - Business tool factories: `ToolModule`\n * - Tool registration: `ToolModule[]`\n *\n * Use with generics for middleware transformation:\n * - Auth middleware: `ToolModule<ToolConfig, ToolHandler<TArgs, EnrichedExtra>>`\n *\n * The bounds ensure compatibility with SDK registration.\n *\n * NOTE: This interface is duplicated in @mcp-z/server for architectural independence.\n * Keep these definitions synchronized manually when updating.\n *\n * @see {@link ToolHandler} for handler function signature\n * @see {@link AuthMiddlewareWrapper} for middleware wrapper pattern\n */\nexport interface ToolModule<TConfig = ToolConfig, THandler = unknown> {\n name: string;\n config: TConfig;\n handler: THandler;\n}\n\n/**\n * Middleware wrapper that enriches tool modules with authentication context.\n *\n * Wraps plain tool modules to inject authentication, logging, and request metadata.\n * The wrapper pattern allows separation of business logic from cross-cutting concerns.\n *\n * @template TArgs - Tool arguments type (inferred from tool module)\n * @template TExtra - Enriched extra type with auth context and logger\n *\n * @param toolModule - Plain tool module to wrap with auth middleware\n * @returns Wrapped tool module with enriched handler signature\n *\n * @remarks\n * Auth middleware wrappers typically:\n * - Extract auth context from MCP request or OAuth provider\n * - Inject logger instance for structured logging\n * - Handle authentication errors with proper MCP error responses\n * - Preserve tool configuration and metadata\n *\n * @example\n * ```typescript\n * // Actual usage pattern from OAuth providers (LoopbackOAuthProvider, ServiceAccountProvider, DcrOAuthProvider)\n * const provider = new LoopbackOAuthProvider({ service: 'gmail', ... });\n * const authMiddleware = provider.authMiddleware();\n *\n * // Apply middleware to tools (handlers receive enriched extra with authContext)\n * const tools = toolFactories.map(f => f()).map(authMiddleware.withToolAuth);\n * const resources = resourceFactories.map(f => f()).map(authMiddleware.withResourceAuth);\n * const prompts = promptFactories.map(f => f()).map(authMiddleware.withPromptAuth);\n *\n * // Tool handler receives enriched extra with guaranteed authContext\n * async function handler({ id }: In, extra: EnrichedExtra) {\n * // extra.authContext.auth is OAuth2Client (from middleware)\n * const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n * // ... business logic with authenticated context\n * }\n * ```\n *\n * @see {@link ToolModule} for base tool interface\n * @see {@link ToolHandler} for handler function signature\n */\nexport type AuthMiddlewareWrapper<TArgs = unknown, TExtra = RequestHandlerExtra<ServerRequest, ServerNotification>> = (toolModule: ToolModule) => ToolModule<ToolConfig, ToolHandler<TArgs, TExtra>>;\n\n/**\n * Base interface for stateful OAuth adapters (LoopbackOAuthProvider pattern)\n *\n * Stateful adapters manage token storage, refresh, and multi-account state.\n * Used for local development, test setup, and CI/CD workflows.\n *\n * Key characteristics:\n * - Token storage and retrieval via tokenStore\n * - Automatic token refresh with provider\n * - Interactive OAuth flows (browser, ephemeral server)\n * - Multi-account management\n *\n * Parameter usage:\n * - accountId: Account identifier (email address for token storage)\n */\nexport interface OAuth2TokenStorageProvider {\n /**\n * Get access token for the specified account.\n * If token is expired, automatically refreshes it.\n * If token is missing, triggers OAuth flow (interactive) or throws AuthRequired (headless).\n *\n * @param accountId - Account identifier for multi-account support\n * @returns Access token string\n */\n getAccessToken(accountId?: string): Promise<string>;\n\n /**\n * Get email address for the specified account.\n * Used during account registration to verify identity with provider.\n *\n * @param accountId - Account identifier\n * @returns Email address from provider verification\n */\n getUserEmail(accountId?: string): Promise<string>;\n}\n"],"names":["AccountManagerError","AccountNotFoundError","AuthRequiredError","ConfigurationError","RequiresAuthenticationError","message","code","retryable","name","Error","accountRef","service","accountId","descriptor","kind"],"mappings":"AAAA;;CAEC;;;;;;;;;;;QAsHYA;eAAAA;;QAYAC;eAAAA;;QA+DAC;eAAAA;;QAzDAC;eAAAA;;QAMAC;eAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAxBN,IAAA,AAAMJ,oCAAN;;cAAMA;aAAAA,oBAICK,OAAe,EAAEC,IAAY;YAAEC,YAAAA,iEAAY;gCAJ5CP;;gBAKT,kBALSA;YAKHK;;QACN,MAAKG,IAAI,GAAG;QACZ,MAAKF,IAAI,GAAGA;QACZ,MAAKC,SAAS,GAAGA;;;WARRP;qBAA4BS;AAYlC,IAAA,AAAMR,qCAAN;;cAAMA;aAAAA,qBACCS,UAAkB;gCADnBT;QAET,OAAA,kBAFSA;YAEF,YAAsB,OAAXS,YAAW;YAAc;YAAqB;;;WAFvDT;EAA6BD;AAMnC,IAAA,AAAMG,mCAAN;;cAAMA;aAAAA,mBACCE,OAAe;gCADhBF;QAET,OAAA,kBAFSA;YAEF,wBAA+B,OAARE;YAAW;YAAuB;;;WAFvDF;EAA2BH;AAMjC,IAAA,AAAMI,4CAAN;;cAAMA;aAAAA,4BAGCO,OAAe,EAAEC,SAAkB;gCAHpCR;;QAIT,IAAMC,UAAUO,YAAY,AAAC,wBAA4CA,OAArBD,SAAQ,eAAuB,OAAVC,WAAU,wCAAsC,AAAC,wBAA+B,OAARD,SAAQ;gBACzJ,kBALSP;YAKHC;YAAS;YAA2B;;QAC1C,MAAKO,SAAS,GAAGA;;;WANRR;EAAoCJ;AAmD1C,IAAA,AAAME,kCAAN;;cAAMA;aAAAA,kBAGCW,UAA8B,EAAER,OAAgB;gCAHjDH;;gBAIT,kBAJSA;YAIHG,WAAW,AAAC,4BAA2C,OAAhBQ,WAAWC,IAAI;;QAC5D,MAAKN,IAAI,GAAG;QACZ,MAAKK,UAAU,GAAGA;;;WANTX;qBAA0BO"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account management utilities for OAuth token storage
|
|
3
|
+
*
|
|
4
|
+
* Provides account lifecycle operations (add, remove, activate) and account data
|
|
5
|
+
* access (tokens, metadata). Uses named parameters consistent with key-utils.ts.
|
|
6
|
+
*/
|
|
7
|
+
import type { Keyv } from 'keyv';
|
|
8
|
+
import { type AccountKeyParams, type ServiceKeyParams } from './key-utils.js';
|
|
9
|
+
import type { AccountInfo } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Add account to linked accounts list and set as active if first account.
|
|
12
|
+
*
|
|
13
|
+
* @param store - Keyv storage instance
|
|
14
|
+
* @param params - Account identification (service, accountId)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* await addAccount(tokenStore, {
|
|
18
|
+
* service: 'gmail',
|
|
19
|
+
* accountId: 'alice@gmail.com'
|
|
20
|
+
* });
|
|
21
|
+
*/
|
|
22
|
+
export declare function addAccount(store: Keyv, params: AccountKeyParams): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Remove account: delete token, metadata, update linked list, and active account.
|
|
25
|
+
*
|
|
26
|
+
* @param store - Keyv storage instance
|
|
27
|
+
* @param params - Account identification (service, accountId)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* await removeAccount(tokenStore, {
|
|
31
|
+
* service: 'gmail',
|
|
32
|
+
* accountId: 'alice@gmail.com'
|
|
33
|
+
* });
|
|
34
|
+
*/
|
|
35
|
+
export declare function removeAccount(store: Keyv, params: AccountKeyParams): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Get active account ID for a service.
|
|
38
|
+
*
|
|
39
|
+
* Key: {service}:active
|
|
40
|
+
*
|
|
41
|
+
* @param store - Keyv storage instance
|
|
42
|
+
* @param params - Service identification (service)
|
|
43
|
+
* @returns Active account ID or undefined if none set
|
|
44
|
+
*/
|
|
45
|
+
export declare function getActiveAccount(store: Keyv, params: ServiceKeyParams): Promise<string | undefined>;
|
|
46
|
+
/**
|
|
47
|
+
* Set active account ID for a service.
|
|
48
|
+
* Pass null as accountId to deactivate (clear active account).
|
|
49
|
+
*
|
|
50
|
+
* Key: {service}:active
|
|
51
|
+
*
|
|
52
|
+
* @param store - Keyv storage instance
|
|
53
|
+
* @param params - Account identification (service, accountId). Pass accountId: null to deactivate.
|
|
54
|
+
*/
|
|
55
|
+
export declare function setActiveAccount(store: Keyv, params: AccountKeyParams | (ServiceKeyParams & {
|
|
56
|
+
accountId: null;
|
|
57
|
+
})): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Get list of linked account IDs for a service.
|
|
60
|
+
*
|
|
61
|
+
* Key: {service}:linked
|
|
62
|
+
*
|
|
63
|
+
* @param store - Keyv storage instance
|
|
64
|
+
* @param params - Service identification (service)
|
|
65
|
+
* @returns Array of account IDs (empty array if none)
|
|
66
|
+
*/
|
|
67
|
+
export declare function getLinkedAccounts(store: Keyv, params: ServiceKeyParams): Promise<string[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Get account metadata (alias, lastUsed, etc).
|
|
70
|
+
*
|
|
71
|
+
* Key: {accountId}:{service}:metadata
|
|
72
|
+
*
|
|
73
|
+
* @param store - Keyv storage instance
|
|
74
|
+
* @param params - Account identification (accountId, service)
|
|
75
|
+
* @returns Account info or undefined if not found
|
|
76
|
+
*/
|
|
77
|
+
export declare function getAccountInfo(store: Keyv, params: AccountKeyParams): Promise<AccountInfo | undefined>;
|
|
78
|
+
/**
|
|
79
|
+
* Set account metadata (alias, lastUsed, etc).
|
|
80
|
+
*
|
|
81
|
+
* Key: {accountId}:{service}:metadata
|
|
82
|
+
*
|
|
83
|
+
* @param store - Keyv storage instance
|
|
84
|
+
* @param params - Account identification (accountId, service)
|
|
85
|
+
* @param info - Account metadata to store
|
|
86
|
+
*/
|
|
87
|
+
export declare function setAccountInfo(store: Keyv, params: AccountKeyParams, info: AccountInfo): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Get OAuth token for an account.
|
|
90
|
+
*
|
|
91
|
+
* Key: {accountId}:{service}:token
|
|
92
|
+
*
|
|
93
|
+
* @param store - Keyv storage instance
|
|
94
|
+
* @param params - Account identification (accountId, service)
|
|
95
|
+
* @returns Token or undefined if not found
|
|
96
|
+
*/
|
|
97
|
+
export declare function getToken<T>(store: Keyv, params: AccountKeyParams): Promise<T | undefined>;
|
|
98
|
+
/**
|
|
99
|
+
* Set OAuth token for an account.
|
|
100
|
+
*
|
|
101
|
+
* Key: {accountId}:{service}:token
|
|
102
|
+
*
|
|
103
|
+
* @param store - Keyv storage instance
|
|
104
|
+
* @param params - Account identification (accountId, service)
|
|
105
|
+
* @param token - OAuth token data to store
|
|
106
|
+
*/
|
|
107
|
+
export declare function setToken<T>(store: Keyv, params: AccountKeyParams, token: T): Promise<void>;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account management utilities for OAuth token storage
|
|
3
|
+
*
|
|
4
|
+
* Provides account lifecycle operations (add, remove, activate) and account data
|
|
5
|
+
* access (tokens, metadata). Uses named parameters consistent with key-utils.ts.
|
|
6
|
+
*/ import { createAccountKey, createServiceKey } from './key-utils.js';
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Account Lifecycle Operations
|
|
9
|
+
// ============================================================================
|
|
10
|
+
/**
|
|
11
|
+
* Add account to linked accounts list and set as active if first account.
|
|
12
|
+
*
|
|
13
|
+
* @param store - Keyv storage instance
|
|
14
|
+
* @param params - Account identification (service, accountId)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* await addAccount(tokenStore, {
|
|
18
|
+
* service: 'gmail',
|
|
19
|
+
* accountId: 'alice@gmail.com'
|
|
20
|
+
* });
|
|
21
|
+
*/ export async function addAccount(store, params) {
|
|
22
|
+
const linked = await getLinkedAccounts(store, {
|
|
23
|
+
service: params.service
|
|
24
|
+
});
|
|
25
|
+
if (!linked.includes(params.accountId)) {
|
|
26
|
+
linked.push(params.accountId);
|
|
27
|
+
const linkedKey = createServiceKey('linked', {
|
|
28
|
+
service: params.service
|
|
29
|
+
});
|
|
30
|
+
await store.set(linkedKey, linked);
|
|
31
|
+
}
|
|
32
|
+
const active = await getActiveAccount(store, {
|
|
33
|
+
service: params.service
|
|
34
|
+
});
|
|
35
|
+
if (!active) {
|
|
36
|
+
await setActiveAccount(store, params);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Remove account: delete token, metadata, update linked list, and active account.
|
|
41
|
+
*
|
|
42
|
+
* @param store - Keyv storage instance
|
|
43
|
+
* @param params - Account identification (service, accountId)
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* await removeAccount(tokenStore, {
|
|
47
|
+
* service: 'gmail',
|
|
48
|
+
* accountId: 'alice@gmail.com'
|
|
49
|
+
* });
|
|
50
|
+
*/ export async function removeAccount(store, params) {
|
|
51
|
+
const tokenKey = createAccountKey('token', params);
|
|
52
|
+
await store.delete(tokenKey);
|
|
53
|
+
const infoKey = createAccountKey('metadata', params);
|
|
54
|
+
await store.delete(infoKey);
|
|
55
|
+
const linked = await getLinkedAccounts(store, {
|
|
56
|
+
service: params.service
|
|
57
|
+
});
|
|
58
|
+
const filtered = linked.filter((id)=>id !== params.accountId);
|
|
59
|
+
const linkedKey = createServiceKey('linked', {
|
|
60
|
+
service: params.service
|
|
61
|
+
});
|
|
62
|
+
await store.set(linkedKey, filtered);
|
|
63
|
+
// Set new active account if we're removing the currently active one
|
|
64
|
+
const active = await getActiveAccount(store, {
|
|
65
|
+
service: params.service
|
|
66
|
+
});
|
|
67
|
+
if (active === params.accountId) {
|
|
68
|
+
const newActive = filtered[0];
|
|
69
|
+
if (newActive) {
|
|
70
|
+
await setActiveAccount(store, {
|
|
71
|
+
service: params.service,
|
|
72
|
+
accountId: newActive
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
const activeKey = createServiceKey('active', {
|
|
76
|
+
service: params.service
|
|
77
|
+
});
|
|
78
|
+
await store.delete(activeKey);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// ============================================================================
|
|
83
|
+
// Service-Scoped Account Operations
|
|
84
|
+
// ============================================================================
|
|
85
|
+
/**
|
|
86
|
+
* Get active account ID for a service.
|
|
87
|
+
*
|
|
88
|
+
* Key: {service}:active
|
|
89
|
+
*
|
|
90
|
+
* @param store - Keyv storage instance
|
|
91
|
+
* @param params - Service identification (service)
|
|
92
|
+
* @returns Active account ID or undefined if none set
|
|
93
|
+
*/ export async function getActiveAccount(store, params) {
|
|
94
|
+
const key = createServiceKey('active', params);
|
|
95
|
+
return await store.get(key);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Set active account ID for a service.
|
|
99
|
+
* Pass null as accountId to deactivate (clear active account).
|
|
100
|
+
*
|
|
101
|
+
* Key: {service}:active
|
|
102
|
+
*
|
|
103
|
+
* @param store - Keyv storage instance
|
|
104
|
+
* @param params - Account identification (service, accountId). Pass accountId: null to deactivate.
|
|
105
|
+
*/ export async function setActiveAccount(store, params) {
|
|
106
|
+
const key = createServiceKey('active', {
|
|
107
|
+
service: params.service
|
|
108
|
+
});
|
|
109
|
+
if ('accountId' in params && params.accountId === null) {
|
|
110
|
+
// accountId: null signals deactivation per API contract
|
|
111
|
+
await store.delete(key);
|
|
112
|
+
} else {
|
|
113
|
+
await store.set(key, params.accountId);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get list of linked account IDs for a service.
|
|
118
|
+
*
|
|
119
|
+
* Key: {service}:linked
|
|
120
|
+
*
|
|
121
|
+
* @param store - Keyv storage instance
|
|
122
|
+
* @param params - Service identification (service)
|
|
123
|
+
* @returns Array of account IDs (empty array if none)
|
|
124
|
+
*/ export async function getLinkedAccounts(store, params) {
|
|
125
|
+
const key = createServiceKey('linked', params);
|
|
126
|
+
const accounts = await store.get(key);
|
|
127
|
+
return accounts || [];
|
|
128
|
+
}
|
|
129
|
+
// ============================================================================
|
|
130
|
+
// Account Data Operations
|
|
131
|
+
// ============================================================================
|
|
132
|
+
/**
|
|
133
|
+
* Get account metadata (alias, lastUsed, etc).
|
|
134
|
+
*
|
|
135
|
+
* Key: {accountId}:{service}:metadata
|
|
136
|
+
*
|
|
137
|
+
* @param store - Keyv storage instance
|
|
138
|
+
* @param params - Account identification (accountId, service)
|
|
139
|
+
* @returns Account info or undefined if not found
|
|
140
|
+
*/ export async function getAccountInfo(store, params) {
|
|
141
|
+
const key = createAccountKey('metadata', params);
|
|
142
|
+
return await store.get(key);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Set account metadata (alias, lastUsed, etc).
|
|
146
|
+
*
|
|
147
|
+
* Key: {accountId}:{service}:metadata
|
|
148
|
+
*
|
|
149
|
+
* @param store - Keyv storage instance
|
|
150
|
+
* @param params - Account identification (accountId, service)
|
|
151
|
+
* @param info - Account metadata to store
|
|
152
|
+
*/ export async function setAccountInfo(store, params, info) {
|
|
153
|
+
const key = createAccountKey('metadata', params);
|
|
154
|
+
await store.set(key, info);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get OAuth token for an account.
|
|
158
|
+
*
|
|
159
|
+
* Key: {accountId}:{service}:token
|
|
160
|
+
*
|
|
161
|
+
* @param store - Keyv storage instance
|
|
162
|
+
* @param params - Account identification (accountId, service)
|
|
163
|
+
* @returns Token or undefined if not found
|
|
164
|
+
*/ export async function getToken(store, params) {
|
|
165
|
+
const key = createAccountKey('token', params);
|
|
166
|
+
return await store.get(key);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Set OAuth token for an account.
|
|
170
|
+
*
|
|
171
|
+
* Key: {accountId}:{service}:token
|
|
172
|
+
*
|
|
173
|
+
* @param store - Keyv storage instance
|
|
174
|
+
* @param params - Account identification (accountId, service)
|
|
175
|
+
* @param token - OAuth token data to store
|
|
176
|
+
*/ export async function setToken(store, params, token) {
|
|
177
|
+
const key = createAccountKey('token', params);
|
|
178
|
+
await store.set(key, token);
|
|
179
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth/src/account-utils.ts"],"sourcesContent":["/**\n * Account management utilities for OAuth token storage\n *\n * Provides account lifecycle operations (add, remove, activate) and account data\n * access (tokens, metadata). Uses named parameters consistent with key-utils.ts.\n */\n\nimport type { Keyv } from 'keyv';\nimport { type AccountKeyParams, createAccountKey, createServiceKey, type ServiceKeyParams } from './key-utils.ts';\nimport type { AccountInfo } from './types.ts';\n\n// ============================================================================\n// Account Lifecycle Operations\n// ============================================================================\n\n/**\n * Add account to linked accounts list and set as active if first account.\n *\n * @param store - Keyv storage instance\n * @param params - Account identification (service, accountId)\n *\n * @example\n * await addAccount(tokenStore, {\n * service: 'gmail',\n * accountId: 'alice@gmail.com'\n * });\n */\nexport async function addAccount(store: Keyv, params: AccountKeyParams): Promise<void> {\n const linked = await getLinkedAccounts(store, { service: params.service });\n\n if (!linked.includes(params.accountId)) {\n linked.push(params.accountId);\n const linkedKey = createServiceKey('linked', { service: params.service });\n await store.set(linkedKey, linked);\n }\n\n const active = await getActiveAccount(store, { service: params.service });\n if (!active) {\n await setActiveAccount(store, params);\n }\n}\n\n/**\n * Remove account: delete token, metadata, update linked list, and active account.\n *\n * @param store - Keyv storage instance\n * @param params - Account identification (service, accountId)\n *\n * @example\n * await removeAccount(tokenStore, {\n * service: 'gmail',\n * accountId: 'alice@gmail.com'\n * });\n */\nexport async function removeAccount(store: Keyv, params: AccountKeyParams): Promise<void> {\n const tokenKey = createAccountKey('token', params);\n await store.delete(tokenKey);\n\n const infoKey = createAccountKey('metadata', params);\n await store.delete(infoKey);\n\n const linked = await getLinkedAccounts(store, { service: params.service });\n const filtered = linked.filter((id) => id !== params.accountId);\n const linkedKey = createServiceKey('linked', { service: params.service });\n await store.set(linkedKey, filtered);\n\n // Set new active account if we're removing the currently active one\n const active = await getActiveAccount(store, { service: params.service });\n if (active === params.accountId) {\n const newActive = filtered[0];\n if (newActive) {\n await setActiveAccount(store, { service: params.service, accountId: newActive });\n } else {\n const activeKey = createServiceKey('active', { service: params.service });\n await store.delete(activeKey);\n }\n }\n}\n\n// ============================================================================\n// Service-Scoped Account Operations\n// ============================================================================\n\n/**\n * Get active account ID for a service.\n *\n * Key: {service}:active\n *\n * @param store - Keyv storage instance\n * @param params - Service identification (service)\n * @returns Active account ID or undefined if none set\n */\nexport async function getActiveAccount(store: Keyv, params: ServiceKeyParams): Promise<string | undefined> {\n const key = createServiceKey('active', params);\n return await store.get(key);\n}\n\n/**\n * Set active account ID for a service.\n * Pass null as accountId to deactivate (clear active account).\n *\n * Key: {service}:active\n *\n * @param store - Keyv storage instance\n * @param params - Account identification (service, accountId). Pass accountId: null to deactivate.\n */\nexport async function setActiveAccount(store: Keyv, params: AccountKeyParams | (ServiceKeyParams & { accountId: null })): Promise<void> {\n const key = createServiceKey('active', { service: params.service });\n if ('accountId' in params && params.accountId === null) {\n // accountId: null signals deactivation per API contract\n await store.delete(key);\n } else {\n await store.set(key, (params as AccountKeyParams).accountId);\n }\n}\n\n/**\n * Get list of linked account IDs for a service.\n *\n * Key: {service}:linked\n *\n * @param store - Keyv storage instance\n * @param params - Service identification (service)\n * @returns Array of account IDs (empty array if none)\n */\nexport async function getLinkedAccounts(store: Keyv, params: ServiceKeyParams): Promise<string[]> {\n const key = createServiceKey('linked', params);\n const accounts = await store.get(key);\n return accounts || [];\n}\n\n// ============================================================================\n// Account Data Operations\n// ============================================================================\n\n/**\n * Get account metadata (alias, lastUsed, etc).\n *\n * Key: {accountId}:{service}:metadata\n *\n * @param store - Keyv storage instance\n * @param params - Account identification (accountId, service)\n * @returns Account info or undefined if not found\n */\nexport async function getAccountInfo(store: Keyv, params: AccountKeyParams): Promise<AccountInfo | undefined> {\n const key = createAccountKey('metadata', params);\n return await store.get(key);\n}\n\n/**\n * Set account metadata (alias, lastUsed, etc).\n *\n * Key: {accountId}:{service}:metadata\n *\n * @param store - Keyv storage instance\n * @param params - Account identification (accountId, service)\n * @param info - Account metadata to store\n */\nexport async function setAccountInfo(store: Keyv, params: AccountKeyParams, info: AccountInfo): Promise<void> {\n const key = createAccountKey('metadata', params);\n await store.set(key, info);\n}\n\n/**\n * Get OAuth token for an account.\n *\n * Key: {accountId}:{service}:token\n *\n * @param store - Keyv storage instance\n * @param params - Account identification (accountId, service)\n * @returns Token or undefined if not found\n */\nexport async function getToken<T>(store: Keyv, params: AccountKeyParams): Promise<T | undefined> {\n const key = createAccountKey('token', params);\n return await store.get(key);\n}\n\n/**\n * Set OAuth token for an account.\n *\n * Key: {accountId}:{service}:token\n *\n * @param store - Keyv storage instance\n * @param params - Account identification (accountId, service)\n * @param token - OAuth token data to store\n */\nexport async function setToken<T>(store: Keyv, params: AccountKeyParams, token: T): Promise<void> {\n const key = createAccountKey('token', params);\n await store.set(key, token);\n}\n"],"names":["createAccountKey","createServiceKey","addAccount","store","params","linked","getLinkedAccounts","service","includes","accountId","push","linkedKey","set","active","getActiveAccount","setActiveAccount","removeAccount","tokenKey","delete","infoKey","filtered","filter","id","newActive","activeKey","key","get","accounts","getAccountInfo","setAccountInfo","info","getToken","setToken","token"],"mappings":"AAAA;;;;;CAKC,GAGD,SAAgCA,gBAAgB,EAAEC,gBAAgB,QAA+B,iBAAiB;AAGlH,+EAA+E;AAC/E,+BAA+B;AAC/B,+EAA+E;AAE/E;;;;;;;;;;;CAWC,GACD,OAAO,eAAeC,WAAWC,KAAW,EAAEC,MAAwB;IACpE,MAAMC,SAAS,MAAMC,kBAAkBH,OAAO;QAAEI,SAASH,OAAOG,OAAO;IAAC;IAExE,IAAI,CAACF,OAAOG,QAAQ,CAACJ,OAAOK,SAAS,GAAG;QACtCJ,OAAOK,IAAI,CAACN,OAAOK,SAAS;QAC5B,MAAME,YAAYV,iBAAiB,UAAU;YAAEM,SAASH,OAAOG,OAAO;QAAC;QACvE,MAAMJ,MAAMS,GAAG,CAACD,WAAWN;IAC7B;IAEA,MAAMQ,SAAS,MAAMC,iBAAiBX,OAAO;QAAEI,SAASH,OAAOG,OAAO;IAAC;IACvE,IAAI,CAACM,QAAQ;QACX,MAAME,iBAAiBZ,OAAOC;IAChC;AACF;AAEA;;;;;;;;;;;CAWC,GACD,OAAO,eAAeY,cAAcb,KAAW,EAAEC,MAAwB;IACvE,MAAMa,WAAWjB,iBAAiB,SAASI;IAC3C,MAAMD,MAAMe,MAAM,CAACD;IAEnB,MAAME,UAAUnB,iBAAiB,YAAYI;IAC7C,MAAMD,MAAMe,MAAM,CAACC;IAEnB,MAAMd,SAAS,MAAMC,kBAAkBH,OAAO;QAAEI,SAASH,OAAOG,OAAO;IAAC;IACxE,MAAMa,WAAWf,OAAOgB,MAAM,CAAC,CAACC,KAAOA,OAAOlB,OAAOK,SAAS;IAC9D,MAAME,YAAYV,iBAAiB,UAAU;QAAEM,SAASH,OAAOG,OAAO;IAAC;IACvE,MAAMJ,MAAMS,GAAG,CAACD,WAAWS;IAE3B,oEAAoE;IACpE,MAAMP,SAAS,MAAMC,iBAAiBX,OAAO;QAAEI,SAASH,OAAOG,OAAO;IAAC;IACvE,IAAIM,WAAWT,OAAOK,SAAS,EAAE;QAC/B,MAAMc,YAAYH,QAAQ,CAAC,EAAE;QAC7B,IAAIG,WAAW;YACb,MAAMR,iBAAiBZ,OAAO;gBAAEI,SAASH,OAAOG,OAAO;gBAAEE,WAAWc;YAAU;QAChF,OAAO;YACL,MAAMC,YAAYvB,iBAAiB,UAAU;gBAAEM,SAASH,OAAOG,OAAO;YAAC;YACvE,MAAMJ,MAAMe,MAAM,CAACM;QACrB;IACF;AACF;AAEA,+EAA+E;AAC/E,oCAAoC;AACpC,+EAA+E;AAE/E;;;;;;;;CAQC,GACD,OAAO,eAAeV,iBAAiBX,KAAW,EAAEC,MAAwB;IAC1E,MAAMqB,MAAMxB,iBAAiB,UAAUG;IACvC,OAAO,MAAMD,MAAMuB,GAAG,CAACD;AACzB;AAEA;;;;;;;;CAQC,GACD,OAAO,eAAeV,iBAAiBZ,KAAW,EAAEC,MAAmE;IACrH,MAAMqB,MAAMxB,iBAAiB,UAAU;QAAEM,SAASH,OAAOG,OAAO;IAAC;IACjE,IAAI,eAAeH,UAAUA,OAAOK,SAAS,KAAK,MAAM;QACtD,wDAAwD;QACxD,MAAMN,MAAMe,MAAM,CAACO;IACrB,OAAO;QACL,MAAMtB,MAAMS,GAAG,CAACa,KAAK,AAACrB,OAA4BK,SAAS;IAC7D;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,eAAeH,kBAAkBH,KAAW,EAAEC,MAAwB;IAC3E,MAAMqB,MAAMxB,iBAAiB,UAAUG;IACvC,MAAMuB,WAAW,MAAMxB,MAAMuB,GAAG,CAACD;IACjC,OAAOE,YAAY,EAAE;AACvB;AAEA,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E;;;;;;;;CAQC,GACD,OAAO,eAAeC,eAAezB,KAAW,EAAEC,MAAwB;IACxE,MAAMqB,MAAMzB,iBAAiB,YAAYI;IACzC,OAAO,MAAMD,MAAMuB,GAAG,CAACD;AACzB;AAEA;;;;;;;;CAQC,GACD,OAAO,eAAeI,eAAe1B,KAAW,EAAEC,MAAwB,EAAE0B,IAAiB;IAC3F,MAAML,MAAMzB,iBAAiB,YAAYI;IACzC,MAAMD,MAAMS,GAAG,CAACa,KAAKK;AACvB;AAEA;;;;;;;;CAQC,GACD,OAAO,eAAeC,SAAY5B,KAAW,EAAEC,MAAwB;IACrE,MAAMqB,MAAMzB,iBAAiB,SAASI;IACtC,OAAO,MAAMD,MAAMuB,GAAG,CAACD;AACzB;AAEA;;;;;;;;CAQC,GACD,OAAO,eAAeO,SAAY7B,KAAW,EAAEC,MAAwB,EAAE6B,KAAQ;IAC/E,MAAMR,MAAMzB,iBAAiB,SAASI;IACtC,MAAMD,MAAMS,GAAG,CAACa,KAAKQ;AACvB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mcp-z/oauth - Multi-account OAuth orchestration and secure token storage for MCP servers
|
|
3
|
+
*
|
|
4
|
+
* Provides account management functions, account tools generation, and secure logging utilities.
|
|
5
|
+
* Designed to work with any storage backend (file, Redis, DuckDB) via Keyv interface.
|
|
6
|
+
*/
|
|
7
|
+
export { addAccount, getActiveAccount, getToken, removeAccount, setAccountInfo, setActiveAccount, setToken } from './account-utils.js';
|
|
8
|
+
export { JWTUserAuth } from './jwt-auth.js';
|
|
9
|
+
export { type AccountKeyParams, type AccountKeyType, createAccountKey, createServiceKey, listAccountIds, type ServiceKeyParams, type ServiceKeyType } from './key-utils.js';
|
|
10
|
+
export { type AccountLoopbackConfig, AccountServer, type AccountStatelessConfig, createLoopback, createStateless } from './lib/account-server/index.js';
|
|
11
|
+
export type { DcrClientInformation, DcrClientMetadata, DcrConfig, DcrErrorResponse, ProviderTokens } from './lib/dcr-types.js';
|
|
12
|
+
export type { RFC8414Metadata, RFC9728Metadata } from './lib/rfc-metadata-types.js';
|
|
13
|
+
export { generatePKCE, type PKCEPair } from './pkce.js';
|
|
14
|
+
export { sanitizeForLogging, sanitizeForLoggingFormatter } from './sanitizer.js';
|
|
15
|
+
export * as schemas from './schemas/index.js';
|
|
16
|
+
export { SessionUserAuth } from './session-auth.js';
|
|
17
|
+
export { getErrorTemplate, getSuccessTemplate } from './templates.js';
|
|
18
|
+
export type { AccountInfo, AuthEmailProvider, AuthFlowDescriptor, AuthMiddlewareWrapper, CachedToken, Credentials, JWTUserAuthConfig, Logger, McpPrompt, McpTool, OAuth2TokenStorageProvider, SessionUserAuthConfig, ToolConfig, ToolHandler, ToolModule, UserAuthProvider, } from './types.js';
|
|
19
|
+
export { AccountManagerError, AccountNotFoundError, AuthRequiredError, ConfigurationError, RequiresAuthenticationError } from './types.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mcp-z/oauth - Multi-account OAuth orchestration and secure token storage for MCP servers
|
|
3
|
+
*
|
|
4
|
+
* Provides account management functions, account tools generation, and secure logging utilities.
|
|
5
|
+
* Designed to work with any storage backend (file, Redis, DuckDB) via Keyv interface.
|
|
6
|
+
*/ // Core account management - Public API
|
|
7
|
+
// Internal functions - For provider implementations and testing
|
|
8
|
+
export { addAccount, getActiveAccount, getToken, removeAccount, setAccountInfo, setActiveAccount, setToken } from './account-utils.js';
|
|
9
|
+
// Auth classes - For multi-tenant testing
|
|
10
|
+
export { JWTUserAuth } from './jwt-auth.js';
|
|
11
|
+
export { createAccountKey, createServiceKey, listAccountIds } from './key-utils.js';
|
|
12
|
+
// Account server and factory functions - Public API
|
|
13
|
+
export { AccountServer, createLoopback, createStateless } from './lib/account-server/index.js';
|
|
14
|
+
export { generatePKCE } from './pkce.js';
|
|
15
|
+
// Logging utilities - Public API
|
|
16
|
+
export { sanitizeForLogging, sanitizeForLoggingFormatter } from './sanitizer.js';
|
|
17
|
+
// Schemas
|
|
18
|
+
import * as _schemas from './schemas/index.js';
|
|
19
|
+
export { _schemas as schemas };
|
|
20
|
+
export { SessionUserAuth } from './session-auth.js';
|
|
21
|
+
export { getErrorTemplate, getSuccessTemplate } from './templates.js';
|
|
22
|
+
// Public error classes
|
|
23
|
+
export { AccountManagerError, AccountNotFoundError, AuthRequiredError, ConfigurationError, RequiresAuthenticationError } from './types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth/src/index.ts"],"sourcesContent":["/**\n * @mcp-z/oauth - Multi-account OAuth orchestration and secure token storage for MCP servers\n *\n * Provides account management functions, account tools generation, and secure logging utilities.\n * Designed to work with any storage backend (file, Redis, DuckDB) via Keyv interface.\n */\n\n// Core account management - Public API\n// Internal functions - For provider implementations and testing\nexport { addAccount, getActiveAccount, getToken, removeAccount, setAccountInfo, setActiveAccount, setToken } from './account-utils.ts';\n// Auth classes - For multi-tenant testing\nexport { JWTUserAuth } from './jwt-auth.ts';\nexport { type AccountKeyParams, type AccountKeyType, createAccountKey, createServiceKey, listAccountIds, type ServiceKeyParams, type ServiceKeyType } from './key-utils.ts';\n// Account server and factory functions - Public API\nexport { type AccountLoopbackConfig, AccountServer, type AccountStatelessConfig, createLoopback, createStateless } from './lib/account-server/index.ts';\n// DCR types - Public API\nexport type { DcrClientInformation, DcrClientMetadata, DcrConfig, DcrErrorResponse, ProviderTokens } from './lib/dcr-types.ts';\n// RFC Metadata Types - Public API\nexport type { RFC8414Metadata, RFC9728Metadata } from './lib/rfc-metadata-types.ts';\nexport { generatePKCE, type PKCEPair } from './pkce.ts';\n// Logging utilities - Public API\nexport { sanitizeForLogging, sanitizeForLoggingFormatter } from './sanitizer.ts';\n// Schemas\nexport * as schemas from './schemas/index.ts';\nexport { SessionUserAuth } from './session-auth.ts';\nexport { getErrorTemplate, getSuccessTemplate } from './templates.ts';\n\n// Public types - core interfaces that consumers use\nexport type {\n // Account management types\n AccountInfo,\n // Provider interfaces\n AuthEmailProvider,\n AuthFlowDescriptor,\n AuthMiddlewareWrapper,\n CachedToken,\n Credentials,\n // Auth config types\n JWTUserAuthConfig,\n // Utility types\n Logger,\n McpPrompt,\n McpTool,\n OAuth2TokenStorageProvider,\n SessionUserAuthConfig,\n ToolConfig,\n ToolHandler,\n ToolModule,\n UserAuthProvider,\n} from './types.ts';\n\n// Public error classes\nexport { AccountManagerError, AccountNotFoundError, AuthRequiredError, ConfigurationError, RequiresAuthenticationError } from './types.ts';\n"],"names":["addAccount","getActiveAccount","getToken","removeAccount","setAccountInfo","setActiveAccount","setToken","JWTUserAuth","createAccountKey","createServiceKey","listAccountIds","AccountServer","createLoopback","createStateless","generatePKCE","sanitizeForLogging","sanitizeForLoggingFormatter","schemas","SessionUserAuth","getErrorTemplate","getSuccessTemplate","AccountManagerError","AccountNotFoundError","AuthRequiredError","ConfigurationError","RequiresAuthenticationError"],"mappings":"AAAA;;;;;CAKC,GAED,uCAAuC;AACvC,gEAAgE;AAChE,SAASA,UAAU,EAAEC,gBAAgB,EAAEC,QAAQ,EAAEC,aAAa,EAAEC,cAAc,EAAEC,gBAAgB,EAAEC,QAAQ,QAAQ,qBAAqB;AACvI,0CAA0C;AAC1C,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SAAqDC,gBAAgB,EAAEC,gBAAgB,EAAEC,cAAc,QAAoD,iBAAiB;AAC5K,oDAAoD;AACpD,SAAqCC,aAAa,EAA+BC,cAAc,EAAEC,eAAe,QAAQ,gCAAgC;AAKxJ,SAASC,YAAY,QAAuB,YAAY;AACxD,iCAAiC;AACjC,SAASC,kBAAkB,EAAEC,2BAA2B,QAAQ,iBAAiB;AACjF,UAAU;AACV,0BAAyB,qBAAqB;AAA9C,SAAO,YAAKC,OAAO,GAA2B;AAC9C,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,iBAAiB;AA0BtE,uBAAuB;AACvB,SAASC,mBAAmB,EAAEC,oBAAoB,EAAEC,iBAAiB,EAAEC,kBAAkB,EAAEC,2BAA2B,QAAQ,aAAa"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JWT-based user authentication for multi-tenant deployments
|
|
3
|
+
*
|
|
4
|
+
* Extracts user ID from JWT tokens with signature and claims verification.
|
|
5
|
+
* Supports HS256, RS256, ES256 algorithms via JOSE library.
|
|
6
|
+
*/
|
|
7
|
+
import type { JWTUserAuthConfig, UserAuthProvider } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* JWT-based user authentication provider
|
|
10
|
+
*
|
|
11
|
+
* Verifies JWT tokens and extracts user IDs from claims.
|
|
12
|
+
* Use for multi-tenant deployments where users authenticate via JWT.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // HS256 with shared secret
|
|
17
|
+
* const userAuth = new JWTUserAuth({
|
|
18
|
+
* secret: process.env.JWT_SECRET!,
|
|
19
|
+
* issuer: 'https://auth.example.com',
|
|
20
|
+
* audience: 'api.example.com',
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // RS256 with public key
|
|
24
|
+
* const userAuth = new JWTUserAuth({
|
|
25
|
+
* publicKey: process.env.JWT_PUBLIC_KEY!,
|
|
26
|
+
* issuer: 'https://auth.example.com',
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // RS256 with JWKS URL (dynamic key rotation)
|
|
30
|
+
* const userAuth = new JWTUserAuth({
|
|
31
|
+
* jwksUrl: 'https://auth.example.com/.well-known/jwks.json',
|
|
32
|
+
* issuer: 'https://auth.example.com',
|
|
33
|
+
* audience: 'api.example.com',
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class JWTUserAuth implements UserAuthProvider {
|
|
38
|
+
private readonly config;
|
|
39
|
+
private readonly remoteJWKSet?;
|
|
40
|
+
constructor(config: JWTUserAuthConfig);
|
|
41
|
+
/**
|
|
42
|
+
* Extract and verify user ID from JWT token
|
|
43
|
+
*
|
|
44
|
+
* @param req - HTTP request object with Authorization header
|
|
45
|
+
* @returns User ID from verified JWT claims
|
|
46
|
+
* @throws Error if token missing, invalid, expired, or claims invalid
|
|
47
|
+
*/
|
|
48
|
+
getUserId(req: unknown): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Verify JWT signature and claims
|
|
51
|
+
*/
|
|
52
|
+
private verifyToken;
|
|
53
|
+
}
|