@juspay/neurolink 9.31.2 → 9.32.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/CHANGELOG.md +6 -0
- package/dist/auth/AuthProviderFactory.d.ts +71 -0
- package/dist/auth/AuthProviderFactory.js +111 -0
- package/dist/auth/AuthProviderRegistry.d.ts +33 -0
- package/dist/auth/AuthProviderRegistry.js +190 -0
- package/dist/auth/RequestContext.d.ts +23 -0
- package/dist/auth/RequestContext.js +78 -0
- package/dist/auth/authContext.d.ts +198 -0
- package/dist/auth/authContext.js +314 -0
- package/dist/auth/errors.d.ts +63 -0
- package/dist/auth/errors.js +39 -0
- package/dist/auth/index.d.ts +20 -8
- package/dist/auth/index.js +35 -7
- package/dist/auth/middleware/AuthMiddleware.d.ts +181 -0
- package/dist/auth/middleware/AuthMiddleware.js +519 -0
- package/dist/auth/middleware/rateLimitByUser.d.ts +282 -0
- package/dist/auth/middleware/rateLimitByUser.js +554 -0
- package/dist/auth/providers/BaseAuthProvider.d.ts +259 -0
- package/dist/auth/providers/BaseAuthProvider.js +723 -0
- package/dist/auth/providers/CognitoProvider.d.ts +61 -0
- package/dist/auth/providers/CognitoProvider.js +304 -0
- package/dist/auth/providers/KeycloakProvider.d.ts +61 -0
- package/dist/auth/providers/KeycloakProvider.js +393 -0
- package/dist/auth/providers/auth0.d.ts +59 -0
- package/dist/auth/providers/auth0.js +274 -0
- package/dist/auth/providers/betterAuth.d.ts +51 -0
- package/dist/auth/providers/betterAuth.js +182 -0
- package/dist/auth/providers/clerk.d.ts +65 -0
- package/dist/auth/providers/clerk.js +317 -0
- package/dist/auth/providers/custom.d.ts +64 -0
- package/dist/auth/providers/custom.js +112 -0
- package/dist/auth/providers/firebase.d.ts +63 -0
- package/dist/auth/providers/firebase.js +226 -0
- package/dist/auth/providers/jwt.d.ts +68 -0
- package/dist/auth/providers/jwt.js +212 -0
- package/dist/auth/providers/oauth2.d.ts +73 -0
- package/dist/auth/providers/oauth2.js +303 -0
- package/dist/auth/providers/supabase.d.ts +63 -0
- package/dist/auth/providers/supabase.js +259 -0
- package/dist/auth/providers/workos.d.ts +61 -0
- package/dist/auth/providers/workos.js +284 -0
- package/dist/auth/serverBridge.d.ts +14 -0
- package/dist/auth/serverBridge.js +25 -0
- package/dist/auth/sessionManager.d.ts +142 -0
- package/dist/auth/sessionManager.js +437 -0
- package/dist/cli/commands/authProviders.d.ts +43 -0
- package/dist/cli/commands/authProviders.js +399 -0
- package/dist/cli/factories/authCommandFactory.d.ts +23 -5
- package/dist/cli/factories/authCommandFactory.js +108 -5
- package/dist/cli/parser.js +1 -1
- package/dist/client/auth/AuthProviderFactory.js +111 -0
- package/dist/client/auth/AuthProviderRegistry.js +190 -0
- package/dist/client/auth/RequestContext.js +78 -0
- package/dist/client/auth/accountPool.js +178 -0
- package/dist/client/auth/authContext.js +314 -0
- package/dist/client/auth/errors.js +39 -0
- package/dist/client/auth/index.js +61 -0
- package/dist/client/auth/middleware/AuthMiddleware.js +519 -0
- package/dist/client/auth/middleware/rateLimitByUser.js +554 -0
- package/dist/client/auth/providers/BaseAuthProvider.js +723 -0
- package/dist/client/auth/providers/CognitoProvider.js +304 -0
- package/dist/client/auth/providers/KeycloakProvider.js +393 -0
- package/dist/client/auth/providers/auth0.js +274 -0
- package/dist/client/auth/providers/betterAuth.js +182 -0
- package/dist/client/auth/providers/clerk.js +317 -0
- package/dist/client/auth/providers/custom.js +112 -0
- package/dist/client/auth/providers/firebase.js +226 -0
- package/dist/client/auth/providers/jwt.js +212 -0
- package/dist/client/auth/providers/oauth2.js +303 -0
- package/dist/client/auth/providers/supabase.js +259 -0
- package/dist/client/auth/providers/workos.js +284 -0
- package/dist/client/auth/serverBridge.js +25 -0
- package/dist/client/auth/sessionManager.js +437 -0
- package/dist/client/core/infrastructure/baseRegistry.js +5 -1
- package/dist/client/index.js +25 -0
- package/dist/client/mcp/toolRegistry.js +11 -1
- package/dist/client/neurolink.js +218 -0
- package/dist/client/rag/ChunkerRegistry.js +2 -2
- package/dist/client/rag/metadata/MetadataExtractorRegistry.js +2 -2
- package/dist/client/rag/reranker/RerankerRegistry.js +2 -2
- package/dist/client/server/routes/agentRoutes.js +20 -2
- package/dist/client/types/authTypes.js +2 -1
- package/dist/core/infrastructure/baseRegistry.d.ts +3 -1
- package/dist/core/infrastructure/baseRegistry.js +5 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +25 -0
- package/dist/lib/auth/AuthProviderFactory.d.ts +71 -0
- package/dist/lib/auth/AuthProviderFactory.js +112 -0
- package/dist/lib/auth/AuthProviderRegistry.d.ts +33 -0
- package/dist/lib/auth/AuthProviderRegistry.js +191 -0
- package/dist/lib/auth/RequestContext.d.ts +23 -0
- package/dist/lib/auth/RequestContext.js +79 -0
- package/dist/lib/auth/authContext.d.ts +198 -0
- package/dist/lib/auth/authContext.js +315 -0
- package/dist/lib/auth/errors.d.ts +63 -0
- package/dist/lib/auth/errors.js +40 -0
- package/dist/lib/auth/index.d.ts +20 -8
- package/dist/lib/auth/index.js +35 -7
- package/dist/lib/auth/middleware/AuthMiddleware.d.ts +181 -0
- package/dist/lib/auth/middleware/AuthMiddleware.js +520 -0
- package/dist/lib/auth/middleware/rateLimitByUser.d.ts +282 -0
- package/dist/lib/auth/middleware/rateLimitByUser.js +555 -0
- package/dist/lib/auth/providers/BaseAuthProvider.d.ts +259 -0
- package/dist/lib/auth/providers/BaseAuthProvider.js +724 -0
- package/dist/lib/auth/providers/CognitoProvider.d.ts +61 -0
- package/dist/lib/auth/providers/CognitoProvider.js +305 -0
- package/dist/lib/auth/providers/KeycloakProvider.d.ts +61 -0
- package/dist/lib/auth/providers/KeycloakProvider.js +394 -0
- package/dist/lib/auth/providers/auth0.d.ts +59 -0
- package/dist/lib/auth/providers/auth0.js +275 -0
- package/dist/lib/auth/providers/betterAuth.d.ts +51 -0
- package/dist/lib/auth/providers/betterAuth.js +183 -0
- package/dist/lib/auth/providers/clerk.d.ts +65 -0
- package/dist/lib/auth/providers/clerk.js +318 -0
- package/dist/lib/auth/providers/custom.d.ts +64 -0
- package/dist/lib/auth/providers/custom.js +113 -0
- package/dist/lib/auth/providers/firebase.d.ts +63 -0
- package/dist/lib/auth/providers/firebase.js +227 -0
- package/dist/lib/auth/providers/jwt.d.ts +68 -0
- package/dist/lib/auth/providers/jwt.js +213 -0
- package/dist/lib/auth/providers/oauth2.d.ts +73 -0
- package/dist/lib/auth/providers/oauth2.js +304 -0
- package/dist/lib/auth/providers/supabase.d.ts +63 -0
- package/dist/lib/auth/providers/supabase.js +260 -0
- package/dist/lib/auth/providers/workos.d.ts +61 -0
- package/dist/lib/auth/providers/workos.js +285 -0
- package/dist/lib/auth/serverBridge.d.ts +14 -0
- package/dist/lib/auth/serverBridge.js +26 -0
- package/dist/lib/auth/sessionManager.d.ts +142 -0
- package/dist/lib/auth/sessionManager.js +438 -0
- package/dist/lib/core/infrastructure/baseRegistry.d.ts +3 -1
- package/dist/lib/core/infrastructure/baseRegistry.js +5 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +25 -0
- package/dist/lib/mcp/toolRegistry.js +11 -1
- package/dist/lib/neurolink.d.ts +42 -1
- package/dist/lib/neurolink.js +218 -0
- package/dist/lib/rag/ChunkerRegistry.js +2 -2
- package/dist/lib/rag/metadata/MetadataExtractorRegistry.js +2 -2
- package/dist/lib/rag/reranker/RerankerRegistry.js +2 -2
- package/dist/lib/server/routes/agentRoutes.js +20 -2
- package/dist/lib/types/authTypes.d.ts +937 -1
- package/dist/lib/types/authTypes.js +2 -1
- package/dist/lib/types/configTypes.d.ts +46 -0
- package/dist/lib/types/generateTypes.d.ts +6 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/streamTypes.d.ts +6 -0
- package/dist/mcp/toolRegistry.js +11 -1
- package/dist/neurolink.d.ts +42 -1
- package/dist/neurolink.js +218 -0
- package/dist/rag/ChunkerRegistry.js +2 -2
- package/dist/rag/metadata/MetadataExtractorRegistry.js +2 -2
- package/dist/rag/reranker/RerankerRegistry.js +2 -2
- package/dist/server/routes/agentRoutes.js +20 -2
- package/dist/types/authTypes.d.ts +937 -1
- package/dist/types/authTypes.js +2 -1
- package/dist/types/configTypes.d.ts +46 -0
- package/dist/types/generateTypes.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/streamTypes.d.ts +6 -0
- package/package.json +2 -1
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
// src/cli/commands/authProviders.ts
|
|
2
|
+
/**
|
|
3
|
+
* Multi-provider authentication CLI handlers.
|
|
4
|
+
*
|
|
5
|
+
* Provides commands for listing, validating, and health-checking
|
|
6
|
+
* authentication providers (Auth0, Clerk, Firebase, Supabase, etc.).
|
|
7
|
+
*/
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
import { AuthProviderFactory } from "../../lib/auth/AuthProviderFactory.js";
|
|
10
|
+
import { logger } from "../../lib/utils/logger.js";
|
|
11
|
+
/**
|
|
12
|
+
* Provider information for display
|
|
13
|
+
*/
|
|
14
|
+
const PROVIDER_INFO = {
|
|
15
|
+
auth0: {
|
|
16
|
+
name: "Auth0",
|
|
17
|
+
description: "Enterprise identity platform with JWT and session support",
|
|
18
|
+
requiredConfig: ["domain", "clientId"],
|
|
19
|
+
website: "https://auth0.com",
|
|
20
|
+
},
|
|
21
|
+
clerk: {
|
|
22
|
+
name: "Clerk",
|
|
23
|
+
description: "Modern authentication with session-based and JWT support",
|
|
24
|
+
requiredConfig: ["publishableKey", "secretKey"],
|
|
25
|
+
website: "https://clerk.com",
|
|
26
|
+
},
|
|
27
|
+
supabase: {
|
|
28
|
+
name: "Supabase Auth",
|
|
29
|
+
description: "Open-source Firebase alternative with JWT authentication",
|
|
30
|
+
requiredConfig: ["url", "anonKey"],
|
|
31
|
+
website: "https://supabase.com",
|
|
32
|
+
},
|
|
33
|
+
firebase: {
|
|
34
|
+
name: "Firebase Auth",
|
|
35
|
+
description: "Google's authentication service with multiple providers",
|
|
36
|
+
requiredConfig: ["projectId"],
|
|
37
|
+
website: "https://firebase.google.com",
|
|
38
|
+
},
|
|
39
|
+
workos: {
|
|
40
|
+
name: "WorkOS",
|
|
41
|
+
description: "Enterprise-ready authentication with SSO support",
|
|
42
|
+
requiredConfig: ["apiKey", "clientId"],
|
|
43
|
+
website: "https://workos.com",
|
|
44
|
+
},
|
|
45
|
+
"better-auth": {
|
|
46
|
+
name: "Better Auth",
|
|
47
|
+
description: "Self-hosted authentication solution",
|
|
48
|
+
requiredConfig: ["secret", "baseUrl"],
|
|
49
|
+
website: "https://github.com/better-auth/better-auth",
|
|
50
|
+
},
|
|
51
|
+
custom: {
|
|
52
|
+
name: "Custom",
|
|
53
|
+
description: "Custom authentication adapter for any provider",
|
|
54
|
+
requiredConfig: ["validateToken"],
|
|
55
|
+
website: "",
|
|
56
|
+
},
|
|
57
|
+
oauth2: {
|
|
58
|
+
name: "OAuth2",
|
|
59
|
+
description: "Generic OAuth2 authentication with configurable endpoints",
|
|
60
|
+
requiredConfig: [
|
|
61
|
+
"clientId",
|
|
62
|
+
"clientSecret",
|
|
63
|
+
"authorizationUrl",
|
|
64
|
+
"tokenUrl",
|
|
65
|
+
],
|
|
66
|
+
website: "https://oauth.net/2/",
|
|
67
|
+
},
|
|
68
|
+
cognito: {
|
|
69
|
+
name: "AWS Cognito",
|
|
70
|
+
description: "AWS Cognito user pools with JWT authentication",
|
|
71
|
+
requiredConfig: ["userPoolId", "clientId", "region"],
|
|
72
|
+
website: "https://aws.amazon.com/cognito/",
|
|
73
|
+
},
|
|
74
|
+
keycloak: {
|
|
75
|
+
name: "Keycloak",
|
|
76
|
+
description: "Open-source identity and access management",
|
|
77
|
+
requiredConfig: ["realm", "serverUrl", "clientId"],
|
|
78
|
+
website: "https://www.keycloak.org/",
|
|
79
|
+
},
|
|
80
|
+
jwt: {
|
|
81
|
+
name: "JWT",
|
|
82
|
+
description: "Generic JWT token validation with configurable secret/keys",
|
|
83
|
+
requiredConfig: ["secret"],
|
|
84
|
+
website: "https://jwt.io/",
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Handle 'auth providers' command
|
|
89
|
+
*/
|
|
90
|
+
export async function handleProvidersCommand(argv) {
|
|
91
|
+
const providers = Object.entries(PROVIDER_INFO).filter(([key]) => key !== "custom");
|
|
92
|
+
if (argv.format === "json") {
|
|
93
|
+
const output = providers.map(([type, info]) => ({
|
|
94
|
+
type,
|
|
95
|
+
...info,
|
|
96
|
+
}));
|
|
97
|
+
logger.always(JSON.stringify(output, null, 2));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (argv.format === "table") {
|
|
101
|
+
logger.always(chalk.bold("\nAvailable Authentication Providers\n"));
|
|
102
|
+
logger.always(chalk.gray("+-----------------+--------------------------------------------------+"));
|
|
103
|
+
logger.always(chalk.gray("| ") +
|
|
104
|
+
chalk.bold("Provider".padEnd(15)) +
|
|
105
|
+
chalk.gray(" | ") +
|
|
106
|
+
chalk.bold("Description".padEnd(48)) +
|
|
107
|
+
chalk.gray(" |"));
|
|
108
|
+
logger.always(chalk.gray("+-----------------+--------------------------------------------------+"));
|
|
109
|
+
for (const [type, info] of providers) {
|
|
110
|
+
logger.always(chalk.gray("| ") +
|
|
111
|
+
chalk.cyan(type.padEnd(15)) +
|
|
112
|
+
chalk.gray(" | ") +
|
|
113
|
+
info.description.substring(0, 48).padEnd(48) +
|
|
114
|
+
chalk.gray(" |"));
|
|
115
|
+
}
|
|
116
|
+
logger.always(chalk.gray("+-----------------+--------------------------------------------------+"));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
// Text format (default)
|
|
120
|
+
logger.always(chalk.bold("\nAvailable Authentication Providers\n"));
|
|
121
|
+
for (const [type, info] of providers) {
|
|
122
|
+
logger.always(chalk.cyan.bold(` ${info.name} (${type})`));
|
|
123
|
+
logger.always(chalk.gray(` ${info.description}`));
|
|
124
|
+
logger.always(chalk.gray(` Required config: ${info.requiredConfig.join(", ")}`));
|
|
125
|
+
if (info.website) {
|
|
126
|
+
logger.always(chalk.gray(` Website: ${info.website}`));
|
|
127
|
+
}
|
|
128
|
+
logger.always("");
|
|
129
|
+
}
|
|
130
|
+
logger.always(chalk.gray("Use 'neurolink auth validate <token> --provider <type>' to validate a token"));
|
|
131
|
+
logger.always(chalk.gray("Use 'neurolink auth health --provider <type>' to check provider health\n"));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Handle 'auth validate' command
|
|
135
|
+
*/
|
|
136
|
+
export async function handleValidateCommand(argv) {
|
|
137
|
+
try {
|
|
138
|
+
const providerConfig = buildProviderConfig(argv);
|
|
139
|
+
if (!providerConfig) {
|
|
140
|
+
logger.error(chalk.red(`\nError: Missing required configuration for ${argv.provider} provider.\n`));
|
|
141
|
+
logger.always(chalk.gray(`Required: ${PROVIDER_INFO[argv.provider].requiredConfig.join(", ")}`));
|
|
142
|
+
logger.always(chalk.gray("\nProvide via CLI options or environment variables (e.g., AUTH0_DOMAIN)"));
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
const provider = await AuthProviderFactory.createProvider(argv.provider, providerConfig);
|
|
146
|
+
const result = await provider.authenticateToken(argv.token);
|
|
147
|
+
if (argv.format === "json") {
|
|
148
|
+
logger.always(JSON.stringify(result, null, 2));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
logger.always("");
|
|
152
|
+
if (result.valid) {
|
|
153
|
+
logger.always(chalk.green.bold("Token is VALID"));
|
|
154
|
+
logger.always("");
|
|
155
|
+
if (result.user) {
|
|
156
|
+
logger.always(chalk.bold("User Information:"));
|
|
157
|
+
logger.always(chalk.gray(` ID: ${result.user.id}`));
|
|
158
|
+
if (result.user.email) {
|
|
159
|
+
logger.always(chalk.gray(` Email: ${result.user.email}`));
|
|
160
|
+
}
|
|
161
|
+
if (result.user.name) {
|
|
162
|
+
logger.always(chalk.gray(` Name: ${result.user.name}`));
|
|
163
|
+
}
|
|
164
|
+
if (result.user.roles.length > 0) {
|
|
165
|
+
logger.always(chalk.gray(` Roles: ${result.user.roles.join(", ")}`));
|
|
166
|
+
}
|
|
167
|
+
if (result.user.permissions.length > 0) {
|
|
168
|
+
logger.always(chalk.gray(` Permissions: ${result.user.permissions.join(", ")}`));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (result.expiresAt) {
|
|
172
|
+
logger.always("");
|
|
173
|
+
logger.always(chalk.gray(`Expires: ${result.expiresAt.toISOString()}`));
|
|
174
|
+
}
|
|
175
|
+
if (result.tokenType) {
|
|
176
|
+
logger.always(chalk.gray(`Token Type: ${result.tokenType}`));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
logger.always(chalk.red.bold("Token is INVALID"));
|
|
181
|
+
if (result.error) {
|
|
182
|
+
logger.always(chalk.red(`\nError: ${result.error}`));
|
|
183
|
+
}
|
|
184
|
+
process.exit(1);
|
|
185
|
+
}
|
|
186
|
+
logger.always("");
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
190
|
+
logger.error("Token validation failed:", error);
|
|
191
|
+
if (argv.format === "json") {
|
|
192
|
+
logger.always(JSON.stringify({ valid: false, error: message }, null, 2));
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
logger.error(chalk.red(`\nValidation Error: ${message}\n`));
|
|
196
|
+
}
|
|
197
|
+
process.exit(1);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Handle 'auth health' command
|
|
202
|
+
*/
|
|
203
|
+
export async function handleHealthCommand(argv) {
|
|
204
|
+
try {
|
|
205
|
+
const providerConfig = buildProviderConfig(argv);
|
|
206
|
+
if (!providerConfig) {
|
|
207
|
+
logger.error(chalk.red(`\nError: Missing required configuration for ${argv.provider} provider.\n`));
|
|
208
|
+
logger.always(chalk.gray(`Required: ${PROVIDER_INFO[argv.provider].requiredConfig.join(", ")}`));
|
|
209
|
+
logger.always(chalk.gray("\nProvide via CLI options or environment variables (e.g., AUTH0_DOMAIN)"));
|
|
210
|
+
process.exit(1);
|
|
211
|
+
}
|
|
212
|
+
const provider = await AuthProviderFactory.createProvider(argv.provider, providerConfig);
|
|
213
|
+
const health = await provider.healthCheck?.();
|
|
214
|
+
if (!health) {
|
|
215
|
+
logger.error(chalk.red(`\nProvider ${argv.provider} does not support health checks.\n`));
|
|
216
|
+
process.exit(1);
|
|
217
|
+
}
|
|
218
|
+
if (argv.format === "json") {
|
|
219
|
+
logger.always(JSON.stringify(health, null, 2));
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
logger.always("");
|
|
223
|
+
logger.always(chalk.bold(`Auth Provider Health: ${argv.provider}`));
|
|
224
|
+
logger.always("");
|
|
225
|
+
const statusIcon = health.healthy ? chalk.green("OK") : chalk.red("FAIL");
|
|
226
|
+
logger.always(` Overall Status: ${statusIcon}`);
|
|
227
|
+
logger.always(` Provider Connected: ${health.providerConnected ? chalk.green("Yes") : chalk.red("No")}`);
|
|
228
|
+
logger.always(` Session Storage: ${health.sessionStorageHealthy ? chalk.green("Healthy") : chalk.red("Unhealthy")}`);
|
|
229
|
+
if (health.lastSuccessfulAuth) {
|
|
230
|
+
logger.always(chalk.gray(` Last Auth: ${health.lastSuccessfulAuth.toISOString()}`));
|
|
231
|
+
}
|
|
232
|
+
if (health.error) {
|
|
233
|
+
logger.always(chalk.red(`\n Error: ${health.error}`));
|
|
234
|
+
}
|
|
235
|
+
logger.always("");
|
|
236
|
+
if (!health.healthy) {
|
|
237
|
+
process.exit(1);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
242
|
+
logger.error("Health check failed:", error);
|
|
243
|
+
if (argv.format === "json") {
|
|
244
|
+
logger.always(JSON.stringify({ healthy: false, error: message }, null, 2));
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
logger.error(chalk.red(`\nHealth Check Error: ${message}\n`));
|
|
248
|
+
}
|
|
249
|
+
process.exit(1);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Build provider configuration from CLI args and environment variables
|
|
254
|
+
*/
|
|
255
|
+
function buildProviderConfig(argv) {
|
|
256
|
+
switch (argv.provider) {
|
|
257
|
+
case "auth0": {
|
|
258
|
+
const domain = argv.domain || process.env.AUTH0_DOMAIN;
|
|
259
|
+
const clientId = argv.clientId || process.env.AUTH0_CLIENT_ID;
|
|
260
|
+
if (!domain || !clientId) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
type: argv.provider,
|
|
265
|
+
domain,
|
|
266
|
+
clientId,
|
|
267
|
+
audience: process.env.AUTH0_AUDIENCE,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
case "clerk": {
|
|
271
|
+
const secretKey = argv.secretKey || process.env.CLERK_SECRET_KEY;
|
|
272
|
+
const publishableKey = process.env.CLERK_PUBLISHABLE_KEY || "";
|
|
273
|
+
if (!secretKey) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
type: argv.provider,
|
|
278
|
+
publishableKey,
|
|
279
|
+
secretKey,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
case "supabase": {
|
|
283
|
+
const url = argv.url || process.env.SUPABASE_URL;
|
|
284
|
+
const anonKey = argv.anonKey || process.env.SUPABASE_ANON_KEY;
|
|
285
|
+
if (!url || !anonKey) {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
type: argv.provider,
|
|
290
|
+
url,
|
|
291
|
+
anonKey,
|
|
292
|
+
jwtSecret: process.env.SUPABASE_JWT_SECRET,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
case "firebase": {
|
|
296
|
+
const projectId = process.env.FIREBASE_PROJECT_ID;
|
|
297
|
+
if (!projectId) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
type: argv.provider,
|
|
302
|
+
projectId,
|
|
303
|
+
apiKey: process.env.FIREBASE_API_KEY,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
case "workos": {
|
|
307
|
+
const apiKey = argv.apiKey || process.env.WORKOS_API_KEY;
|
|
308
|
+
const clientId = argv.clientId || process.env.WORKOS_CLIENT_ID;
|
|
309
|
+
if (!apiKey || !clientId) {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
type: argv.provider,
|
|
314
|
+
apiKey,
|
|
315
|
+
clientId,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
case "better-auth": {
|
|
319
|
+
const secret = argv.secret || process.env.BETTER_AUTH_SECRET;
|
|
320
|
+
const baseUrl = argv.url || process.env.BETTER_AUTH_BASE_URL;
|
|
321
|
+
if (!secret || !baseUrl) {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
type: argv.provider,
|
|
326
|
+
secret,
|
|
327
|
+
baseUrl,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
case "oauth2": {
|
|
331
|
+
const clientId = argv.clientId || process.env.OAUTH2_CLIENT_ID;
|
|
332
|
+
const clientSecret = process.env.OAUTH2_CLIENT_SECRET;
|
|
333
|
+
const authorizationUrl = process.env.OAUTH2_AUTHORIZATION_URL;
|
|
334
|
+
const tokenUrl = process.env.OAUTH2_TOKEN_URL;
|
|
335
|
+
if (!clientId || !authorizationUrl || !tokenUrl) {
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
type: argv.provider,
|
|
340
|
+
clientId,
|
|
341
|
+
clientSecret,
|
|
342
|
+
authorizationUrl,
|
|
343
|
+
tokenUrl,
|
|
344
|
+
userInfoUrl: process.env.OAUTH2_USERINFO_URL,
|
|
345
|
+
jwksUrl: process.env.OAUTH2_JWKS_URL,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
case "cognito": {
|
|
349
|
+
const userPoolId = process.env.COGNITO_USER_POOL_ID;
|
|
350
|
+
const clientId = argv.clientId || process.env.COGNITO_CLIENT_ID;
|
|
351
|
+
const region = process.env.COGNITO_REGION || process.env.AWS_REGION;
|
|
352
|
+
if (!userPoolId || !clientId || !region) {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
type: argv.provider,
|
|
357
|
+
userPoolId,
|
|
358
|
+
clientId,
|
|
359
|
+
region,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
case "keycloak": {
|
|
363
|
+
const realm = process.env.KEYCLOAK_REALM;
|
|
364
|
+
const serverUrl = argv.url || process.env.KEYCLOAK_SERVER_URL;
|
|
365
|
+
const clientId = argv.clientId || process.env.KEYCLOAK_CLIENT_ID;
|
|
366
|
+
if (!realm || !serverUrl || !clientId) {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
type: argv.provider,
|
|
371
|
+
realm,
|
|
372
|
+
serverUrl,
|
|
373
|
+
clientId,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
case "jwt": {
|
|
377
|
+
const secret = argv.secret || process.env.JWT_SECRET;
|
|
378
|
+
const publicKey = process.env.JWT_PUBLIC_KEY;
|
|
379
|
+
if (!secret && !publicKey) {
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
type: argv.provider,
|
|
384
|
+
secret,
|
|
385
|
+
publicKey,
|
|
386
|
+
issuer: process.env.JWT_ISSUER,
|
|
387
|
+
audience: process.env.JWT_AUDIENCE,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
case "custom": {
|
|
391
|
+
// Custom provider requires a validateToken function which can't be
|
|
392
|
+
// provided via CLI flags. Return null to show guidance message.
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
default:
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
//# sourceMappingURL=authProviders.js.map
|
|
@@ -2,20 +2,22 @@
|
|
|
2
2
|
* Auth Command Factory for NeuroLink
|
|
3
3
|
*
|
|
4
4
|
* Creates the unified authentication command with subcommands for AI providers.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* - Anthropic (API key + OAuth for Claude subscription plans)
|
|
5
|
+
* Subcommands:
|
|
6
|
+
* - login, logout, status, refresh: Anthropic OAuth (API key + OAuth)
|
|
7
|
+
* - providers, validate, health: Multi-provider auth management
|
|
9
8
|
*/
|
|
10
9
|
import type { CommandModule } from "yargs";
|
|
11
10
|
/**
|
|
12
11
|
* Auth Command Factory
|
|
13
12
|
*
|
|
14
13
|
* Creates the main auth command with subcommands:
|
|
15
|
-
* - login: Authenticate with a provider
|
|
14
|
+
* - login: Authenticate with a provider (Anthropic OAuth)
|
|
16
15
|
* - logout: Clear stored credentials
|
|
17
16
|
* - status: Show authentication status
|
|
18
17
|
* - refresh: Manually refresh OAuth tokens
|
|
18
|
+
* - providers: List available auth providers
|
|
19
|
+
* - validate: Validate a token against a provider
|
|
20
|
+
* - health: Check auth provider health
|
|
19
21
|
*/
|
|
20
22
|
export declare class AuthCommandFactory {
|
|
21
23
|
/**
|
|
@@ -54,4 +56,20 @@ export declare class AuthCommandFactory {
|
|
|
54
56
|
* Build options for enable subcommand
|
|
55
57
|
*/
|
|
56
58
|
private static buildEnableOptions;
|
|
59
|
+
/**
|
|
60
|
+
* Auth provider choices for multi-provider commands
|
|
61
|
+
*/
|
|
62
|
+
private static readonly AUTH_PROVIDER_CHOICES;
|
|
63
|
+
/**
|
|
64
|
+
* Build common provider options for validate/health commands
|
|
65
|
+
*/
|
|
66
|
+
private static buildProviderOptions;
|
|
67
|
+
/**
|
|
68
|
+
* Build options for validate subcommand
|
|
69
|
+
*/
|
|
70
|
+
private static buildValidateOptions;
|
|
71
|
+
/**
|
|
72
|
+
* Build options for health subcommand
|
|
73
|
+
*/
|
|
74
|
+
private static buildHealthOptions;
|
|
57
75
|
}
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* Auth Command Factory for NeuroLink
|
|
3
3
|
*
|
|
4
4
|
* Creates the unified authentication command with subcommands for AI providers.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* - Anthropic (API key + OAuth for Claude subscription plans)
|
|
5
|
+
* Subcommands:
|
|
6
|
+
* - login, logout, status, refresh: Anthropic OAuth (API key + OAuth)
|
|
7
|
+
* - providers, validate, health: Multi-provider auth management
|
|
9
8
|
*/
|
|
10
9
|
/**
|
|
11
10
|
* Supported providers for authentication
|
|
@@ -15,10 +14,13 @@ const SUPPORTED_PROVIDERS = ["anthropic"];
|
|
|
15
14
|
* Auth Command Factory
|
|
16
15
|
*
|
|
17
16
|
* Creates the main auth command with subcommands:
|
|
18
|
-
* - login: Authenticate with a provider
|
|
17
|
+
* - login: Authenticate with a provider (Anthropic OAuth)
|
|
19
18
|
* - logout: Clear stored credentials
|
|
20
19
|
* - status: Show authentication status
|
|
21
20
|
* - refresh: Manually refresh OAuth tokens
|
|
21
|
+
* - providers: List available auth providers
|
|
22
|
+
* - validate: Validate a token against a provider
|
|
23
|
+
* - health: Check auth provider health
|
|
22
24
|
*/
|
|
23
25
|
export class AuthCommandFactory {
|
|
24
26
|
/**
|
|
@@ -61,6 +63,24 @@ export class AuthCommandFactory {
|
|
|
61
63
|
.command("enable <account>", "Re-enable a previously disabled account", (yargs) => this.buildEnableOptions(yargs), async (argv) => {
|
|
62
64
|
const { handleEnable } = await import("../commands/auth.js");
|
|
63
65
|
await handleEnable(argv);
|
|
66
|
+
})
|
|
67
|
+
.command("providers", "List available authentication providers", (yargs) => yargs.option("format", {
|
|
68
|
+
type: "string",
|
|
69
|
+
choices: ["text", "json", "table"],
|
|
70
|
+
default: "text",
|
|
71
|
+
description: "Output format",
|
|
72
|
+
alias: "f",
|
|
73
|
+
}), async (argv) => {
|
|
74
|
+
const { handleProvidersCommand } = await import("../commands/authProviders.js");
|
|
75
|
+
await handleProvidersCommand(argv);
|
|
76
|
+
})
|
|
77
|
+
.command("validate <token>", "Validate an authentication token", (yargs) => this.buildValidateOptions(yargs), async (argv) => {
|
|
78
|
+
const { handleValidateCommand } = await import("../commands/authProviders.js");
|
|
79
|
+
await handleValidateCommand(argv);
|
|
80
|
+
})
|
|
81
|
+
.command("health", "Check authentication provider health", (yargs) => this.buildHealthOptions(yargs), async (argv) => {
|
|
82
|
+
const { handleHealthCommand } = await import("../commands/authProviders.js");
|
|
83
|
+
await handleHealthCommand(argv);
|
|
64
84
|
})
|
|
65
85
|
.option("format", {
|
|
66
86
|
choices: ["text", "json"],
|
|
@@ -237,5 +257,88 @@ export class AuthCommandFactory {
|
|
|
237
257
|
})
|
|
238
258
|
.example("$0 auth enable anthropic:1-VjRIq", "Re-enable a disabled account");
|
|
239
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Auth provider choices for multi-provider commands
|
|
262
|
+
*/
|
|
263
|
+
static AUTH_PROVIDER_CHOICES = [
|
|
264
|
+
"auth0",
|
|
265
|
+
"clerk",
|
|
266
|
+
"supabase",
|
|
267
|
+
"firebase",
|
|
268
|
+
"workos",
|
|
269
|
+
"better-auth",
|
|
270
|
+
"jwt",
|
|
271
|
+
"oauth2",
|
|
272
|
+
"cognito",
|
|
273
|
+
"keycloak",
|
|
274
|
+
];
|
|
275
|
+
/**
|
|
276
|
+
* Build common provider options for validate/health commands
|
|
277
|
+
*/
|
|
278
|
+
static buildProviderOptions(yargs) {
|
|
279
|
+
return yargs
|
|
280
|
+
.option("provider", {
|
|
281
|
+
type: "string",
|
|
282
|
+
choices: this.AUTH_PROVIDER_CHOICES,
|
|
283
|
+
default: "auth0",
|
|
284
|
+
description: "Authentication provider type",
|
|
285
|
+
alias: "p",
|
|
286
|
+
})
|
|
287
|
+
.option("domain", {
|
|
288
|
+
type: "string",
|
|
289
|
+
description: "Auth0 domain (for auth0 provider)",
|
|
290
|
+
})
|
|
291
|
+
.option("clientId", {
|
|
292
|
+
type: "string",
|
|
293
|
+
description: "Client ID (for auth0 provider)",
|
|
294
|
+
alias: "client-id",
|
|
295
|
+
})
|
|
296
|
+
.option("secretKey", {
|
|
297
|
+
type: "string",
|
|
298
|
+
description: "Secret key (for clerk provider)",
|
|
299
|
+
alias: "secret-key",
|
|
300
|
+
})
|
|
301
|
+
.option("url", {
|
|
302
|
+
type: "string",
|
|
303
|
+
description: "Provider URL (for supabase, better-auth)",
|
|
304
|
+
})
|
|
305
|
+
.option("anonKey", {
|
|
306
|
+
type: "string",
|
|
307
|
+
description: "Anon key (for supabase provider)",
|
|
308
|
+
alias: "anon-key",
|
|
309
|
+
})
|
|
310
|
+
.option("apiKey", {
|
|
311
|
+
type: "string",
|
|
312
|
+
description: "API key (for workos provider)",
|
|
313
|
+
alias: "api-key",
|
|
314
|
+
})
|
|
315
|
+
.option("secret", {
|
|
316
|
+
type: "string",
|
|
317
|
+
description: "Secret (for better-auth, jwt providers). Can also be set via BETTER_AUTH_SECRET or JWT_SECRET env vars.",
|
|
318
|
+
})
|
|
319
|
+
.option("format", {
|
|
320
|
+
type: "string",
|
|
321
|
+
choices: ["text", "json"],
|
|
322
|
+
default: "text",
|
|
323
|
+
description: "Output format",
|
|
324
|
+
alias: "f",
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Build options for validate subcommand
|
|
329
|
+
*/
|
|
330
|
+
static buildValidateOptions(yargs) {
|
|
331
|
+
return this.buildProviderOptions(yargs.positional("token", {
|
|
332
|
+
type: "string",
|
|
333
|
+
description: "The token to validate (JWT or session token)",
|
|
334
|
+
demandOption: true,
|
|
335
|
+
}));
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Build options for health subcommand
|
|
339
|
+
*/
|
|
340
|
+
static buildHealthOptions(yargs) {
|
|
341
|
+
return this.buildProviderOptions(yargs);
|
|
342
|
+
}
|
|
240
343
|
}
|
|
241
344
|
//# sourceMappingURL=authCommandFactory.js.map
|
package/dist/cli/parser.js
CHANGED
|
@@ -7,13 +7,13 @@ import { globalSession } from "../lib/session/globalSessionState.js";
|
|
|
7
7
|
import { handleError } from "./errorHandler.js";
|
|
8
8
|
import { logger } from "../lib/utils/logger.js";
|
|
9
9
|
import { SetupCommandFactory } from "./factories/setupCommandFactory.js";
|
|
10
|
+
import { AuthCommandFactory } from "./factories/authCommandFactory.js";
|
|
10
11
|
import { ServerCommandFactory } from "./commands/server.js";
|
|
11
12
|
import { ServeCommandFactory } from "./commands/serve.js";
|
|
12
13
|
import { ragCommand } from "./commands/rag.js";
|
|
13
14
|
import { ObservabilityCommandFactory } from "./commands/observability.js";
|
|
14
15
|
import { TelemetryCommandFactory } from "./commands/telemetry.js";
|
|
15
16
|
import { proxyStartCommand, proxyStatusCommand, proxySetupCommand, proxyGuardCommand, proxyInstallCommand, proxyUninstallCommand, } from "./commands/proxy.js";
|
|
16
|
-
import { AuthCommandFactory } from "./factories/authCommandFactory.js";
|
|
17
17
|
// Enhanced CLI with Professional UX
|
|
18
18
|
export function initializeCliParser() {
|
|
19
19
|
return (yargs(hideBin(process.argv))
|