@dataflint/mcp-server 1.0.12 → 1.0.15
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/dist/auth/auth-strategy-factory.d.ts +60 -0
- package/dist/auth/auth-strategy-factory.d.ts.map +1 -0
- package/dist/auth/auth-strategy-factory.js +113 -0
- package/dist/auth/auth-strategy-factory.js.map +1 -0
- package/dist/auth/auth0-m2m-service.d.ts +74 -0
- package/dist/auth/auth0-m2m-service.d.ts.map +1 -0
- package/dist/auth/auth0-m2m-service.js +195 -0
- package/dist/auth/auth0-m2m-service.js.map +1 -0
- package/dist/auth/auth0-service.d.ts +64 -0
- package/dist/auth/auth0-service.d.ts.map +1 -0
- package/dist/auth/auth0-service.js +326 -0
- package/dist/auth/auth0-service.js.map +1 -0
- package/dist/auth/customer-auth-configs.d.ts +31 -0
- package/dist/auth/customer-auth-configs.d.ts.map +1 -0
- package/dist/auth/customer-auth-configs.js +39 -0
- package/dist/auth/customer-auth-configs.js.map +1 -0
- package/dist/auth/index.d.ts +75 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +137 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/secrets/aws-secrets-provider.d.ts +45 -0
- package/dist/auth/secrets/aws-secrets-provider.d.ts.map +1 -0
- package/dist/auth/secrets/aws-secrets-provider.js +123 -0
- package/dist/auth/secrets/aws-secrets-provider.js.map +1 -0
- package/dist/auth/secrets/index.d.ts +12 -0
- package/dist/auth/secrets/index.d.ts.map +1 -0
- package/dist/auth/secrets/index.js +17 -0
- package/dist/auth/secrets/index.js.map +1 -0
- package/dist/auth/secrets/local-file-secrets-provider.d.ts +47 -0
- package/dist/auth/secrets/local-file-secrets-provider.d.ts.map +1 -0
- package/dist/auth/secrets/local-file-secrets-provider.js +151 -0
- package/dist/auth/secrets/local-file-secrets-provider.js.map +1 -0
- package/dist/auth/secrets/secrets-provider.d.ts +54 -0
- package/dist/auth/secrets/secrets-provider.d.ts.map +1 -0
- package/dist/auth/secrets/secrets-provider.js +106 -0
- package/dist/auth/secrets/secrets-provider.js.map +1 -0
- package/dist/auth/secrets/types.d.ts +32 -0
- package/dist/auth/secrets/types.d.ts.map +1 -0
- package/dist/auth/secrets/types.js +8 -0
- package/dist/auth/secrets/types.js.map +1 -0
- package/dist/auth/service-account-service.d.ts +77 -0
- package/dist/auth/service-account-service.d.ts.map +1 -0
- package/dist/auth/service-account-service.js +209 -0
- package/dist/auth/service-account-service.js.map +1 -0
- package/dist/auth/types.d.ts +140 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +30 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/dataflint-server-service.d.ts +1 -1
- package/dist/dataflint-server-service.d.ts.map +1 -1
- package/dist/dataflint-server-service.js +27 -2
- package/dist/dataflint-server-service.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +4 -4
- package/dist/server.js.map +1 -1
- package/dist/standalone/config.d.ts +10 -9
- package/dist/standalone/config.d.ts.map +1 -1
- package/dist/standalone/config.js +291 -23948
- package/dist/standalone/config.js.map +1 -7
- package/dist/standalone/logger.js +2 -2
- package/dist/standalone/logger.js.map +1 -1
- package/dist/standalone/server.d.ts.map +1 -1
- package/dist/standalone/server.js +13 -10
- package/dist/standalone/server.js.map +1 -1
- package/dist/standalone/stdio-transport.d.ts +1 -1
- package/dist/standalone/stdio-transport.d.ts.map +1 -1
- package/dist/standalone/stdio-transport.js +2 -2
- package/dist/standalone/stdio-transport.js.map +1 -1
- package/dist/tools/highlight-tools.js +5 -3
- package/dist/tools/highlight-tools.js.map +1 -1
- package/dist/types.d.ts +4 -17
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -1
- package/package.json +2 -3
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Strategy Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates the appropriate authentication strategy based on configuration and environment.
|
|
5
|
+
*
|
|
6
|
+
* Strategy Priority (for MCP standalone server):
|
|
7
|
+
* 1. Service Account - M2M_SA_TOKEN_PATH env var → read JWT from file
|
|
8
|
+
* 2. Auth0 M2M - Secrets available → client credentials grant
|
|
9
|
+
* 3. Auth0 User - Interactive OAuth2/PKCE flow (fallback, returned as null)
|
|
10
|
+
*
|
|
11
|
+
* Note: VS Code Extension only uses Auth0 User flow directly (no factory needed).
|
|
12
|
+
*/
|
|
13
|
+
import { IAuthStrategy, AuthStrategyType, IAuthConfigProvider, IAuthLogger } from "./types";
|
|
14
|
+
/**
|
|
15
|
+
* Result from strategy creation
|
|
16
|
+
*/
|
|
17
|
+
export interface StrategyResult {
|
|
18
|
+
/**
|
|
19
|
+
* The created strategy, or null if fallback to interactive OAuth is needed
|
|
20
|
+
*/
|
|
21
|
+
strategy: IAuthStrategy | null;
|
|
22
|
+
/**
|
|
23
|
+
* The type of strategy created (or 'auth0_user' if null strategy)
|
|
24
|
+
*/
|
|
25
|
+
strategyType: AuthStrategyType;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Factory for creating authentication strategies
|
|
29
|
+
*
|
|
30
|
+
* This factory determines the best authentication strategy based on:
|
|
31
|
+
* 1. Environment configuration (M2M_SA_TOKEN_PATH)
|
|
32
|
+
* 2. Available secrets (AWS Secrets Manager or local file)
|
|
33
|
+
* 3. Falls back to interactive OAuth if no M2M strategy is available
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const factory = new AuthStrategyFactory(configService, logger);
|
|
38
|
+
* const { strategy, strategyType } = await factory.createStrategy();
|
|
39
|
+
*
|
|
40
|
+
* if (strategy) {
|
|
41
|
+
* // Use M2M strategy (ServiceAccount or Auth0 M2M)
|
|
42
|
+
* await strategy.initialize();
|
|
43
|
+
* const token = await strategy.getToken();
|
|
44
|
+
* } else {
|
|
45
|
+
* // Fall back to interactive Auth0 OAuth flow
|
|
46
|
+
* const auth0Service = new Auth0Service(...);
|
|
47
|
+
* await auth0Service.authenticate();
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare class AuthStrategyFactory {
|
|
52
|
+
private configProvider;
|
|
53
|
+
private logger;
|
|
54
|
+
constructor(configProvider: IAuthConfigProvider, logger?: IAuthLogger);
|
|
55
|
+
createStrategy(): Promise<StrategyResult>;
|
|
56
|
+
private buildServiceAccountStrategy;
|
|
57
|
+
private buildAuth0M2MStrategy;
|
|
58
|
+
isM2MAvailable(): Promise<boolean>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=auth-strategy-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-strategy-factory.d.ts","sourceRoot":"","sources":["../../src/auth/auth-strategy-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EAGd,MAAM,SAAS,CAAC;AAKjB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B;;OAEG;IACH,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IAE/B;;OAEG;IACH,YAAY,EAAE,gBAAgB,CAAC;CAClC;AAYD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,MAAM,CAAc;gBAEhB,cAAc,EAAE,mBAAmB,EAAE,MAAM,CAAC,EAAE,WAAW;IAK/D,cAAc,IAAI,OAAO,CAAC,cAAc,CAAC;IAiB/C,OAAO,CAAC,2BAA2B;YAcrB,qBAAqB;IAqC7B,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;CAc3C"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Authentication Strategy Factory
|
|
4
|
+
*
|
|
5
|
+
* Creates the appropriate authentication strategy based on configuration and environment.
|
|
6
|
+
*
|
|
7
|
+
* Strategy Priority (for MCP standalone server):
|
|
8
|
+
* 1. Service Account - M2M_SA_TOKEN_PATH env var → read JWT from file
|
|
9
|
+
* 2. Auth0 M2M - Secrets available → client credentials grant
|
|
10
|
+
* 3. Auth0 User - Interactive OAuth2/PKCE flow (fallback, returned as null)
|
|
11
|
+
*
|
|
12
|
+
* Note: VS Code Extension only uses Auth0 User flow directly (no factory needed).
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AuthStrategyFactory = void 0;
|
|
16
|
+
const types_1 = require("./types");
|
|
17
|
+
const service_account_service_1 = require("./service-account-service");
|
|
18
|
+
const auth0_m2m_service_1 = require("./auth0-m2m-service");
|
|
19
|
+
const secrets_1 = require("./secrets");
|
|
20
|
+
/**
|
|
21
|
+
* Default no-op logger
|
|
22
|
+
*/
|
|
23
|
+
const noopLogger = {
|
|
24
|
+
info: () => { },
|
|
25
|
+
warn: () => { },
|
|
26
|
+
error: () => { },
|
|
27
|
+
debug: () => { },
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Factory for creating authentication strategies
|
|
31
|
+
*
|
|
32
|
+
* This factory determines the best authentication strategy based on:
|
|
33
|
+
* 1. Environment configuration (M2M_SA_TOKEN_PATH)
|
|
34
|
+
* 2. Available secrets (AWS Secrets Manager or local file)
|
|
35
|
+
* 3. Falls back to interactive OAuth if no M2M strategy is available
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const factory = new AuthStrategyFactory(configService, logger);
|
|
40
|
+
* const { strategy, strategyType } = await factory.createStrategy();
|
|
41
|
+
*
|
|
42
|
+
* if (strategy) {
|
|
43
|
+
* // Use M2M strategy (ServiceAccount or Auth0 M2M)
|
|
44
|
+
* await strategy.initialize();
|
|
45
|
+
* const token = await strategy.getToken();
|
|
46
|
+
* } else {
|
|
47
|
+
* // Fall back to interactive Auth0 OAuth flow
|
|
48
|
+
* const auth0Service = new Auth0Service(...);
|
|
49
|
+
* await auth0Service.authenticate();
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
class AuthStrategyFactory {
|
|
54
|
+
configProvider;
|
|
55
|
+
logger;
|
|
56
|
+
constructor(configProvider, logger) {
|
|
57
|
+
this.configProvider = configProvider;
|
|
58
|
+
this.logger = logger || noopLogger;
|
|
59
|
+
}
|
|
60
|
+
async createStrategy() {
|
|
61
|
+
const m2mMode = this.configProvider.getM2MMode();
|
|
62
|
+
switch (m2mMode.type) {
|
|
63
|
+
case types_1.M2MType.SERVICE_ACCOUNT:
|
|
64
|
+
return this.buildServiceAccountStrategy(m2mMode);
|
|
65
|
+
case types_1.M2MType.AUTH0_M2M:
|
|
66
|
+
return await this.buildAuth0M2MStrategy(m2mMode);
|
|
67
|
+
default:
|
|
68
|
+
this.logger.info("Using interactive OAuth flow");
|
|
69
|
+
return {
|
|
70
|
+
strategy: null,
|
|
71
|
+
strategyType: types_1.AuthStrategyType.AUTH0_USER,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
buildServiceAccountStrategy(mode) {
|
|
76
|
+
this.logger.info(`Service Account mode: ${mode.tokenPath}`);
|
|
77
|
+
return {
|
|
78
|
+
strategy: new service_account_service_1.ServiceAccountService(mode.tokenPath, mode.tenantId, this.logger),
|
|
79
|
+
strategyType: types_1.AuthStrategyType.SERVICE_ACCOUNT,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async buildAuth0M2MStrategy(mode) {
|
|
83
|
+
const secretsProvider = new secrets_1.SecretsProvider(this.configProvider.getEnvironment(), this.logger);
|
|
84
|
+
if (!(await secretsProvider.isAvailable())) {
|
|
85
|
+
throw new Error(`Auth0 M2M mode requires a secrets provider. ` +
|
|
86
|
+
`M2M_AUTH0_SECRET_NAME is set to "${mode.secretName}" but no secrets provider is available. ` +
|
|
87
|
+
`Ensure AWS credentials are configured or use Service Account mode instead.`);
|
|
88
|
+
}
|
|
89
|
+
const credentials = await secretsProvider.loadAuth0M2MCredentials(mode.secretName);
|
|
90
|
+
if (!credentials) {
|
|
91
|
+
throw new Error(`Auth0 M2M credentials not found: "${mode.secretName}". ` +
|
|
92
|
+
`Ensure the secret exists and contains valid Auth0 M2M credentials.`);
|
|
93
|
+
}
|
|
94
|
+
this.logger.info(`Auth0 M2M mode: ${mode.secretName}`);
|
|
95
|
+
return {
|
|
96
|
+
strategy: new auth0_m2m_service_1.Auth0M2MService(credentials, mode.tenantId, this.logger),
|
|
97
|
+
strategyType: types_1.AuthStrategyType.AUTH0_M2M,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async isM2MAvailable() {
|
|
101
|
+
const mode = this.configProvider.getM2MMode();
|
|
102
|
+
if (mode.type === types_1.M2MType.SERVICE_ACCOUNT) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (mode.type === types_1.M2MType.AUTH0_M2M) {
|
|
106
|
+
const secretsProvider = new secrets_1.SecretsProvider(this.configProvider.getEnvironment(), this.logger);
|
|
107
|
+
return secretsProvider.isAvailable();
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.AuthStrategyFactory = AuthStrategyFactory;
|
|
113
|
+
//# sourceMappingURL=auth-strategy-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-strategy-factory.js","sourceRoot":"","sources":["../../src/auth/auth-strategy-factory.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,mCAOiB;AACjB,uEAAkE;AAClE,2DAAsD;AACtD,uCAA4C;AAiB5C;;GAEG;AACH,MAAM,UAAU,GAAgB;IAC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AAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA3FD,kDA2FC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth0 Machine-to-Machine (M2M) Authentication Service
|
|
3
|
+
*
|
|
4
|
+
* Provides authentication using Auth0's client credentials grant.
|
|
5
|
+
* This is used for server-to-server communication where no user interaction is needed.
|
|
6
|
+
*
|
|
7
|
+
* The service automatically caches tokens and refreshes them before expiration.
|
|
8
|
+
*/
|
|
9
|
+
import { IAuthStrategy, AuthStrategyType, AuthUserInfo, Auth0M2MCredentials, IAuthLogger } from "./types";
|
|
10
|
+
/**
|
|
11
|
+
* Auth0 M2M authentication strategy using client credentials grant
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const credentials: Auth0M2MCredentials = {
|
|
16
|
+
* client_id: 'my-client-id',
|
|
17
|
+
* client_secret: 'my-client-secret',
|
|
18
|
+
* domain: 'https://my-tenant.auth0.com',
|
|
19
|
+
* audience: 'https://api.example.com',
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* const service = new Auth0M2MService(credentials, 'tenant-123', logger);
|
|
23
|
+
* await service.initialize();
|
|
24
|
+
* const token = await service.getToken();
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class Auth0M2MService implements IAuthStrategy {
|
|
28
|
+
private credentials;
|
|
29
|
+
private tenantId;
|
|
30
|
+
private tokenCache;
|
|
31
|
+
private logger;
|
|
32
|
+
private initialized;
|
|
33
|
+
/**
|
|
34
|
+
* Token expiry buffer in milliseconds (5 minutes)
|
|
35
|
+
* Tokens will be refreshed this long before actual expiration
|
|
36
|
+
*/
|
|
37
|
+
private static readonly EXPIRY_BUFFER_MS;
|
|
38
|
+
constructor(credentials: Auth0M2MCredentials, tenantId?: string, logger?: IAuthLogger);
|
|
39
|
+
/**
|
|
40
|
+
* Get the strategy type identifier
|
|
41
|
+
*/
|
|
42
|
+
getType(): AuthStrategyType;
|
|
43
|
+
/**
|
|
44
|
+
* Initialize the M2M service
|
|
45
|
+
* Validates credentials format and performs initial token fetch
|
|
46
|
+
*/
|
|
47
|
+
initialize(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Get a valid access token, fetching a new one if cache is expired
|
|
50
|
+
*/
|
|
51
|
+
getToken(): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Force refresh the token by clearing cache and fetching a new one
|
|
54
|
+
*/
|
|
55
|
+
refreshToken(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Check if currently authenticated (credentials are valid)
|
|
58
|
+
*/
|
|
59
|
+
isAuthenticated(): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* Get user information for the M2M client
|
|
62
|
+
* Returns synthetic user info since M2M clients don't have traditional user profiles
|
|
63
|
+
*/
|
|
64
|
+
getUserInfo(): Promise<AuthUserInfo>;
|
|
65
|
+
/**
|
|
66
|
+
* Get the tenant ID associated with this M2M client
|
|
67
|
+
*/
|
|
68
|
+
getTenantId(): string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Fetch a new token from Auth0 using client credentials grant
|
|
71
|
+
*/
|
|
72
|
+
private fetchNewToken;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=auth0-m2m-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth0-m2m-service.d.ts","sourceRoot":"","sources":["../../src/auth/auth0-m2m-service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACd,MAAM,SAAS,CAAC;AA2BjB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,eAAgB,YAAW,aAAa;IACjD,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,WAAW,CAAS;IAE5B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAiB;gBAGrD,WAAW,EAAE,mBAAmB,EAChC,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,WAAW;IAaxB;;OAEG;IACH,OAAO,IAAI,gBAAgB;IAI3B;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA4BjC;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAoBjC;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAOnC;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IASzC;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,YAAY,CAAC;IAS1C;;OAEG;IACH,WAAW,IAAI,MAAM,GAAG,SAAS;IAIjC;;OAEG;YACW,aAAa;CAgE9B"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Auth0 Machine-to-Machine (M2M) Authentication Service
|
|
4
|
+
*
|
|
5
|
+
* Provides authentication using Auth0's client credentials grant.
|
|
6
|
+
* This is used for server-to-server communication where no user interaction is needed.
|
|
7
|
+
*
|
|
8
|
+
* The service automatically caches tokens and refreshes them before expiration.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.Auth0M2MService = void 0;
|
|
12
|
+
const types_1 = require("./types");
|
|
13
|
+
/**
|
|
14
|
+
* Default no-op logger for when no logger is provided
|
|
15
|
+
*/
|
|
16
|
+
const noopLogger = {
|
|
17
|
+
info: () => { },
|
|
18
|
+
warn: () => { },
|
|
19
|
+
error: () => { },
|
|
20
|
+
debug: () => { },
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Auth0 M2M authentication strategy using client credentials grant
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const credentials: Auth0M2MCredentials = {
|
|
28
|
+
* client_id: 'my-client-id',
|
|
29
|
+
* client_secret: 'my-client-secret',
|
|
30
|
+
* domain: 'https://my-tenant.auth0.com',
|
|
31
|
+
* audience: 'https://api.example.com',
|
|
32
|
+
* };
|
|
33
|
+
*
|
|
34
|
+
* const service = new Auth0M2MService(credentials, 'tenant-123', logger);
|
|
35
|
+
* await service.initialize();
|
|
36
|
+
* const token = await service.getToken();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
class Auth0M2MService {
|
|
40
|
+
credentials;
|
|
41
|
+
tenantId;
|
|
42
|
+
tokenCache = null;
|
|
43
|
+
logger;
|
|
44
|
+
initialized = false;
|
|
45
|
+
/**
|
|
46
|
+
* Token expiry buffer in milliseconds (5 minutes)
|
|
47
|
+
* Tokens will be refreshed this long before actual expiration
|
|
48
|
+
*/
|
|
49
|
+
static EXPIRY_BUFFER_MS = 5 * 60 * 1000;
|
|
50
|
+
constructor(credentials, tenantId, logger) {
|
|
51
|
+
this.credentials = credentials;
|
|
52
|
+
this.tenantId = tenantId;
|
|
53
|
+
this.logger = logger || noopLogger;
|
|
54
|
+
// Security: only log partial client_id
|
|
55
|
+
const clientIdPrefix = credentials.client_id.substring(0, 8);
|
|
56
|
+
this.logger.info(`Auth0M2MService created for client: ${clientIdPrefix}...`);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get the strategy type identifier
|
|
60
|
+
*/
|
|
61
|
+
getType() {
|
|
62
|
+
return types_1.AuthStrategyType.AUTH0_M2M;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Initialize the M2M service
|
|
66
|
+
* Validates credentials format and performs initial token fetch
|
|
67
|
+
*/
|
|
68
|
+
async initialize() {
|
|
69
|
+
if (this.initialized) {
|
|
70
|
+
this.logger.debug("Auth0M2MService already initialized");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.logger.info("Initializing Auth0M2MService...");
|
|
74
|
+
// Validate credentials
|
|
75
|
+
if (!this.credentials.client_id || !this.credentials.client_secret) {
|
|
76
|
+
throw new Error("M2M credentials missing client_id or client_secret");
|
|
77
|
+
}
|
|
78
|
+
if (!this.credentials.domain) {
|
|
79
|
+
throw new Error("M2M credentials missing domain");
|
|
80
|
+
}
|
|
81
|
+
if (!this.credentials.audience) {
|
|
82
|
+
throw new Error("M2M credentials missing audience");
|
|
83
|
+
}
|
|
84
|
+
// Perform initial token fetch to validate credentials
|
|
85
|
+
await this.fetchNewToken();
|
|
86
|
+
this.initialized = true;
|
|
87
|
+
this.logger.info("Auth0M2MService initialized successfully");
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get a valid access token, fetching a new one if cache is expired
|
|
91
|
+
*/
|
|
92
|
+
async getToken() {
|
|
93
|
+
const now = Date.now();
|
|
94
|
+
// Check if we have a valid cached token (with buffer)
|
|
95
|
+
if (this.tokenCache &&
|
|
96
|
+
now < this.tokenCache.expiresAt - Auth0M2MService.EXPIRY_BUFFER_MS) {
|
|
97
|
+
this.logger.debug("Using cached M2M token");
|
|
98
|
+
return this.tokenCache.accessToken;
|
|
99
|
+
}
|
|
100
|
+
this.logger.info("M2M token expired or not cached, fetching new token...");
|
|
101
|
+
await this.fetchNewToken();
|
|
102
|
+
return this.tokenCache.accessToken;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Force refresh the token by clearing cache and fetching a new one
|
|
106
|
+
*/
|
|
107
|
+
async refreshToken() {
|
|
108
|
+
this.logger.info("Force refreshing M2M token...");
|
|
109
|
+
this.tokenCache = null;
|
|
110
|
+
await this.fetchNewToken();
|
|
111
|
+
this.logger.info("M2M token refreshed");
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Check if currently authenticated (credentials are valid)
|
|
115
|
+
*/
|
|
116
|
+
async isAuthenticated() {
|
|
117
|
+
try {
|
|
118
|
+
await this.getToken();
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get user information for the M2M client
|
|
127
|
+
* Returns synthetic user info since M2M clients don't have traditional user profiles
|
|
128
|
+
*/
|
|
129
|
+
async getUserInfo() {
|
|
130
|
+
const clientIdPrefix = this.credentials.client_id.substring(0, 8);
|
|
131
|
+
return {
|
|
132
|
+
sub: `m2m-client-${clientIdPrefix}`,
|
|
133
|
+
name: "M2M Client",
|
|
134
|
+
...(this.tenantId && { tenant_id: this.tenantId }),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get the tenant ID associated with this M2M client
|
|
139
|
+
*/
|
|
140
|
+
getTenantId() {
|
|
141
|
+
return this.tenantId;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Fetch a new token from Auth0 using client credentials grant
|
|
145
|
+
*/
|
|
146
|
+
async fetchNewToken() {
|
|
147
|
+
const domain = this.credentials.domain.startsWith("http")
|
|
148
|
+
? this.credentials.domain
|
|
149
|
+
: `https://${this.credentials.domain}`;
|
|
150
|
+
const tokenUrl = `${domain.replace(/\/$/, "")}/oauth/token`;
|
|
151
|
+
this.logger.debug(`Fetching M2M token from: ${tokenUrl}`);
|
|
152
|
+
const requestBody = {
|
|
153
|
+
grant_type: "client_credentials",
|
|
154
|
+
client_id: this.credentials.client_id,
|
|
155
|
+
client_secret: this.credentials.client_secret,
|
|
156
|
+
audience: this.credentials.audience,
|
|
157
|
+
};
|
|
158
|
+
try {
|
|
159
|
+
const response = await fetch(tokenUrl, {
|
|
160
|
+
method: "POST",
|
|
161
|
+
headers: {
|
|
162
|
+
"Content-Type": "application/json",
|
|
163
|
+
},
|
|
164
|
+
body: JSON.stringify(requestBody),
|
|
165
|
+
});
|
|
166
|
+
if (!response.ok) {
|
|
167
|
+
this.logger.error(`M2M token request failed: ${response.status}`);
|
|
168
|
+
throw new Error(`Auth0 M2M token request failed with status ${response.status}`);
|
|
169
|
+
}
|
|
170
|
+
const tokenResponse = (await response.json());
|
|
171
|
+
if (!tokenResponse.access_token) {
|
|
172
|
+
throw new Error("Auth0 response missing access_token");
|
|
173
|
+
}
|
|
174
|
+
const expiresIn = tokenResponse.expires_in || 3600; // Default to 1 hour
|
|
175
|
+
const expiresAt = Date.now() + expiresIn * 1000;
|
|
176
|
+
this.tokenCache = {
|
|
177
|
+
accessToken: tokenResponse.access_token,
|
|
178
|
+
expiresAt,
|
|
179
|
+
};
|
|
180
|
+
const expiresInMinutes = Math.floor(expiresIn / 60);
|
|
181
|
+
this.logger.info(`M2M token obtained${this.tenantId ? ` for tenant ${this.tenantId}` : ""}: expires in ${expiresInMinutes} minutes`);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
// Clear cache on error
|
|
185
|
+
this.tokenCache = null;
|
|
186
|
+
if (error instanceof Error) {
|
|
187
|
+
this.logger.error("Failed to fetch M2M token", error);
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
throw new Error(`Failed to fetch M2M token: ${error}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.Auth0M2MService = Auth0M2MService;
|
|
195
|
+
//# sourceMappingURL=auth0-m2m-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth0-m2m-service.js","sourceRoot":"","sources":["../../src/auth/auth0-m2m-service.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,mCAMiB;AAOjB;;GAEG;AACH,MAAM,UAAU,GAAgB;IAC5B,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;IACd,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;IACd,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;IACf,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;CAClB,CAAC;AAYF;;;;;;;;;;;;;;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AC3D,CAAC;IACL,CAAC;;AAvML,0CAwMC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth0 OAuth2/PKCE Authentication Service
|
|
3
|
+
*
|
|
4
|
+
* Provides interactive browser-based authentication using Auth0 with PKCE flow.
|
|
5
|
+
* This is the primary authentication method for user-facing applications.
|
|
6
|
+
*/
|
|
7
|
+
import { AuthResult, OpenUrlHandler, ConfigProvider, IAuthLogger } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Auth0 service for interactive OAuth2/PKCE authentication
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const auth0Service = new Auth0Service(
|
|
14
|
+
* async (url) => { await open(url); },
|
|
15
|
+
* () => configService.getAuthConfig(),
|
|
16
|
+
* logger
|
|
17
|
+
* );
|
|
18
|
+
*
|
|
19
|
+
* await auth0Service.initialize();
|
|
20
|
+
* const result = await auth0Service.authenticate();
|
|
21
|
+
* console.log('Access Token:', result.accessToken);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class Auth0Service {
|
|
25
|
+
private config;
|
|
26
|
+
private redirectUri;
|
|
27
|
+
private callbackPort;
|
|
28
|
+
private client;
|
|
29
|
+
private issuer;
|
|
30
|
+
private initialized;
|
|
31
|
+
private openUrlHandler;
|
|
32
|
+
private logger;
|
|
33
|
+
constructor(openUrlHandler: OpenUrlHandler, configProvider: ConfigProvider, logger?: IAuthLogger, callbackPort?: number);
|
|
34
|
+
/**
|
|
35
|
+
* Initialize the Auth0 client by discovering the issuer metadata
|
|
36
|
+
*/
|
|
37
|
+
initialize(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Start the authentication flow
|
|
40
|
+
*/
|
|
41
|
+
authenticate(): Promise<AuthResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Get user information using the access token
|
|
44
|
+
*/
|
|
45
|
+
getUserInfo(accessToken: string): Promise<unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* Refresh the access token using refresh token
|
|
48
|
+
*/
|
|
49
|
+
refreshToken(refreshToken: string): Promise<AuthResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Process token set and return structured result
|
|
52
|
+
*/
|
|
53
|
+
private processTokenSet;
|
|
54
|
+
/**
|
|
55
|
+
* Check if a token is expired
|
|
56
|
+
*/
|
|
57
|
+
isTokenExpired(authResult: AuthResult): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Logout (revoke tokens if supported)
|
|
60
|
+
*/
|
|
61
|
+
logout(accessToken: string): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
export type { AuthResult };
|
|
64
|
+
//# sourceMappingURL=auth0-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth0-service.d.ts","sourceRoot":"","sources":["../../src/auth/auth0-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAEH,UAAU,EACV,cAAc,EACd,cAAc,EACd,WAAW,EACd,MAAM,SAAS,CAAC;AAkBjB;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,YAAY;IACrB,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,MAAM,CAAc;gBAGxB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,cAAc,EAC9B,MAAM,CAAC,EAAE,WAAW,EACpB,YAAY,GAAE,MAAc;IAehC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA6DjC;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,UAAU,CAAC;IAkHzC;;OAEG;IACG,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoBxD;;OAEG;IACG,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAmB7D;;OAEG;IACH,OAAO,CAAC,eAAe;IA+BvB;;OAEG;IACH,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO;IA2B/C;;OAEG;IACG,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAanD;AAGD,YAAY,EAAE,UAAU,EAAE,CAAC"}
|