@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,24 @@
|
|
|
1
|
+
import { getAccountInfo, getLinkedAccounts } from '../../account-utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Find account ID by email or alias lookup.
|
|
4
|
+
* Returns accountId if found, otherwise null.
|
|
5
|
+
*/ export async function findAccountByEmailOrAlias(store, service, emailOrAlias) {
|
|
6
|
+
const linkedAccountIds = await getLinkedAccounts(store, {
|
|
7
|
+
service
|
|
8
|
+
});
|
|
9
|
+
// Try exact email match first
|
|
10
|
+
if (linkedAccountIds.includes(emailOrAlias)) {
|
|
11
|
+
return emailOrAlias;
|
|
12
|
+
}
|
|
13
|
+
// Search by alias
|
|
14
|
+
for (const accountId of linkedAccountIds){
|
|
15
|
+
const info = await getAccountInfo(store, {
|
|
16
|
+
accountId,
|
|
17
|
+
service
|
|
18
|
+
});
|
|
19
|
+
if ((info === null || info === void 0 ? void 0 : info.alias) === emailOrAlias) {
|
|
20
|
+
return accountId;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth/src/lib/account-server/shared-utils.ts"],"sourcesContent":["import type { Keyv } from 'keyv';\nimport { getAccountInfo, getLinkedAccounts } from '../../account-utils.ts';\n\n/**\n * Find account ID by email or alias lookup.\n * Returns accountId if found, otherwise null.\n */\nexport async function findAccountByEmailOrAlias(store: Keyv, service: string, emailOrAlias: string): Promise<string | null> {\n const linkedAccountIds = await getLinkedAccounts(store, { service });\n\n // Try exact email match first\n if (linkedAccountIds.includes(emailOrAlias)) {\n return emailOrAlias;\n }\n\n // Search by alias\n for (const accountId of linkedAccountIds) {\n const info = await getAccountInfo(store, { accountId, service });\n if (info?.alias === emailOrAlias) {\n return accountId;\n }\n }\n\n return null;\n}\n"],"names":["getAccountInfo","getLinkedAccounts","findAccountByEmailOrAlias","store","service","emailOrAlias","linkedAccountIds","includes","accountId","info","alias"],"mappings":"AACA,SAASA,cAAc,EAAEC,iBAAiB,QAAQ,yBAAyB;AAE3E;;;CAGC,GACD,OAAO,eAAeC,0BAA0BC,KAAW,EAAEC,OAAe,EAAEC,YAAoB;IAChG,MAAMC,mBAAmB,MAAML,kBAAkBE,OAAO;QAAEC;IAAQ;IAElE,8BAA8B;IAC9B,IAAIE,iBAAiBC,QAAQ,CAACF,eAAe;QAC3C,OAAOA;IACT;IAEA,kBAAkB;IAClB,KAAK,MAAMG,aAAaF,iBAAkB;QACxC,MAAMG,OAAO,MAAMT,eAAeG,OAAO;YAAEK;YAAWJ;QAAQ;QAC9D,IAAIK,CAAAA,iBAAAA,2BAAAA,KAAMC,KAAK,MAAKL,cAAc;YAChC,OAAOG;QACT;IACF;IAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateless tool set for MCP OAuth mode (DCR).
|
|
3
|
+
*
|
|
4
|
+
* Use this when authentication is managed by the MCP client.
|
|
5
|
+
* Tokens are provided per-request and not stored by the server.
|
|
6
|
+
*
|
|
7
|
+
* Tools:
|
|
8
|
+
* - {service}-account-me: Show current user identity from bearer token
|
|
9
|
+
*/
|
|
10
|
+
import type { McpPrompt, McpTool } from '../../types.js';
|
|
11
|
+
import type { AccountStatelessConfig } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Create stateless mode tools.
|
|
14
|
+
* MCP client manages authentication. Server provides user identity from bearer token.
|
|
15
|
+
* Returns 1 tool: account-me.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createStateless(config: AccountStatelessConfig): {
|
|
18
|
+
tools: McpTool[];
|
|
19
|
+
prompts: McpPrompt[];
|
|
20
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateless tool set for MCP OAuth mode (DCR).
|
|
3
|
+
*
|
|
4
|
+
* Use this when authentication is managed by the MCP client.
|
|
5
|
+
* Tokens are provided per-request and not stored by the server.
|
|
6
|
+
*
|
|
7
|
+
* Tools:
|
|
8
|
+
* - {service}-account-me: Show current user identity from bearer token
|
|
9
|
+
*/ import { createAccountMe } from './me.js';
|
|
10
|
+
/**
|
|
11
|
+
* Create stateless mode tools.
|
|
12
|
+
* MCP client manages authentication. Server provides user identity from bearer token.
|
|
13
|
+
* Returns 1 tool: account-me.
|
|
14
|
+
*/ export function createStateless(config) {
|
|
15
|
+
const { service } = config;
|
|
16
|
+
// Create account-me tool for stateless mode
|
|
17
|
+
const meTools = createAccountMe({
|
|
18
|
+
service,
|
|
19
|
+
mode: 'stateless'
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
tools: meTools.tools,
|
|
23
|
+
prompts: []
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth/src/lib/account-server/stateless.ts"],"sourcesContent":["/**\n * Stateless tool set for MCP OAuth mode (DCR).\n *\n * Use this when authentication is managed by the MCP client.\n * Tokens are provided per-request and not stored by the server.\n *\n * Tools:\n * - {service}-account-me: Show current user identity from bearer token\n */\n\nimport type { McpPrompt, McpTool } from '../../types.ts';\nimport { createAccountMe } from './me.ts';\nimport type { AccountStatelessConfig } from './types.ts';\n\n/**\n * Create stateless mode tools.\n * MCP client manages authentication. Server provides user identity from bearer token.\n * Returns 1 tool: account-me.\n */\nexport function createStateless(config: AccountStatelessConfig): { tools: McpTool[]; prompts: McpPrompt[] } {\n const { service } = config;\n\n // Create account-me tool for stateless mode\n const meTools = createAccountMe({ service, mode: 'stateless' });\n\n return { tools: meTools.tools, prompts: [] };\n}\n"],"names":["createAccountMe","createStateless","config","service","meTools","mode","tools","prompts"],"mappings":"AAAA;;;;;;;;CAQC,GAGD,SAASA,eAAe,QAAQ,UAAU;AAG1C;;;;CAIC,GACD,OAAO,SAASC,gBAAgBC,MAA8B;IAC5D,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,4CAA4C;IAC5C,MAAME,UAAUJ,gBAAgB;QAAEG;QAASE,MAAM;IAAY;IAE7D,OAAO;QAAEC,OAAOF,QAAQE,KAAK;QAAEC,SAAS,EAAE;IAAC;AAC7C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration types for account tool factories.
|
|
3
|
+
*/
|
|
4
|
+
import type { Keyv } from 'keyv';
|
|
5
|
+
import type { AuthEmailProvider, Logger } from '../../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for loopback OAuth account management.
|
|
8
|
+
* Supports multiple accounts with server-managed tokens (LoopbackOAuthProvider).
|
|
9
|
+
*/
|
|
10
|
+
export interface AccountLoopbackConfig {
|
|
11
|
+
service: string;
|
|
12
|
+
store: Keyv;
|
|
13
|
+
logger: Logger;
|
|
14
|
+
auth: AuthEmailProvider;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for stateless mode.
|
|
18
|
+
* MCP client manages authentication. Server provides read-only status.
|
|
19
|
+
*/
|
|
20
|
+
export interface AccountStatelessConfig {
|
|
21
|
+
service: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Configuration for account-me tool.
|
|
25
|
+
* Works across all auth modes: loopback, stateless, device code, service account.
|
|
26
|
+
*/
|
|
27
|
+
export interface AccountMeConfig {
|
|
28
|
+
service: string;
|
|
29
|
+
store?: Keyv;
|
|
30
|
+
logger?: Logger;
|
|
31
|
+
mode: 'loopback' | 'stateless' | 'device-code' | 'service-account';
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth/src/lib/account-server/types.ts"],"sourcesContent":["/**\n * Configuration types for account tool factories.\n */\n\nimport type { Keyv } from 'keyv';\nimport type { AuthEmailProvider, Logger } from '../../types.ts';\n\n/**\n * Configuration for loopback OAuth account management.\n * Supports multiple accounts with server-managed tokens (LoopbackOAuthProvider).\n */\nexport interface AccountLoopbackConfig {\n service: string;\n store: Keyv;\n logger: Logger;\n auth: AuthEmailProvider;\n}\n\n/**\n * Configuration for stateless mode.\n * MCP client manages authentication. Server provides read-only status.\n */\nexport interface AccountStatelessConfig {\n service: string;\n}\n\n/**\n * Configuration for account-me tool.\n * Works across all auth modes: loopback, stateless, device code, service account.\n */\nexport interface AccountMeConfig {\n service: string;\n store?: Keyv;\n logger?: Logger;\n mode: 'loopback' | 'stateless' | 'device-code' | 'service-account';\n}\n"],"names":[],"mappings":"AAAA;;CAEC,GAwBD;;;CAGC,GACD,WAKC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic Client Registration (DCR) types per RFC 7591
|
|
3
|
+
*
|
|
4
|
+
* Defines core types for OAuth 2.0 Dynamic Client Registration Protocol.
|
|
5
|
+
* Used by providers to register clients dynamically with authorization servers.
|
|
6
|
+
*
|
|
7
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7591
|
|
8
|
+
*/
|
|
9
|
+
import type { Logger } from '../types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Client metadata for dynamic registration request (RFC 7591 Section 2)
|
|
12
|
+
*
|
|
13
|
+
* All fields are optional per RFC 7591. Authorization server may have
|
|
14
|
+
* required fields or default values based on policy.
|
|
15
|
+
*/
|
|
16
|
+
export interface DcrClientMetadata {
|
|
17
|
+
/** Array of redirection URI strings for redirect-based flows */
|
|
18
|
+
redirect_uris?: string[];
|
|
19
|
+
/** Client authentication method for token endpoint */
|
|
20
|
+
token_endpoint_auth_method?: 'none' | 'client_secret_post' | 'client_secret_basic';
|
|
21
|
+
/** OAuth 2.0 grant types the client may use */
|
|
22
|
+
grant_types?: string[];
|
|
23
|
+
/** OAuth 2.0 response types the client may use */
|
|
24
|
+
response_types?: string[];
|
|
25
|
+
/** Human-readable client name */
|
|
26
|
+
client_name?: string;
|
|
27
|
+
/** URL providing information about the client */
|
|
28
|
+
client_uri?: string;
|
|
29
|
+
/** URL referencing a logo for the client */
|
|
30
|
+
logo_uri?: string;
|
|
31
|
+
/** Space-separated list of scope values */
|
|
32
|
+
scope?: string;
|
|
33
|
+
/** Array of contact strings (typically email addresses) */
|
|
34
|
+
contacts?: string[];
|
|
35
|
+
/** URL pointing to terms of service document */
|
|
36
|
+
tos_uri?: string;
|
|
37
|
+
/** URL pointing to privacy policy document */
|
|
38
|
+
policy_uri?: string;
|
|
39
|
+
/** URL referencing the client's JSON Web Key Set */
|
|
40
|
+
jwks_uri?: string;
|
|
41
|
+
/** Client's JSON Web Key Set document value */
|
|
42
|
+
jwks?: object;
|
|
43
|
+
/** Unique identifier for the client software */
|
|
44
|
+
software_id?: string;
|
|
45
|
+
/** Version identifier for the client software */
|
|
46
|
+
software_version?: string;
|
|
47
|
+
/** JWT containing client metadata claims (signed software statement) */
|
|
48
|
+
software_statement?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Client information response from successful registration (RFC 7591 Section 3.2.1)
|
|
52
|
+
*
|
|
53
|
+
* Authorization server returns client credentials and echoes/modifies metadata.
|
|
54
|
+
* client_id is always returned, client_secret is optional for public clients.
|
|
55
|
+
*/
|
|
56
|
+
export interface DcrClientInformation {
|
|
57
|
+
/** REQUIRED: OAuth 2.0 client identifier string */
|
|
58
|
+
client_id: string;
|
|
59
|
+
/** OPTIONAL: OAuth 2.0 client secret (omitted for public clients) */
|
|
60
|
+
client_secret?: string;
|
|
61
|
+
/** OPTIONAL: Timestamp of client ID issuance (seconds since Unix epoch) */
|
|
62
|
+
client_id_issued_at?: number;
|
|
63
|
+
/**
|
|
64
|
+
* REQUIRED if client_secret issued: Expiration timestamp (seconds since epoch)
|
|
65
|
+
* Value of 0 indicates the secret does not expire
|
|
66
|
+
*/
|
|
67
|
+
client_secret_expires_at?: number;
|
|
68
|
+
redirect_uris?: string[];
|
|
69
|
+
token_endpoint_auth_method?: string;
|
|
70
|
+
grant_types?: string[];
|
|
71
|
+
response_types?: string[];
|
|
72
|
+
client_name?: string;
|
|
73
|
+
client_uri?: string;
|
|
74
|
+
logo_uri?: string;
|
|
75
|
+
scope?: string;
|
|
76
|
+
contacts?: string[];
|
|
77
|
+
tos_uri?: string;
|
|
78
|
+
policy_uri?: string;
|
|
79
|
+
jwks_uri?: string;
|
|
80
|
+
jwks?: object;
|
|
81
|
+
software_id?: string;
|
|
82
|
+
software_version?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Provider tokens for stateless DCR pattern
|
|
86
|
+
*
|
|
87
|
+
* In stateless mode, DCR provider receives provider credentials from context
|
|
88
|
+
* rather than managing token storage. Used for MCP server deployments where
|
|
89
|
+
* client manages all tokens.
|
|
90
|
+
*/
|
|
91
|
+
export interface ProviderTokens {
|
|
92
|
+
/** OAuth 2.0 access token for provider API calls */
|
|
93
|
+
accessToken: string;
|
|
94
|
+
/** Optional refresh token for token renewal */
|
|
95
|
+
refreshToken?: string;
|
|
96
|
+
/** Token expiration timestamp (seconds since Unix epoch) */
|
|
97
|
+
expiresAt?: number;
|
|
98
|
+
/** Space-separated list of granted scopes */
|
|
99
|
+
scope?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Configuration for DCR provider initialization
|
|
103
|
+
*
|
|
104
|
+
* Minimal config for creating DCR provider instances. Additional provider-specific
|
|
105
|
+
* config (client IDs, secrets, redirect URIs) handled by concrete implementations.
|
|
106
|
+
*/
|
|
107
|
+
export interface DcrConfig {
|
|
108
|
+
/** Authorization server's registration endpoint URL */
|
|
109
|
+
registrationEndpoint: string;
|
|
110
|
+
/** Client metadata to register with authorization server */
|
|
111
|
+
metadata: DcrClientMetadata;
|
|
112
|
+
/** Optional logger for DCR operations */
|
|
113
|
+
logger?: Logger;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* DCR error response per RFC 7591 Section 3.2.2
|
|
117
|
+
*
|
|
118
|
+
* Authorization server returns HTTP 400 with error details when
|
|
119
|
+
* registration fails due to invalid metadata or policy violations.
|
|
120
|
+
*/
|
|
121
|
+
export interface DcrErrorResponse {
|
|
122
|
+
/** REQUIRED: Single ASCII error code string */
|
|
123
|
+
error: 'invalid_redirect_uri' | 'invalid_client_metadata' | 'invalid_software_statement' | 'unapproved_software_statement' | string;
|
|
124
|
+
/** OPTIONAL: Human-readable ASCII description */
|
|
125
|
+
error_description?: string;
|
|
126
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic Client Registration (DCR) types per RFC 7591
|
|
3
|
+
*
|
|
4
|
+
* Defines core types for OAuth 2.0 Dynamic Client Registration Protocol.
|
|
5
|
+
* Used by providers to register clients dynamically with authorization servers.
|
|
6
|
+
*
|
|
7
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7591
|
|
8
|
+
*/ /**
|
|
9
|
+
* DCR error response per RFC 7591 Section 3.2.2
|
|
10
|
+
*
|
|
11
|
+
* Authorization server returns HTTP 400 with error details when
|
|
12
|
+
* registration fails due to invalid metadata or policy violations.
|
|
13
|
+
*/ export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth/src/lib/dcr-types.ts"],"sourcesContent":["/**\n * Dynamic Client Registration (DCR) types per RFC 7591\n *\n * Defines core types for OAuth 2.0 Dynamic Client Registration Protocol.\n * Used by providers to register clients dynamically with authorization servers.\n *\n * @see https://datatracker.ietf.org/doc/html/rfc7591\n */\n\nimport type { Logger } from '../types.ts';\n\n/**\n * Client metadata for dynamic registration request (RFC 7591 Section 2)\n *\n * All fields are optional per RFC 7591. Authorization server may have\n * required fields or default values based on policy.\n */\nexport interface DcrClientMetadata {\n /** Array of redirection URI strings for redirect-based flows */\n redirect_uris?: string[];\n\n /** Client authentication method for token endpoint */\n token_endpoint_auth_method?: 'none' | 'client_secret_post' | 'client_secret_basic';\n\n /** OAuth 2.0 grant types the client may use */\n grant_types?: string[];\n\n /** OAuth 2.0 response types the client may use */\n response_types?: string[];\n\n /** Human-readable client name */\n client_name?: string;\n\n /** URL providing information about the client */\n client_uri?: string;\n\n /** URL referencing a logo for the client */\n logo_uri?: string;\n\n /** Space-separated list of scope values */\n scope?: string;\n\n /** Array of contact strings (typically email addresses) */\n contacts?: string[];\n\n /** URL pointing to terms of service document */\n tos_uri?: string;\n\n /** URL pointing to privacy policy document */\n policy_uri?: string;\n\n /** URL referencing the client's JSON Web Key Set */\n jwks_uri?: string;\n\n /** Client's JSON Web Key Set document value */\n jwks?: object;\n\n /** Unique identifier for the client software */\n software_id?: string;\n\n /** Version identifier for the client software */\n software_version?: string;\n\n /** JWT containing client metadata claims (signed software statement) */\n software_statement?: string;\n}\n\n/**\n * Client information response from successful registration (RFC 7591 Section 3.2.1)\n *\n * Authorization server returns client credentials and echoes/modifies metadata.\n * client_id is always returned, client_secret is optional for public clients.\n */\nexport interface DcrClientInformation {\n /** REQUIRED: OAuth 2.0 client identifier string */\n client_id: string;\n\n /** OPTIONAL: OAuth 2.0 client secret (omitted for public clients) */\n client_secret?: string;\n\n /** OPTIONAL: Timestamp of client ID issuance (seconds since Unix epoch) */\n client_id_issued_at?: number;\n\n /**\n * REQUIRED if client_secret issued: Expiration timestamp (seconds since epoch)\n * Value of 0 indicates the secret does not expire\n */\n client_secret_expires_at?: number;\n\n // All registered metadata fields (echoed or server-modified)\n redirect_uris?: string[];\n token_endpoint_auth_method?: string;\n grant_types?: string[];\n response_types?: string[];\n client_name?: string;\n client_uri?: string;\n logo_uri?: string;\n scope?: string;\n contacts?: string[];\n tos_uri?: string;\n policy_uri?: string;\n jwks_uri?: string;\n jwks?: object;\n software_id?: string;\n software_version?: string;\n}\n\n/**\n * Provider tokens for stateless DCR pattern\n *\n * In stateless mode, DCR provider receives provider credentials from context\n * rather than managing token storage. Used for MCP server deployments where\n * client manages all tokens.\n */\nexport interface ProviderTokens {\n /** OAuth 2.0 access token for provider API calls */\n accessToken: string;\n\n /** Optional refresh token for token renewal */\n refreshToken?: string;\n\n /** Token expiration timestamp (seconds since Unix epoch) */\n expiresAt?: number;\n\n /** Space-separated list of granted scopes */\n scope?: string;\n}\n\n/**\n * Configuration for DCR provider initialization\n *\n * Minimal config for creating DCR provider instances. Additional provider-specific\n * config (client IDs, secrets, redirect URIs) handled by concrete implementations.\n */\nexport interface DcrConfig {\n /** Authorization server's registration endpoint URL */\n registrationEndpoint: string;\n\n /** Client metadata to register with authorization server */\n metadata: DcrClientMetadata;\n\n /** Optional logger for DCR operations */\n logger?: Logger;\n}\n\n/**\n * DCR error response per RFC 7591 Section 3.2.2\n *\n * Authorization server returns HTTP 400 with error details when\n * registration fails due to invalid metadata or policy violations.\n */\nexport interface DcrErrorResponse {\n /** REQUIRED: Single ASCII error code string */\n error: 'invalid_redirect_uri' | 'invalid_client_metadata' | 'invalid_software_statement' | 'unapproved_software_statement' | string;\n\n /** OPTIONAL: Human-readable ASCII description */\n error_description?: string;\n}\n"],"names":[],"mappings":"AAAA;;;;;;;CAOC,GA0ID;;;;;CAKC,GACD,WAMC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC 8414 Authorization Server Metadata
|
|
3
|
+
* @see https://www.rfc-editor.org/rfc/rfc8414.html
|
|
4
|
+
*/
|
|
5
|
+
export interface RFC8414Metadata {
|
|
6
|
+
/** Authorization server issuer URL */
|
|
7
|
+
issuer: string;
|
|
8
|
+
/** OAuth 2.0 authorization endpoint */
|
|
9
|
+
authorization_endpoint: string;
|
|
10
|
+
/** OAuth 2.0 token endpoint */
|
|
11
|
+
token_endpoint: string;
|
|
12
|
+
/** Dynamic Client Registration endpoint (RFC 7591) */
|
|
13
|
+
registration_endpoint: string;
|
|
14
|
+
/** Optional: Token revocation endpoint */
|
|
15
|
+
revocation_endpoint?: string;
|
|
16
|
+
/** Optional: Supported OAuth scopes */
|
|
17
|
+
scopes_supported?: string[];
|
|
18
|
+
/** Optional: Supported response types */
|
|
19
|
+
response_types_supported?: string[];
|
|
20
|
+
/** Optional: Supported grant types */
|
|
21
|
+
grant_types_supported?: string[];
|
|
22
|
+
/** Optional: Supported token endpoint auth methods */
|
|
23
|
+
token_endpoint_auth_methods_supported?: string[];
|
|
24
|
+
/** Optional: Supported PKCE code challenge methods (RFC 7636) */
|
|
25
|
+
code_challenge_methods_supported?: string[];
|
|
26
|
+
/** Optional: Service documentation URL */
|
|
27
|
+
service_documentation?: string;
|
|
28
|
+
/** Allow additional provider-specific fields */
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* RFC 9728 Protected Resource Metadata
|
|
33
|
+
* @see https://www.rfc-editor.org/rfc/rfc9728.html
|
|
34
|
+
*/
|
|
35
|
+
export interface RFC9728Metadata {
|
|
36
|
+
/** Protected resource URL */
|
|
37
|
+
resource: string;
|
|
38
|
+
/** List of authorization servers that can issue tokens for this resource */
|
|
39
|
+
authorization_servers: string[];
|
|
40
|
+
/** OAuth scopes supported by this resource */
|
|
41
|
+
scopes_supported: string[];
|
|
42
|
+
/** Methods for providing bearer tokens (typically ['header']) */
|
|
43
|
+
bearer_methods_supported: string[];
|
|
44
|
+
/** Allow additional provider-specific fields */
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth/src/lib/rfc-metadata-types.ts"],"sourcesContent":["/**\n * RFC 8414 Authorization Server Metadata\n * @see https://www.rfc-editor.org/rfc/rfc8414.html\n */\nexport interface RFC8414Metadata {\n /** Authorization server issuer URL */\n issuer: string;\n /** OAuth 2.0 authorization endpoint */\n authorization_endpoint: string;\n /** OAuth 2.0 token endpoint */\n token_endpoint: string;\n /** Dynamic Client Registration endpoint (RFC 7591) */\n registration_endpoint: string;\n /** Optional: Token revocation endpoint */\n revocation_endpoint?: string;\n /** Optional: Supported OAuth scopes */\n scopes_supported?: string[];\n /** Optional: Supported response types */\n response_types_supported?: string[];\n /** Optional: Supported grant types */\n grant_types_supported?: string[];\n /** Optional: Supported token endpoint auth methods */\n token_endpoint_auth_methods_supported?: string[];\n /** Optional: Supported PKCE code challenge methods (RFC 7636) */\n code_challenge_methods_supported?: string[];\n /** Optional: Service documentation URL */\n service_documentation?: string;\n /** Allow additional provider-specific fields */\n [key: string]: unknown;\n}\n\n/**\n * RFC 9728 Protected Resource Metadata\n * @see https://www.rfc-editor.org/rfc/rfc9728.html\n */\nexport interface RFC9728Metadata {\n /** Protected resource URL */\n resource: string;\n /** List of authorization servers that can issue tokens for this resource */\n authorization_servers: string[];\n /** OAuth scopes supported by this resource */\n scopes_supported: string[];\n /** Methods for providing bearer tokens (typically ['header']) */\n bearer_methods_supported: string[];\n /** Allow additional provider-specific fields */\n [key: string]: unknown;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GA4BD;;;CAGC,GACD,WAWC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PKCE (Proof Key for Code Exchange) utilities for OAuth 2.0
|
|
3
|
+
*
|
|
4
|
+
* Implements RFC 7636 PKCE extension for public OAuth clients.
|
|
5
|
+
* Generates cryptographically secure code verifier and challenge.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* PKCE code verifier and challenge pair
|
|
9
|
+
*/
|
|
10
|
+
export interface PKCEPair {
|
|
11
|
+
/** Code verifier - random string sent to token endpoint */
|
|
12
|
+
verifier: string;
|
|
13
|
+
/** Code challenge - SHA256 hash of verifier sent to authorization endpoint */
|
|
14
|
+
challenge: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generate PKCE code verifier and challenge pair
|
|
18
|
+
*
|
|
19
|
+
* Uses SHA-256 hashing (S256 method) as recommended by RFC 7636.
|
|
20
|
+
* Code verifier is 32 random bytes base64url-encoded (43 characters).
|
|
21
|
+
*
|
|
22
|
+
* @returns PKCE pair with verifier and challenge
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const { verifier, challenge } = generatePKCE();
|
|
27
|
+
*
|
|
28
|
+
* // Use challenge in authorization URL
|
|
29
|
+
* authUrl.searchParams.set('code_challenge', challenge);
|
|
30
|
+
* authUrl.searchParams.set('code_challenge_method', 'S256');
|
|
31
|
+
*
|
|
32
|
+
* // Later, use verifier in token exchange
|
|
33
|
+
* tokenParams.code_verifier = verifier;
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function generatePKCE(): PKCEPair;
|
package/dist/esm/pkce.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PKCE (Proof Key for Code Exchange) utilities for OAuth 2.0
|
|
3
|
+
*
|
|
4
|
+
* Implements RFC 7636 PKCE extension for public OAuth clients.
|
|
5
|
+
* Generates cryptographically secure code verifier and challenge.
|
|
6
|
+
*/ import { createHash, randomBytes } from 'crypto';
|
|
7
|
+
/**
|
|
8
|
+
* Generate PKCE code verifier and challenge pair
|
|
9
|
+
*
|
|
10
|
+
* Uses SHA-256 hashing (S256 method) as recommended by RFC 7636.
|
|
11
|
+
* Code verifier is 32 random bytes base64url-encoded (43 characters).
|
|
12
|
+
*
|
|
13
|
+
* @returns PKCE pair with verifier and challenge
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const { verifier, challenge } = generatePKCE();
|
|
18
|
+
*
|
|
19
|
+
* // Use challenge in authorization URL
|
|
20
|
+
* authUrl.searchParams.set('code_challenge', challenge);
|
|
21
|
+
* authUrl.searchParams.set('code_challenge_method', 'S256');
|
|
22
|
+
*
|
|
23
|
+
* // Later, use verifier in token exchange
|
|
24
|
+
* tokenParams.code_verifier = verifier;
|
|
25
|
+
* ```
|
|
26
|
+
*/ export function generatePKCE() {
|
|
27
|
+
const verifier = randomBytes(32).toString('base64url');
|
|
28
|
+
const challenge = createHash('sha256').update(verifier).digest('base64url');
|
|
29
|
+
return {
|
|
30
|
+
verifier,
|
|
31
|
+
challenge
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/oauth/oauth/src/pkce.ts"],"sourcesContent":["/**\n * PKCE (Proof Key for Code Exchange) utilities for OAuth 2.0\n *\n * Implements RFC 7636 PKCE extension for public OAuth clients.\n * Generates cryptographically secure code verifier and challenge.\n */\n\nimport { createHash, randomBytes } from 'crypto';\n\n/**\n * PKCE code verifier and challenge pair\n */\nexport interface PKCEPair {\n /** Code verifier - random string sent to token endpoint */\n verifier: string;\n /** Code challenge - SHA256 hash of verifier sent to authorization endpoint */\n challenge: string;\n}\n\n/**\n * Generate PKCE code verifier and challenge pair\n *\n * Uses SHA-256 hashing (S256 method) as recommended by RFC 7636.\n * Code verifier is 32 random bytes base64url-encoded (43 characters).\n *\n * @returns PKCE pair with verifier and challenge\n *\n * @example\n * ```typescript\n * const { verifier, challenge } = generatePKCE();\n *\n * // Use challenge in authorization URL\n * authUrl.searchParams.set('code_challenge', challenge);\n * authUrl.searchParams.set('code_challenge_method', 'S256');\n *\n * // Later, use verifier in token exchange\n * tokenParams.code_verifier = verifier;\n * ```\n */\nexport function generatePKCE(): PKCEPair {\n const verifier = randomBytes(32).toString('base64url');\n const challenge = createHash('sha256').update(verifier).digest('base64url');\n\n return {\n verifier,\n challenge,\n };\n}\n"],"names":["createHash","randomBytes","generatePKCE","verifier","toString","challenge","update","digest"],"mappings":"AAAA;;;;;CAKC,GAED,SAASA,UAAU,EAAEC,WAAW,QAAQ,SAAS;AAYjD;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASC;IACd,MAAMC,WAAWF,YAAY,IAAIG,QAAQ,CAAC;IAC1C,MAAMC,YAAYL,WAAW,UAAUM,MAAM,CAACH,UAAUI,MAAM,CAAC;IAE/D,OAAO;QACLJ;QACAE;IACF;AACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data sanitization utilities for secure logging.
|
|
3
|
+
* Redacts sensitive OAuth tokens, API keys, and credentials from log output.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* sanitizeData({ accountId: 'test@example.com', access_token: 'secret_token_value' })
|
|
8
|
+
* // { accountId: 'test@example.com', access_token: 'secr****alue' }
|
|
9
|
+
*
|
|
10
|
+
* sanitizeForLogging('Processing token', { token: 'secret_value' })
|
|
11
|
+
* // { message: 'Processing token', meta: { token: 'secr****alue' } }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function sanitizeData(data: unknown): unknown;
|
|
15
|
+
/**
|
|
16
|
+
* Prevent log injection attacks by escaping control characters
|
|
17
|
+
* SECURITY: Critical for preventing CRLF injection (OWASP A03)
|
|
18
|
+
*/
|
|
19
|
+
export declare function sanitizeLogMessage(message: string, maxLength?: number): string;
|
|
20
|
+
/**
|
|
21
|
+
* Sanitize log message and metadata for safe logging
|
|
22
|
+
* Applies both CRLF protection and sensitive data redaction
|
|
23
|
+
*
|
|
24
|
+
* @param message - The log message to sanitize
|
|
25
|
+
* @param meta - Optional metadata object to sanitize
|
|
26
|
+
* @param enableDataSanitization - Whether to apply sensitive data redaction (default: true)
|
|
27
|
+
* @returns Sanitized message and metadata ready for logging
|
|
28
|
+
*/
|
|
29
|
+
export declare function sanitizeForLogging(message: string, meta?: Record<string, unknown>, enableDataSanitization?: boolean): {
|
|
30
|
+
message: string;
|
|
31
|
+
meta: Record<string, unknown>;
|
|
32
|
+
};
|
|
33
|
+
export declare function sanitizeForLoggingFormatter(): {
|
|
34
|
+
log: (obj: any) => {
|
|
35
|
+
msg: string;
|
|
36
|
+
};
|
|
37
|
+
};
|