@stdiobus/workers-registry 1.4.14 → 1.5.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +181 -21
  2. package/out/dist/workers-registry/acp-registry/index.js +128 -2
  3. package/out/dist/workers-registry/acp-registry/index.js.map +4 -4
  4. package/out/dist/workers-registry/acp-worker/index.js +1 -3
  5. package/out/dist/workers-registry/acp-worker/index.js.map +4 -4
  6. package/out/dist/workers-registry/index.d.ts +1 -0
  7. package/out/dist/workers-registry/index.js +6 -0
  8. package/out/dist/workers-registry/openai-agent/index.js +1 -1
  9. package/out/dist/workers-registry/openai-agent/index.js.map +2 -2
  10. package/out/dist/workers-registry/registry-launcher/index.js +131 -0
  11. package/out/dist/workers-registry/registry-launcher/index.js.map +7 -0
  12. package/out/tsc/workers-registry/acp-worker/src/index.d.ts +0 -10
  13. package/out/tsc/workers-registry/registry-launcher/src/auth/auth-manager.d.ts +392 -0
  14. package/out/tsc/workers-registry/registry-launcher/src/auth/cli/cli.property.test.d.ts +22 -0
  15. package/out/tsc/workers-registry/registry-launcher/src/auth/cli/index.d.ts +9 -0
  16. package/out/tsc/workers-registry/registry-launcher/src/auth/cli/login-command.d.ts +32 -0
  17. package/out/tsc/workers-registry/registry-launcher/src/auth/cli/logout-command.d.ts +25 -0
  18. package/out/tsc/workers-registry/registry-launcher/src/auth/cli/setup-command.d.ts +25 -0
  19. package/out/tsc/workers-registry/registry-launcher/src/auth/cli/status-command.d.ts +21 -0
  20. package/out/tsc/workers-registry/registry-launcher/src/auth/errors.d.ts +190 -0
  21. package/out/tsc/workers-registry/registry-launcher/src/auth/flows/agent-auth-flow.d.ts +146 -0
  22. package/out/tsc/workers-registry/registry-launcher/src/auth/flows/callback-server.d.ts +131 -0
  23. package/out/tsc/workers-registry/registry-launcher/src/auth/flows/callback-server.test.d.ts +1 -0
  24. package/out/tsc/workers-registry/registry-launcher/src/auth/flows/index.d.ts +11 -0
  25. package/out/tsc/workers-registry/registry-launcher/src/auth/flows/terminal-auth-flow.d.ts +252 -0
  26. package/out/tsc/workers-registry/registry-launcher/src/auth/flows/terminal-auth-flow.test.d.ts +1 -0
  27. package/out/tsc/workers-registry/registry-launcher/src/auth/index.d.ts +33 -0
  28. package/out/tsc/workers-registry/registry-launcher/src/auth/integration.test.d.ts +1 -0
  29. package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/anthropic-api-key.d.ts +154 -0
  30. package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/index.d.ts +20 -0
  31. package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/model-credentials.test.d.ts +1 -0
  32. package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/openai-api-key.d.ts +182 -0
  33. package/out/tsc/workers-registry/registry-launcher/src/auth/model-credentials/types.d.ts +186 -0
  34. package/out/tsc/workers-registry/registry-launcher/src/auth/pkce.d.ts +61 -0
  35. package/out/tsc/workers-registry/registry-launcher/src/auth/pkce.property.test.d.ts +1 -0
  36. package/out/tsc/workers-registry/registry-launcher/src/auth/pkce.test.d.ts +1 -0
  37. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/base-provider.d.ts +138 -0
  38. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/base-provider.test.d.ts +1 -0
  39. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/cognito-provider.d.ts +44 -0
  40. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/concrete-providers.test.d.ts +1 -0
  41. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/entra-provider.d.ts +54 -0
  42. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/github-provider.d.ts +19 -0
  43. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/google-provider.d.ts +19 -0
  44. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/index.d.ts +107 -0
  45. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/index.test.d.ts +1 -0
  46. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/oidc-provider.d.ts +413 -0
  47. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/oidc-provider.property.test.d.ts +1 -0
  48. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/oidc-provider.test.d.ts +1 -0
  49. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/providers.property.test.d.ts +1 -0
  50. package/out/tsc/workers-registry/registry-launcher/src/auth/providers/types.d.ts +28 -0
  51. package/out/tsc/workers-registry/registry-launcher/src/auth/session.d.ts +251 -0
  52. package/out/tsc/workers-registry/registry-launcher/src/auth/session.property.test.d.ts +1 -0
  53. package/out/tsc/workers-registry/registry-launcher/src/auth/session.test.d.ts +1 -0
  54. package/out/tsc/workers-registry/registry-launcher/src/auth/state.d.ts +26 -0
  55. package/out/tsc/workers-registry/registry-launcher/src/auth/state.property.test.d.ts +1 -0
  56. package/out/tsc/workers-registry/registry-launcher/src/auth/state.test.d.ts +1 -0
  57. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/credential-store.d.ts +98 -0
  58. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/credential-store.test.d.ts +1 -0
  59. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/encrypted-file-backend.d.ts +101 -0
  60. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/encrypted-file-backend.test.d.ts +1 -0
  61. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/index.d.ts +12 -0
  62. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/keychain-backend.d.ts +80 -0
  63. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/keychain-backend.test.d.ts +1 -0
  64. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/memory-backend.d.ts +54 -0
  65. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/storage.property.test.d.ts +1 -0
  66. package/out/tsc/workers-registry/registry-launcher/src/auth/storage/types.d.ts +44 -0
  67. package/out/tsc/workers-registry/registry-launcher/src/auth/token-manager.d.ts +171 -0
  68. package/out/tsc/workers-registry/registry-launcher/src/auth/token-manager.property.test.d.ts +1 -0
  69. package/out/tsc/workers-registry/registry-launcher/src/auth/token-manager.test.d.ts +1 -0
  70. package/out/tsc/workers-registry/registry-launcher/src/auth/types.d.ts +369 -0
  71. package/out/tsc/workers-registry/registry-launcher/src/auth/types.test.d.ts +1 -0
  72. package/out/tsc/workers-registry/registry-launcher/src/config/config.property.test.d.ts +1 -0
  73. package/out/tsc/workers-registry/registry-launcher/src/config/config.test.d.ts +1 -0
  74. package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/registry/index.d.ts +51 -2
  75. package/out/tsc/workers-registry/registry-launcher/src/registry/index.property.test.d.ts +1 -0
  76. package/out/tsc/workers-registry/registry-launcher/src/registry/index.test.d.ts +1 -0
  77. package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/registry/types.d.ts +24 -0
  78. package/out/tsc/workers-registry/registry-launcher/src/router/message-router.d.ts +770 -0
  79. package/out/tsc/workers-registry/registry-launcher/src/router/message-router.property.test.d.ts +1 -0
  80. package/out/tsc/workers-registry/registry-launcher/src/router/message-router.test.d.ts +1 -0
  81. package/out/tsc/workers-registry/registry-launcher/src/runtime/manager.property.test.d.ts +1 -0
  82. package/out/tsc/workers-registry/registry-launcher/src/runtime/manager.test.d.ts +1 -0
  83. package/out/tsc/workers-registry/registry-launcher/src/stream/ndjson-handler.property.test.d.ts +1 -0
  84. package/out/tsc/workers-registry/registry-launcher/src/stream/ndjson-handler.test.d.ts +1 -0
  85. package/out/tsc/workers-registry/registry-launcher/tests/e2e/auth-flow.e2e.test.d.ts +1 -0
  86. package/out/tsc/workers-registry/registry-launcher/tests/e2e/auth-required-flow.e2e.test.d.ts +1 -0
  87. package/out/tsc/workers-registry/registry-launcher/tests/e2e/helpers/api-keys.d.ts +32 -0
  88. package/out/tsc/workers-registry/registry-launcher/tests/e2e/helpers/index.d.ts +17 -0
  89. package/out/tsc/workers-registry/registry-launcher/tests/e2e/helpers/launcher-harness.d.ts +101 -0
  90. package/out/tsc/workers-registry/registry-launcher/tests/e2e/helpers/registry-server.d.ts +46 -0
  91. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-agent-auth.e2e.test.d.ts +1 -0
  92. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-api-keys.e2e.test.d.ts +1 -0
  93. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-auth-required.e2e.test.d.ts +1 -0
  94. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-cli.e2e.test.d.ts +1 -0
  95. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-concurrent.e2e.test.d.ts +1 -0
  96. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-lifecycle.e2e.test.d.ts +1 -0
  97. package/out/tsc/workers-registry/registry-launcher/tests/e2e/production-terminal-auth.e2e.test.d.ts +1 -0
  98. package/out/tsc/workers-registry/registry-launcher/tests/integration/agent-auth.integration.test.d.ts +9 -0
  99. package/out/tsc/workers-registry/registry-launcher/tests/integration/registry-launcher.test.d.ts +1 -0
  100. package/out/tsc/workers-registry/registry-launcher/tests/integration/terminal-auth.integration.test.d.ts +12 -0
  101. package/package.json +16 -11
  102. package/out/tsc/workers-registry/acp-worker/src/registry-launcher/router/message-router.d.ts +0 -199
  103. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/config/config.property.test.d.ts → registry-launcher/src/auth/auth-manager.property.test.d.ts} +0 -0
  104. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/config/config.test.d.ts → registry-launcher/src/auth/auth-manager.test.d.ts} +0 -0
  105. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/registry/index.property.test.d.ts → registry-launcher/src/auth/cli/cli.test.d.ts} +0 -0
  106. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/registry/index.test.d.ts → registry-launcher/src/auth/cli/login-command.test.d.ts} +0 -0
  107. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/router/message-router.property.test.d.ts → registry-launcher/src/auth/cli/provider-config.test.d.ts} +0 -0
  108. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/router/message-router.test.d.ts → registry-launcher/src/auth/cli/setup-command.test.d.ts} +0 -0
  109. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/runtime/manager.property.test.d.ts → registry-launcher/src/auth/cli/status-command.test.d.ts} +0 -0
  110. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/runtime/manager.test.d.ts → registry-launcher/src/auth/errors.property.test.d.ts} +0 -0
  111. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/stream/ndjson-handler.property.test.d.ts → registry-launcher/src/auth/errors.test.d.ts} +0 -0
  112. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher/stream/ndjson-handler.test.d.ts → registry-launcher/src/auth/flows/agent-auth-flow.test.d.ts} +0 -0
  113. /package/out/tsc/workers-registry/{acp-worker/tests/integration/registry-launcher.test.d.ts → registry-launcher/src/auth/flows/callback-server.property.test.d.ts} +0 -0
  114. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/config/api-keys.d.ts +0 -0
  115. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/config/config.d.ts +0 -0
  116. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/config/index.d.ts +0 -0
  117. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/config/types.d.ts +0 -0
  118. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/index.d.ts +0 -0
  119. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/log.d.ts +0 -0
  120. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/log.test.d.ts +0 -0
  121. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/registry/resolver.d.ts +0 -0
  122. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/router/index.d.ts +0 -0
  123. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/runtime/agent-runtime.d.ts +0 -0
  124. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/runtime/index.d.ts +0 -0
  125. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/runtime/manager.d.ts +0 -0
  126. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/runtime/types.d.ts +0 -0
  127. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/stream/index.d.ts +0 -0
  128. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/stream/ndjson-handler.d.ts +0 -0
  129. /package/out/tsc/workers-registry/{acp-worker/src/registry-launcher → registry-launcher/src}/test-utils/index.d.ts +0 -0
@@ -0,0 +1,413 @@
1
+ import { BaseAuthProvider } from './base-provider.js';
2
+ import type { TokenResponse } from '../types.js';
3
+ /**
4
+ * JSON Web Key (JWK) structure for RSA keys.
5
+ */
6
+ export interface JWK {
7
+ /** Key type (e.g., 'RSA') */
8
+ kty: string;
9
+ /** Key ID - used to match keys in JWKS */
10
+ kid?: string;
11
+ /** Algorithm (e.g., 'RS256') */
12
+ alg?: string;
13
+ /** Key use (e.g., 'sig' for signature) */
14
+ use?: string;
15
+ /** RSA modulus (base64url encoded) */
16
+ n?: string;
17
+ /** RSA exponent (base64url encoded) */
18
+ e?: string;
19
+ /** X.509 certificate chain */
20
+ x5c?: string[];
21
+ }
22
+ /**
23
+ * JSON Web Key Set (JWKS) structure.
24
+ */
25
+ export interface JWKS {
26
+ /** Array of JSON Web Keys */
27
+ keys: JWK[];
28
+ }
29
+ /**
30
+ * Cached JWKS with metadata.
31
+ */
32
+ export interface CachedJWKS {
33
+ /** The JWKS data */
34
+ jwks: JWKS;
35
+ /** Timestamp when the JWKS was fetched */
36
+ fetchedAt: number;
37
+ /** TTL in milliseconds */
38
+ ttlMs: number;
39
+ }
40
+ /**
41
+ * Decoded JWT header.
42
+ */
43
+ export interface JWTHeader {
44
+ /** Algorithm used for signing */
45
+ alg: string;
46
+ /** Token type (usually 'JWT') */
47
+ typ?: string;
48
+ /** Key ID - used to find the signing key in JWKS */
49
+ kid?: string;
50
+ }
51
+ /**
52
+ * ID Token claims structure.
53
+ * Requirements: 7a.5
54
+ */
55
+ export interface IDTokenClaims {
56
+ /** Issuer - must match the configured issuer */
57
+ iss: string;
58
+ /** Subject - unique identifier for the user */
59
+ sub: string;
60
+ /** Audience - must contain the client_id */
61
+ aud: string | string[];
62
+ /** Expiration time (Unix timestamp) */
63
+ exp: number;
64
+ /** Issued at time (Unix timestamp) */
65
+ iat: number;
66
+ /** Nonce - if provided in auth request, must match */
67
+ nonce?: string;
68
+ /** Authentication time */
69
+ auth_time?: number;
70
+ /** Access token hash */
71
+ at_hash?: string;
72
+ /** Additional claims */
73
+ [key: string]: unknown;
74
+ }
75
+ /**
76
+ * Result of ID token validation.
77
+ */
78
+ export interface IDTokenValidationResult {
79
+ /** Whether validation was successful */
80
+ valid: boolean;
81
+ /** The decoded claims if valid */
82
+ claims?: IDTokenClaims;
83
+ /** Error message if validation failed */
84
+ error?: string;
85
+ }
86
+ /**
87
+ * Options for ID token validation.
88
+ */
89
+ export interface IDTokenValidationOptions {
90
+ /** Expected audience (client_id) */
91
+ audience: string;
92
+ /** Expected nonce (if used in auth request) */
93
+ nonce?: string;
94
+ /** Clock skew tolerance in seconds (default: 60) */
95
+ clockSkewSeconds?: number;
96
+ }
97
+ /**
98
+ * OIDC Discovery document structure.
99
+ * Contains the endpoints and capabilities advertised by the OIDC provider.
100
+ */
101
+ export interface OIDCDiscoveryDocument {
102
+ /** The issuer identifier (must match the issuer URL) */
103
+ issuer: string;
104
+ /** URL of the authorization endpoint */
105
+ authorization_endpoint: string;
106
+ /** URL of the token endpoint */
107
+ token_endpoint: string;
108
+ /** URL of the JWKS endpoint for token validation */
109
+ jwks_uri?: string;
110
+ /** URL of the userinfo endpoint */
111
+ userinfo_endpoint?: string;
112
+ /** Supported response types */
113
+ response_types_supported?: string[];
114
+ /** Supported grant types */
115
+ grant_types_supported?: string[];
116
+ /** Supported scopes */
117
+ scopes_supported?: string[];
118
+ /** Supported token endpoint authentication methods */
119
+ token_endpoint_auth_methods_supported?: string[];
120
+ /** Supported code challenge methods for PKCE */
121
+ code_challenge_methods_supported?: string[];
122
+ }
123
+ /**
124
+ * Configuration options for OIDC provider.
125
+ */
126
+ export interface OIDCProviderConfig {
127
+ /**
128
+ * The OIDC issuer URL (e.g., 'https://auth.example.com').
129
+ * Used for discovery via {issuer}/.well-known/openid-configuration.
130
+ */
131
+ issuer: string;
132
+ /**
133
+ * Manual override for authorization endpoint.
134
+ * Used when discovery is unavailable.
135
+ * Requirements: 7a.2
136
+ */
137
+ authorizationEndpoint?: string;
138
+ /**
139
+ * Manual override for token endpoint.
140
+ * Used when discovery is unavailable.
141
+ * Requirements: 7a.2
142
+ */
143
+ tokenEndpoint?: string;
144
+ /**
145
+ * Manual override for JWKS URI.
146
+ * Used for token validation when discovery is unavailable.
147
+ */
148
+ jwksUri?: string;
149
+ /** OAuth client ID */
150
+ clientId?: string;
151
+ /** OAuth client secret (optional, for confidential clients) */
152
+ clientSecret?: string;
153
+ /**
154
+ * Token endpoint authentication method.
155
+ * Supported: 'client_secret_post', 'client_secret_basic'
156
+ * Default: 'client_secret_post'
157
+ * Requirements: 7a.7
158
+ */
159
+ tokenEndpointAuthMethod?: 'client_secret_post' | 'client_secret_basic';
160
+ /**
161
+ * Custom scopes to use instead of defaults.
162
+ * Default: ['openid', 'profile']
163
+ */
164
+ scopes?: string[];
165
+ /**
166
+ * Whether to skip discovery and use manual endpoints only.
167
+ * Default: false (discovery is attempted first)
168
+ */
169
+ skipDiscovery?: boolean;
170
+ /**
171
+ * Timeout for discovery request in milliseconds.
172
+ * Default: 10000 (10 seconds)
173
+ */
174
+ discoveryTimeoutMs?: number;
175
+ }
176
+ /**
177
+ * Result of OIDC discovery operation.
178
+ */
179
+ export interface OIDCDiscoveryResult {
180
+ /** Whether discovery was successful */
181
+ success: boolean;
182
+ /** The discovery document if successful */
183
+ document?: OIDCDiscoveryDocument;
184
+ /** Error message if discovery failed */
185
+ error?: string;
186
+ }
187
+ /**
188
+ * Generic OIDC Discovery provider.
189
+ *
190
+ * Supports any OIDC-compliant provider (Auth0, Okta, Keycloak, etc.)
191
+ * via issuer-based discovery with manual endpoint override fallback.
192
+ *
193
+ * Features:
194
+ * - Automatic discovery via .well-known/openid-configuration
195
+ * - Manual endpoint override when discovery unavailable
196
+ * - PKCE S256 enforcement (per Requirement 7a.3)
197
+ * - Cached discovery document
198
+ * - Support for client_secret_post and client_secret_basic auth methods
199
+ *
200
+ * Default scopes: openid, profile
201
+ * Token injection: Bearer header
202
+ *
203
+ * Requirements: 7a.1, 7a.2, 7a.3, 7a.7
204
+ */
205
+ export declare class OIDCProvider extends BaseAuthProvider {
206
+ private readonly issuer;
207
+ private readonly tokenEndpointAuthMethod;
208
+ private readonly discoveryTimeoutMs;
209
+ private readonly skipDiscovery;
210
+ private readonly manualJwksUri?;
211
+ /** Discovered authorization endpoint (overrides base class endpoint after discovery) */
212
+ private discoveredAuthorizationEndpoint?;
213
+ /** Discovered token endpoint (overrides base class endpoint after discovery) */
214
+ private discoveredTokenEndpoint?;
215
+ /** Cached discovery document */
216
+ private discoveryDocument?;
217
+ /** Whether discovery has been attempted */
218
+ private discoveryAttempted;
219
+ /** Cached JWKS for token validation */
220
+ private cachedJWKS?;
221
+ /** Default timeout for discovery requests (10 seconds) */
222
+ private static readonly DEFAULT_DISCOVERY_TIMEOUT_MS;
223
+ /** Default JWKS cache TTL (1 hour) */
224
+ private static readonly DEFAULT_JWKS_CACHE_TTL_MS;
225
+ /** Default clock skew tolerance for token validation (60 seconds) */
226
+ private static readonly DEFAULT_CLOCK_SKEW_SECONDS;
227
+ constructor(config: OIDCProviderConfig);
228
+ /**
229
+ * Validate the issuer URL.
230
+ * @param issuer - The issuer URL to validate
231
+ * @throws Error if issuer is invalid
232
+ */
233
+ private static validateIssuer;
234
+ /**
235
+ * Validate an endpoint URL.
236
+ * @param endpoint - The endpoint URL to validate
237
+ * @param name - The name of the endpoint for error messages
238
+ * @throws Error if endpoint is invalid
239
+ */
240
+ private static validateEndpoint;
241
+ /**
242
+ * Get the issuer URL.
243
+ * @returns The issuer URL
244
+ */
245
+ getIssuer(): string;
246
+ /**
247
+ * Get the JWKS URI for token validation.
248
+ * Returns the discovered or manually configured JWKS URI.
249
+ * @returns The JWKS URI or undefined if not available
250
+ */
251
+ getJwksUri(): string | undefined;
252
+ /**
253
+ * Get the cached discovery document.
254
+ * @returns The discovery document or undefined if not discovered
255
+ */
256
+ getDiscoveryDocument(): OIDCDiscoveryDocument | undefined;
257
+ /**
258
+ * Check if discovery has been performed.
259
+ * @returns True if discovery was attempted
260
+ */
261
+ isDiscoveryAttempted(): boolean;
262
+ /**
263
+ * Get the effective authorization endpoint.
264
+ * Returns discovered endpoint if available, otherwise the initial endpoint.
265
+ * @returns The authorization endpoint URL
266
+ */
267
+ getAuthorizationEndpoint(): string;
268
+ /**
269
+ * Get the effective token endpoint.
270
+ * Returns discovered endpoint if available, otherwise the initial endpoint.
271
+ * @returns The token endpoint URL
272
+ */
273
+ getTokenEndpoint(): string;
274
+ /**
275
+ * Perform OIDC discovery by fetching the .well-known/openid-configuration.
276
+ *
277
+ * This method fetches and parses the discovery document, updating the
278
+ * provider's endpoints if successful.
279
+ *
280
+ * Requirements: 7a.1
281
+ *
282
+ * @returns The discovery result
283
+ */
284
+ discover(): Promise<OIDCDiscoveryResult>;
285
+ /**
286
+ * Validate the discovery document.
287
+ * @param document - The discovery document to validate
288
+ * @returns Error message if invalid, undefined if valid
289
+ */
290
+ private validateDiscoveryDocument;
291
+ /**
292
+ * Ensure discovery has been performed before operations that need endpoints.
293
+ * If discovery hasn't been attempted and manual endpoints weren't provided,
294
+ * this will perform discovery.
295
+ */
296
+ ensureDiscovered(): Promise<void>;
297
+ /**
298
+ * Exchange authorization code for tokens.
299
+ *
300
+ * Overrides base implementation to support different token endpoint
301
+ * authentication methods (client_secret_post, client_secret_basic).
302
+ *
303
+ * Requirements: 7a.7
304
+ *
305
+ * @param code - The authorization code from the callback
306
+ * @param codeVerifier - The PKCE code verifier
307
+ * @param redirectUri - The redirect URI used in the authorization request
308
+ * @returns The token response
309
+ */
310
+ exchangeCode(code: string, codeVerifier: string, redirectUri: string): Promise<TokenResponse>;
311
+ /**
312
+ * Refresh an access token using a refresh token.
313
+ *
314
+ * Overrides base implementation to support different token endpoint
315
+ * authentication methods.
316
+ *
317
+ * @param refreshToken - The refresh token
318
+ * @returns The new token response
319
+ */
320
+ refreshToken(refreshToken: string): Promise<TokenResponse>;
321
+ /**
322
+ * Fetch JWKS from the jwks_uri endpoint.
323
+ *
324
+ * Requirements: 7a.6
325
+ *
326
+ * @param forceRefresh - If true, bypasses cache and fetches fresh JWKS
327
+ * @returns The JWKS or null if unavailable
328
+ */
329
+ fetchJWKS(forceRefresh?: boolean): Promise<JWKS | null>;
330
+ /**
331
+ * Find a key in the JWKS by key ID (kid).
332
+ *
333
+ * If the key is not found in the cache, attempts to refresh the JWKS
334
+ * to handle key rotation.
335
+ *
336
+ * Requirements: 7a.6 (key rotation handling)
337
+ *
338
+ * @param kid - The key ID to find
339
+ * @returns The JWK or null if not found
340
+ */
341
+ findKey(kid: string): Promise<JWK | null>;
342
+ /**
343
+ * Clear the JWKS cache.
344
+ * Useful for testing or when key rotation is detected.
345
+ */
346
+ clearJWKSCache(): void;
347
+ /**
348
+ * Get the cached JWKS if available.
349
+ * @returns The cached JWKS or undefined
350
+ */
351
+ getCachedJWKS(): CachedJWKS | undefined;
352
+ /**
353
+ * Validate an ID token.
354
+ *
355
+ * Validates the following claims per OIDC Core spec:
356
+ * - iss: Must match the configured issuer
357
+ * - aud: Must contain the client_id
358
+ * - exp: Must not be expired
359
+ * - iat: Must be present and reasonable
360
+ *
361
+ * Also validates the JWT signature using JWKS.
362
+ *
363
+ * Requirements: 7a.5, 7a.6
364
+ *
365
+ * @param idToken - The ID token to validate
366
+ * @param options - Validation options
367
+ * @returns The validation result
368
+ */
369
+ validateIdToken(idToken: string, options: IDTokenValidationOptions): Promise<IDTokenValidationResult>;
370
+ /**
371
+ * Validate the JWT signature using JWKS.
372
+ *
373
+ * Requirements: 7a.6
374
+ *
375
+ * @param headerB64 - Base64url encoded header
376
+ * @param payloadB64 - Base64url encoded payload
377
+ * @param signatureB64 - Base64url encoded signature
378
+ * @param header - Decoded JWT header
379
+ * @returns True if signature is valid
380
+ */
381
+ private validateJWTSignature;
382
+ /**
383
+ * Validate ID token claims.
384
+ *
385
+ * Requirements: 7a.5
386
+ *
387
+ * @param claims - The decoded claims
388
+ * @param options - Validation options
389
+ * @returns The validation result
390
+ */
391
+ private validateIDTokenClaims;
392
+ /**
393
+ * Decode a base64url encoded string to UTF-8.
394
+ *
395
+ * @param input - Base64url encoded string
396
+ * @returns Decoded UTF-8 string
397
+ */
398
+ private static base64UrlDecode;
399
+ /**
400
+ * Convert a base64url encoded string to a Buffer.
401
+ *
402
+ * @param input - Base64url encoded string
403
+ * @returns Buffer
404
+ */
405
+ private static base64UrlToBuffer;
406
+ /**
407
+ * Convert a JWK RSA public key to PEM format.
408
+ *
409
+ * @param jwk - The JWK to convert
410
+ * @returns PEM formatted public key
411
+ */
412
+ private static jwkToPem;
413
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Provider interface definitions.
3
+ *
4
+ * @module providers/types
5
+ */
6
+ import type { AuthProviderId, AuthorizationParams, TokenResponse, TokenInjectionMethod } from '../types.js';
7
+ /**
8
+ * OAuth 2.1 provider interface.
9
+ * Each provider implements this interface with provider-specific configuration.
10
+ */
11
+ export interface IAuthProvider {
12
+ /** Unique provider identifier */
13
+ readonly id: AuthProviderId;
14
+ /** Human-readable provider name */
15
+ readonly name: string;
16
+ /** Provider-specific default scopes */
17
+ readonly defaultScopes: readonly string[];
18
+ /** Build the authorization URL for the OAuth flow */
19
+ buildAuthorizationUrl(params: AuthorizationParams): string;
20
+ /** Exchange authorization code for tokens */
21
+ exchangeCode(code: string, codeVerifier: string, redirectUri: string): Promise<TokenResponse>;
22
+ /** Refresh an access token using a refresh token */
23
+ refreshToken(refreshToken: string): Promise<TokenResponse>;
24
+ /** Validate provider configuration */
25
+ validateConfig(): void;
26
+ /** Get token injection method for agent requests */
27
+ getTokenInjection(): TokenInjectionMethod;
28
+ }
@@ -0,0 +1,251 @@
1
+ import type { AuthProviderId } from './types.js';
2
+ /**
3
+ * Represents an in-progress OAuth authorization flow.
4
+ */
5
+ export interface IAuthSession {
6
+ /** Unique session identifier */
7
+ readonly sessionId: string;
8
+ /** Provider being authenticated */
9
+ readonly providerId: AuthProviderId;
10
+ /** PKCE code verifier (kept secret) */
11
+ readonly codeVerifier: string;
12
+ /** PKCE code challenge (sent to provider) */
13
+ readonly codeChallenge: string;
14
+ /** State parameter for CSRF protection */
15
+ readonly state: string;
16
+ /** Session start timestamp */
17
+ readonly startedAt: number;
18
+ /** Session timeout in milliseconds */
19
+ readonly timeoutMs: number;
20
+ /** Check if session has expired */
21
+ isExpired(): boolean;
22
+ /** Get remaining time in milliseconds */
23
+ remainingTime(): number;
24
+ /** Validate returned state parameter */
25
+ validateState(returnedState: string): boolean;
26
+ }
27
+ /**
28
+ * Default session timeout in milliseconds (5 minutes).
29
+ */
30
+ export declare const DEFAULT_SESSION_TIMEOUT_MS: number;
31
+ /**
32
+ * Maximum allowed session timeout in milliseconds (1 hour).
33
+ */
34
+ export declare const MAX_SESSION_TIMEOUT_MS: number;
35
+ /**
36
+ * Validate and normalize a timeout value.
37
+ *
38
+ * Ensures the timeout is a finite positive number within allowed bounds.
39
+ * Returns the default timeout for invalid values (NaN, Infinity, negative, zero).
40
+ *
41
+ * @param timeoutMs - The timeout value to validate
42
+ * @returns A valid timeout value within bounds
43
+ */
44
+ export declare function validateTimeout(timeoutMs: number): number;
45
+ /**
46
+ * Represents an in-progress OAuth authorization flow.
47
+ *
48
+ * Implements the IAuthSession interface from the design document.
49
+ * Tracks all PKCE and state parameters needed for a secure OAuth 2.1 flow.
50
+ */
51
+ export declare class AuthSession implements IAuthSession {
52
+ /** Unique session identifier */
53
+ readonly sessionId: string;
54
+ /** Provider being authenticated */
55
+ readonly providerId: AuthProviderId;
56
+ /** PKCE code verifier (kept secret) */
57
+ readonly codeVerifier: string;
58
+ /** PKCE code challenge (sent to provider) */
59
+ readonly codeChallenge: string;
60
+ /** State parameter for CSRF protection */
61
+ readonly state: string;
62
+ /** Session start timestamp (Unix milliseconds) */
63
+ readonly startedAt: number;
64
+ /** Session timeout in milliseconds */
65
+ readonly timeoutMs: number;
66
+ /**
67
+ * Create a new auth session.
68
+ *
69
+ * @param providerId - The OAuth provider being authenticated
70
+ * @param codeVerifier - PKCE code verifier (kept secret)
71
+ * @param codeChallenge - PKCE code challenge (sent to provider)
72
+ * @param state - State parameter for CSRF protection
73
+ * @param timeoutMs - Session timeout in milliseconds (default: 5 minutes)
74
+ */
75
+ constructor(providerId: AuthProviderId, codeVerifier: string, codeChallenge: string, state: string, timeoutMs?: number);
76
+ /**
77
+ * Check if the session has expired.
78
+ *
79
+ * A session is expired if the current time exceeds startedAt + timeoutMs.
80
+ *
81
+ * @returns True if the session has expired, false otherwise
82
+ */
83
+ isExpired(): boolean;
84
+ /**
85
+ * Get the remaining time until session expiration.
86
+ *
87
+ * Returns the number of milliseconds until the session expires.
88
+ * Returns 0 if the session has already expired.
89
+ *
90
+ * @returns Remaining time in milliseconds (0 if expired)
91
+ */
92
+ remainingTime(): number;
93
+ /**
94
+ * Validate a returned state parameter against this session's state.
95
+ *
96
+ * Uses constant-time comparison via the validateState function
97
+ * to prevent timing attacks.
98
+ *
99
+ * @param returnedState - The state parameter from the OAuth callback
100
+ * @returns True if the state matches, false otherwise
101
+ */
102
+ validateState(returnedState: string): boolean;
103
+ }
104
+ /**
105
+ * Factory function to create a new auth session.
106
+ *
107
+ * Generates PKCE parameters and state, then creates a new AuthSession.
108
+ * This is a convenience function that handles all the cryptographic
109
+ * parameter generation.
110
+ *
111
+ * @param providerId - The OAuth provider to authenticate with
112
+ * @param timeoutMs - Session timeout in milliseconds (default: 5 minutes)
113
+ * @returns A new AuthSession with generated PKCE and state parameters
114
+ */
115
+ export declare function createSession(providerId: AuthProviderId, timeoutMs?: number): AuthSession;
116
+ /**
117
+ * Session manager for tracking and cleaning up OAuth authorization sessions.
118
+ *
119
+ * Provides centralized management of active auth sessions including:
120
+ * - Session storage and retrieval by session ID or state parameter
121
+ * - Automatic cleanup of expired sessions
122
+ * - Session lifecycle management (create, get, remove, list)
123
+ *
124
+ * The manager uses a configurable cleanup interval to periodically remove
125
+ * expired sessions, preventing memory leaks in long-running processes.
126
+ */
127
+ export declare class SessionManager {
128
+ private readonly cleanupIntervalMs;
129
+ /** Map of session ID to AuthSession */
130
+ private readonly sessions;
131
+ /** Map of state parameter to session ID for quick lookup */
132
+ private readonly stateToSessionId;
133
+ /** Cleanup interval timer reference */
134
+ private cleanupTimer;
135
+ /** Default cleanup interval in milliseconds (1 minute) */
136
+ static readonly DEFAULT_CLEANUP_INTERVAL_MS: number;
137
+ /**
138
+ * Create a new SessionManager.
139
+ *
140
+ * @param cleanupIntervalMs - Interval for automatic cleanup (default: 1 minute)
141
+ * @param autoStartCleanup - Whether to start automatic cleanup immediately (default: true)
142
+ */
143
+ constructor(cleanupIntervalMs?: number, autoStartCleanup?: boolean);
144
+ /**
145
+ * Create and register a new auth session.
146
+ *
147
+ * Generates PKCE parameters and state, creates a new AuthSession,
148
+ * and registers it with the manager for tracking.
149
+ *
150
+ * @param providerId - The OAuth provider to authenticate with
151
+ * @param timeoutMs - Session timeout in milliseconds (default: 5 minutes)
152
+ * @returns The newly created and registered AuthSession
153
+ */
154
+ create(providerId: AuthProviderId, timeoutMs?: number): AuthSession;
155
+ /**
156
+ * Get a session by its session ID.
157
+ *
158
+ * @param sessionId - The unique session identifier
159
+ * @returns The session if found and not expired, undefined otherwise
160
+ */
161
+ get(sessionId: string): AuthSession | undefined;
162
+ /**
163
+ * Get a session by its state parameter.
164
+ *
165
+ * Useful for looking up sessions during OAuth callback handling.
166
+ *
167
+ * @param state - The state parameter from the OAuth callback
168
+ * @returns The session if found and not expired, undefined otherwise
169
+ */
170
+ getByState(state: string): AuthSession | undefined;
171
+ /**
172
+ * Remove a session by its session ID.
173
+ *
174
+ * Cleans up both the session and its state parameter mapping.
175
+ *
176
+ * @param sessionId - The unique session identifier
177
+ * @returns True if the session was removed, false if it didn't exist
178
+ */
179
+ remove(sessionId: string): boolean;
180
+ /**
181
+ * Remove a session by its state parameter.
182
+ *
183
+ * @param state - The state parameter
184
+ * @returns True if the session was removed, false if it didn't exist
185
+ */
186
+ removeByState(state: string): boolean;
187
+ /**
188
+ * List all active (non-expired) sessions.
189
+ *
190
+ * This method also performs cleanup of any expired sessions found.
191
+ *
192
+ * @returns Array of active AuthSession objects
193
+ */
194
+ list(): AuthSession[];
195
+ /**
196
+ * Get the count of active sessions.
197
+ *
198
+ * Note: This may include sessions that have expired but not yet been cleaned up.
199
+ * Use list().length for an accurate count of non-expired sessions.
200
+ *
201
+ * @returns The number of tracked sessions
202
+ */
203
+ size(): number;
204
+ /**
205
+ * Check if a session exists by session ID.
206
+ *
207
+ * @param sessionId - The unique session identifier
208
+ * @returns True if the session exists and is not expired
209
+ */
210
+ has(sessionId: string): boolean;
211
+ /**
212
+ * Check if a session exists by state parameter.
213
+ *
214
+ * @param state - The state parameter
215
+ * @returns True if a session with this state exists and is not expired
216
+ */
217
+ hasByState(state: string): boolean;
218
+ /**
219
+ * Remove all expired sessions.
220
+ *
221
+ * This is called automatically by the cleanup timer, but can also
222
+ * be called manually to force immediate cleanup.
223
+ *
224
+ * @returns The number of expired sessions that were removed
225
+ */
226
+ cleanup(): number;
227
+ /**
228
+ * Start the automatic cleanup timer.
229
+ *
230
+ * If cleanup is already running, this method does nothing.
231
+ */
232
+ startCleanup(): void;
233
+ /**
234
+ * Stop the automatic cleanup timer.
235
+ *
236
+ * Call this method when shutting down to clean up resources.
237
+ */
238
+ stopCleanup(): void;
239
+ /**
240
+ * Clear all sessions and stop cleanup.
241
+ *
242
+ * Use this for cleanup during shutdown or testing.
243
+ */
244
+ clear(): void;
245
+ /**
246
+ * Check if automatic cleanup is running.
247
+ *
248
+ * @returns True if the cleanup timer is active
249
+ */
250
+ isCleanupRunning(): boolean;
251
+ }