mcp-wordpress 1.2.2 → 1.3.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/README.md +210 -182
- package/dist/cache/CacheInvalidation.d.ts +3 -3
- package/dist/cache/CacheInvalidation.d.ts.map +1 -1
- package/dist/cache/CacheInvalidation.js +119 -119
- package/dist/cache/CacheInvalidation.js.map +1 -1
- package/dist/cache/CacheManager.d.ts +5 -0
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +26 -16
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts.map +1 -1
- package/dist/cache/HttpCacheWrapper.js +29 -29
- package/dist/cache/HttpCacheWrapper.js.map +1 -1
- package/dist/cache/__tests__/CacheInvalidation.test.js +96 -94
- package/dist/cache/__tests__/CacheInvalidation.test.js.map +1 -1
- package/dist/cache/__tests__/CacheManager.test.js +113 -113
- package/dist/cache/__tests__/CacheManager.test.js.map +1 -1
- package/dist/cache/__tests__/CachedWordPressClient.test.js +102 -99
- package/dist/cache/__tests__/CachedWordPressClient.test.js.map +1 -1
- package/dist/cache/__tests__/HttpCacheWrapper.test.js +98 -95
- package/dist/cache/__tests__/HttpCacheWrapper.test.js.map +1 -1
- package/dist/cache/index.d.ts +7 -7
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +4 -4
- package/dist/cache/index.js.map +1 -1
- package/dist/client/CachedWordPressClient.d.ts +4 -4
- package/dist/client/CachedWordPressClient.d.ts.map +1 -1
- package/dist/client/CachedWordPressClient.js +55 -51
- package/dist/client/CachedWordPressClient.js.map +1 -1
- package/dist/client/api.d.ts +10 -10
- package/dist/client/api.js +158 -158
- package/dist/client/api.js.map +1 -1
- package/dist/client/auth.d.ts +2 -2
- package/dist/client/auth.js +72 -72
- package/dist/client/managers/AuthenticationManager.d.ts +2 -2
- package/dist/client/managers/AuthenticationManager.js +46 -46
- package/dist/client/managers/BaseManager.d.ts +1 -1
- package/dist/client/managers/BaseManager.js +9 -9
- package/dist/client/managers/RequestManager.d.ts +5 -3
- package/dist/client/managers/RequestManager.d.ts.map +1 -1
- package/dist/client/managers/RequestManager.js +39 -19
- package/dist/client/managers/RequestManager.js.map +1 -1
- package/dist/client/managers/index.d.ts +3 -3
- package/dist/client/managers/index.js +3 -3
- package/dist/config/ConfigurationSchema.d.ts +2 -2
- package/dist/config/ConfigurationSchema.d.ts.map +1 -1
- package/dist/config/ConfigurationSchema.js +40 -40
- package/dist/config/ConfigurationSchema.js.map +1 -1
- package/dist/config/ServerConfiguration.d.ts +2 -2
- package/dist/config/ServerConfiguration.js +35 -35
- package/dist/config/ServerConfiguration.js.map +1 -1
- package/dist/docs/DocumentationGenerator.d.ts.map +1 -1
- package/dist/docs/DocumentationGenerator.js +296 -255
- package/dist/docs/DocumentationGenerator.js.map +1 -1
- package/dist/docs/MarkdownFormatter.d.ts +1 -1
- package/dist/docs/MarkdownFormatter.d.ts.map +1 -1
- package/dist/docs/MarkdownFormatter.js +60 -51
- package/dist/docs/MarkdownFormatter.js.map +1 -1
- package/dist/docs/index.d.ts +3 -3
- package/dist/docs/index.d.ts.map +1 -1
- package/dist/docs/index.js +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/dist/mcp-wordpress-1.3.0.tgz +0 -0
- package/dist/performance/MetricsCollector.d.ts +3 -3
- package/dist/performance/MetricsCollector.d.ts.map +1 -1
- package/dist/performance/MetricsCollector.js +33 -27
- package/dist/performance/MetricsCollector.js.map +1 -1
- package/dist/performance/PerformanceAnalytics.d.ts +12 -12
- package/dist/performance/PerformanceAnalytics.d.ts.map +1 -1
- package/dist/performance/PerformanceAnalytics.js +200 -154
- package/dist/performance/PerformanceAnalytics.js.map +1 -1
- package/dist/performance/PerformanceMonitor.d.ts +5 -5
- package/dist/performance/PerformanceMonitor.d.ts.map +1 -1
- package/dist/performance/PerformanceMonitor.js +53 -52
- package/dist/performance/PerformanceMonitor.js.map +1 -1
- package/dist/performance/index.d.ts +6 -6
- package/dist/performance/index.d.ts.map +1 -1
- package/dist/performance/index.js +3 -3
- package/dist/security/InputValidator.d.ts +1 -1
- package/dist/security/InputValidator.d.ts.map +1 -1
- package/dist/security/InputValidator.js +111 -88
- package/dist/security/InputValidator.js.map +1 -1
- package/dist/security/SecurityConfig.d.ts +5 -5
- package/dist/security/SecurityConfig.js +92 -92
- package/dist/security/SecurityConfig.js.map +1 -1
- package/dist/server/ConnectionTester.d.ts +1 -1
- package/dist/server/ConnectionTester.d.ts.map +1 -1
- package/dist/server/ConnectionTester.js +4 -4
- package/dist/server/ConnectionTester.js.map +1 -1
- package/dist/server/ToolRegistry.d.ts +2 -2
- package/dist/server/ToolRegistry.d.ts.map +1 -1
- package/dist/server/ToolRegistry.js +35 -32
- package/dist/server/ToolRegistry.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -2
- package/dist/tools/BaseToolManager.js +5 -5
- package/dist/tools/auth.d.ts +2 -2
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +32 -31
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/cache.d.ts +1 -1
- package/dist/tools/cache.d.ts.map +1 -1
- package/dist/tools/cache.js +71 -71
- package/dist/tools/cache.js.map +1 -1
- package/dist/tools/comments.d.ts +2 -2
- package/dist/tools/comments.d.ts.map +1 -1
- package/dist/tools/comments.js +79 -79
- package/dist/tools/comments.js.map +1 -1
- package/dist/tools/index.d.ts +10 -10
- package/dist/tools/index.js +10 -10
- package/dist/tools/media.d.ts +2 -2
- package/dist/tools/media.js +80 -80
- package/dist/tools/pages.d.ts +2 -2
- package/dist/tools/pages.d.ts.map +1 -1
- package/dist/tools/pages.js +75 -75
- package/dist/tools/pages.js.map +1 -1
- package/dist/tools/performance.d.ts +1 -1
- package/dist/tools/performance.d.ts.map +1 -1
- package/dist/tools/performance.js +311 -287
- package/dist/tools/performance.js.map +1 -1
- package/dist/tools/posts.d.ts +2 -2
- package/dist/tools/posts.d.ts.map +1 -1
- package/dist/tools/posts.js +94 -94
- package/dist/tools/posts.js.map +1 -1
- package/dist/tools/site.d.ts +2 -2
- package/dist/tools/site.d.ts.map +1 -1
- package/dist/tools/site.js +60 -60
- package/dist/tools/site.js.map +1 -1
- package/dist/tools/taxonomies.d.ts +2 -2
- package/dist/tools/taxonomies.js +89 -89
- package/dist/tools/users.d.ts +2 -2
- package/dist/tools/users.js +68 -68
- package/dist/tools/users.js.map +1 -1
- package/dist/types/client.d.ts +13 -13
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client.js +12 -12
- package/dist/types/client.js.map +1 -1
- package/dist/types/index.d.ts +19 -19
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -3
- package/dist/types/mcp.d.ts +7 -7
- package/dist/types/wordpress.d.ts +21 -21
- package/dist/types/wordpress.d.ts.map +1 -1
- package/dist/utils/debug.d.ts +2 -2
- package/dist/utils/debug.js +28 -28
- package/dist/utils/error.d.ts.map +1 -1
- package/dist/utils/error.js +13 -13
- package/dist/utils/error.js.map +1 -1
- package/dist/utils/toolWrapper.d.ts.map +1 -1
- package/dist/utils/toolWrapper.js +5 -5
- package/dist/utils/toolWrapper.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +41 -31
- package/dist/utils/validation.js.map +1 -1
- package/docs/CACHING.md +36 -2
- package/docs/DOCKER.md +24 -18
- package/docs/PERFORMANCE_MONITORING.md +49 -1
- package/docs/SECURITY_TESTING.md +30 -1
- package/docs/api/README.md +9 -1
- package/docs/api/summary.json +1 -1
- package/docs/contract-testing.md +24 -3
- package/docs/developer/GITHUB_ACTIONS_SETUP.md +8 -2
- package/docs/developer/MAINTENANCE.md +29 -3
- package/docs/developer/MIGRATION_GUIDE.md +13 -1
- package/docs/developer/NPM_AUTH_SETUP.md +13 -2
- package/docs/developer/REFACTORING.md +31 -1
- package/docs/releases/COMMUNITY_ANNOUNCEMENT_v1.1.2.md +18 -7
- package/docs/releases/RELEASE_NOTES_v1.1.2.md +31 -5
- package/docs/user-guides/DOCKER_SETUP.md +264 -0
- package/docs/user-guides/DTX_SETUP.md +327 -0
- package/docs/user-guides/NPM_SETUP.md +109 -0
- package/docs/user-guides/NPX_SETUP.md +281 -0
- package/docs/wordpress-rest-api-authentication-troubleshooting.md +13 -2
- package/package.json +27 -8
- package/src/cache/CacheInvalidation.ts +140 -132
- package/src/cache/CacheManager.ts +40 -29
- package/src/cache/HttpCacheWrapper.ts +105 -68
- package/src/cache/__tests__/CacheInvalidation.test.ts +123 -118
- package/src/cache/__tests__/CacheManager.test.ts +156 -152
- package/src/cache/__tests__/CachedWordPressClient.test.ts +131 -116
- package/src/cache/__tests__/HttpCacheWrapper.test.ts +118 -115
- package/src/cache/index.ts +13 -13
- package/src/client/CachedWordPressClient.ts +90 -80
- package/src/client/api.ts +205 -205
- package/src/client/auth.ts +80 -80
- package/src/client/managers/AuthenticationManager.ts +61 -61
- package/src/client/managers/BaseManager.ts +11 -11
- package/src/client/managers/RequestManager.ts +79 -47
- package/src/client/managers/index.ts +3 -3
- package/src/config/ConfigurationSchema.ts +44 -44
- package/src/config/ServerConfiguration.ts +39 -39
- package/src/docs/DocumentationGenerator.ts +402 -295
- package/src/docs/MarkdownFormatter.ts +94 -69
- package/src/docs/index.ts +4 -4
- package/src/index.ts +24 -21
- package/src/performance/MetricsCollector.ts +90 -58
- package/src/performance/PerformanceAnalytics.ts +386 -262
- package/src/performance/PerformanceMonitor.ts +152 -118
- package/src/performance/index.ts +9 -9
- package/src/security/InputValidator.ts +148 -91
- package/src/security/SecurityConfig.ts +94 -94
- package/src/server/ConnectionTester.ts +21 -15
- package/src/server/ToolRegistry.ts +64 -51
- package/src/server.ts +2 -2
- package/src/tools/BaseToolManager.ts +6 -6
- package/src/tools/auth.ts +42 -37
- package/src/tools/cache.ts +85 -81
- package/src/tools/comments.ts +93 -91
- package/src/tools/index.ts +10 -10
- package/src/tools/media.ts +89 -89
- package/src/tools/pages.ts +89 -87
- package/src/tools/performance.ts +443 -352
- package/src/tools/posts.ts +109 -107
- package/src/tools/site.ts +86 -77
- package/src/tools/taxonomies.ts +102 -102
- package/src/tools/users.ts +77 -77
- package/src/types/client.ts +157 -60
- package/src/types/index.ts +49 -27
- package/src/types/mcp.ts +15 -15
- package/src/types/wordpress.ts +57 -29
- package/src/utils/debug.ts +37 -37
- package/src/utils/error.ts +47 -25
- package/src/utils/toolWrapper.ts +12 -8
- package/src/utils/validation.ts +116 -65
- package/dist/client/WordPressClient.d.ts +0 -81
- package/dist/client/WordPressClient.d.ts.map +0 -1
- package/dist/client/WordPressClient.js +0 -354
- package/dist/client/WordPressClient.js.map +0 -1
- package/dist/performance/AnomalyDetector.d.ts +0 -63
- package/dist/performance/AnomalyDetector.d.ts.map +0 -1
- package/dist/performance/AnomalyDetector.js +0 -222
- package/dist/performance/AnomalyDetector.js.map +0 -1
- package/dist/performance/BenchmarkAnalyzer.d.ts +0 -67
- package/dist/performance/BenchmarkAnalyzer.d.ts.map +0 -1
- package/dist/performance/BenchmarkAnalyzer.js +0 -301
- package/dist/performance/BenchmarkAnalyzer.js.map +0 -1
- package/dist/performance/TrendAnalyzer.d.ts +0 -69
- package/dist/performance/TrendAnalyzer.d.ts.map +0 -1
- package/dist/performance/TrendAnalyzer.js +0 -203
- package/dist/performance/TrendAnalyzer.js.map +0 -1
- package/dist/tools/BaseToolClass.d.ts +0 -76
- package/dist/tools/BaseToolClass.d.ts.map +0 -1
- package/dist/tools/BaseToolClass.js +0 -104
- package/dist/tools/BaseToolClass.js.map +0 -1
- package/dist/tools/base.d.ts +0 -37
- package/dist/tools/base.d.ts.map +0 -1
- package/dist/tools/base.js +0 -60
- package/dist/tools/base.js.map +0 -1
- package/docs/user-guides/CLAUDE_DESKTOP_SETUP.md +0 -187
package/src/client/auth.ts
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
* Manages different authentication methods for WordPress REST API
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { logger } from
|
|
7
|
-
import { URL } from
|
|
6
|
+
import { logger } from "../utils/debug.js";
|
|
7
|
+
import { URL } from "url";
|
|
8
8
|
import type {
|
|
9
9
|
IAuthProvider,
|
|
10
10
|
IWordPressClient,
|
|
11
11
|
AuthMethod,
|
|
12
12
|
AuthConfig,
|
|
13
|
-
AuthenticationError as _AuthenticationError
|
|
14
|
-
} from
|
|
15
|
-
import type { WordPressUser } from
|
|
13
|
+
AuthenticationError as _AuthenticationError,
|
|
14
|
+
} from "../types/client.js";
|
|
15
|
+
import type { WordPressUser } from "../types/wordpress.js";
|
|
16
16
|
|
|
17
17
|
export class WordPressAuth {
|
|
18
18
|
private client: IWordPressClient;
|
|
@@ -29,21 +29,21 @@ export class WordPressAuth {
|
|
|
29
29
|
async authenticate(): Promise<boolean> {
|
|
30
30
|
try {
|
|
31
31
|
switch (this.authType) {
|
|
32
|
-
case
|
|
32
|
+
case "app-password":
|
|
33
33
|
return await this.handleAppPasswordAuth();
|
|
34
|
-
case
|
|
34
|
+
case "jwt":
|
|
35
35
|
return await this.handleJWTAuth();
|
|
36
|
-
case
|
|
36
|
+
case "basic":
|
|
37
37
|
return await this.handleBasicAuth();
|
|
38
|
-
case
|
|
38
|
+
case "api-key":
|
|
39
39
|
return await this.handleAPIKeyAuth();
|
|
40
|
-
case
|
|
40
|
+
case "cookie":
|
|
41
41
|
return await this.handleCookieAuth();
|
|
42
42
|
default:
|
|
43
43
|
throw new Error(`Unsupported authentication type: ${this.authType}`);
|
|
44
44
|
}
|
|
45
45
|
} catch (error) {
|
|
46
|
-
logger.error(
|
|
46
|
+
logger.error("Authentication failed:", error);
|
|
47
47
|
throw error;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -56,8 +56,8 @@ export class WordPressAuth {
|
|
|
56
56
|
|
|
57
57
|
if (!username || !appPassword) {
|
|
58
58
|
throw new Error(
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
"Application Password authentication requires WORDPRESS_USERNAME and WORDPRESS_APP_PASSWORD. " +
|
|
60
|
+
"Visit your WordPress admin → Users → Profile → Application Passwords to create one.",
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -65,12 +65,12 @@ export class WordPressAuth {
|
|
|
65
65
|
try {
|
|
66
66
|
const user = await this.client.getCurrentUser();
|
|
67
67
|
logger.log(
|
|
68
|
-
`✅ Application Password authentication successful for user: ${user.name} (${user.username})
|
|
68
|
+
`✅ Application Password authentication successful for user: ${user.name} (${user.username})`,
|
|
69
69
|
);
|
|
70
70
|
return true;
|
|
71
71
|
} catch (error) {
|
|
72
72
|
const message =
|
|
73
|
-
|
|
73
|
+
"Application Password authentication failed. Please check your credentials and ensure the application password is valid.";
|
|
74
74
|
logger.error(message, error);
|
|
75
75
|
throw new Error(message);
|
|
76
76
|
}
|
|
@@ -84,19 +84,19 @@ export class WordPressAuth {
|
|
|
84
84
|
|
|
85
85
|
if (!username || !password) {
|
|
86
86
|
throw new Error(
|
|
87
|
-
|
|
87
|
+
"Basic authentication requires WORDPRESS_USERNAME and WORDPRESS_PASSWORD",
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
try {
|
|
92
92
|
const user = await this.client.getCurrentUser();
|
|
93
93
|
logger.log(
|
|
94
|
-
`✅ Basic authentication successful for user: ${user.name} (${user.username})
|
|
94
|
+
`✅ Basic authentication successful for user: ${user.name} (${user.username})`,
|
|
95
95
|
);
|
|
96
96
|
return true;
|
|
97
97
|
} catch (error) {
|
|
98
98
|
const message =
|
|
99
|
-
|
|
99
|
+
"Basic authentication failed. Please check your username and password.";
|
|
100
100
|
logger.error(message, error);
|
|
101
101
|
throw new Error(message);
|
|
102
102
|
}
|
|
@@ -110,8 +110,8 @@ export class WordPressAuth {
|
|
|
110
110
|
|
|
111
111
|
if (!username || !password || !secret) {
|
|
112
112
|
throw new Error(
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
"JWT authentication requires WORDPRESS_USERNAME, WORDPRESS_PASSWORD, and WORDPRESS_JWT_SECRET. " +
|
|
114
|
+
"Install and configure the JWT Authentication plugin first.",
|
|
115
115
|
);
|
|
116
116
|
}
|
|
117
117
|
|
|
@@ -119,12 +119,12 @@ export class WordPressAuth {
|
|
|
119
119
|
// The JWT token should be obtained during client authentication
|
|
120
120
|
const user = await this.client.getCurrentUser();
|
|
121
121
|
logger.log(
|
|
122
|
-
`✅ JWT authentication successful for user: ${user.name} (${user.username})
|
|
122
|
+
`✅ JWT authentication successful for user: ${user.name} (${user.username})`,
|
|
123
123
|
);
|
|
124
124
|
return true;
|
|
125
125
|
} catch (error) {
|
|
126
126
|
const message =
|
|
127
|
-
|
|
127
|
+
"JWT authentication failed. Please check your credentials and ensure the JWT plugin is installed and configured.";
|
|
128
128
|
logger.error(message, error);
|
|
129
129
|
throw new Error(message);
|
|
130
130
|
}
|
|
@@ -137,17 +137,17 @@ export class WordPressAuth {
|
|
|
137
137
|
const { apiKey } = this.client.config.auth;
|
|
138
138
|
|
|
139
139
|
if (!apiKey) {
|
|
140
|
-
throw new Error(
|
|
140
|
+
throw new Error("API Key authentication requires WORDPRESS_API_KEY");
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
try {
|
|
144
144
|
// Test API key by making a simple request
|
|
145
145
|
await this.client.getSiteInfo();
|
|
146
|
-
logger.log(
|
|
146
|
+
logger.log("✅ API Key authentication successful");
|
|
147
147
|
return true;
|
|
148
148
|
} catch (error) {
|
|
149
149
|
const message =
|
|
150
|
-
|
|
150
|
+
"API Key authentication failed. Please check your API key.";
|
|
151
151
|
logger.error(message, error);
|
|
152
152
|
throw new Error(message);
|
|
153
153
|
}
|
|
@@ -161,7 +161,7 @@ export class WordPressAuth {
|
|
|
161
161
|
|
|
162
162
|
if (!nonce) {
|
|
163
163
|
logger.warn(
|
|
164
|
-
|
|
164
|
+
"Cookie authentication: No nonce provided, authentication may fail for write operations",
|
|
165
165
|
);
|
|
166
166
|
}
|
|
167
167
|
|
|
@@ -169,12 +169,12 @@ export class WordPressAuth {
|
|
|
169
169
|
// Test with a simple read operation
|
|
170
170
|
await this.client.getSiteInfo();
|
|
171
171
|
logger.log(
|
|
172
|
-
|
|
172
|
+
"✅ Cookie authentication configured (note: write operations may require valid nonce)",
|
|
173
173
|
);
|
|
174
174
|
return true;
|
|
175
175
|
} catch (error) {
|
|
176
176
|
const message =
|
|
177
|
-
|
|
177
|
+
"Cookie authentication failed. Please ensure you are properly logged into WordPress.";
|
|
178
178
|
logger.error(message, error);
|
|
179
179
|
throw new Error(message);
|
|
180
180
|
}
|
|
@@ -185,7 +185,7 @@ export class WordPressAuth {
|
|
|
185
185
|
*/
|
|
186
186
|
async refreshAuth(): Promise<boolean> {
|
|
187
187
|
switch (this.authType) {
|
|
188
|
-
case
|
|
188
|
+
case "jwt":
|
|
189
189
|
return await this.refreshJWTToken();
|
|
190
190
|
default:
|
|
191
191
|
logger.log(`Authentication refresh not supported for ${this.authType}`);
|
|
@@ -201,7 +201,7 @@ export class WordPressAuth {
|
|
|
201
201
|
// Re-authenticate to get a new token
|
|
202
202
|
return await this.handleJWTAuth();
|
|
203
203
|
} catch (error) {
|
|
204
|
-
logger.error(
|
|
204
|
+
logger.error("Failed to refresh JWT token:", error);
|
|
205
205
|
return false;
|
|
206
206
|
}
|
|
207
207
|
}
|
|
@@ -214,7 +214,7 @@ export class WordPressAuth {
|
|
|
214
214
|
await this.client.getCurrentUser();
|
|
215
215
|
return true;
|
|
216
216
|
} catch (error) {
|
|
217
|
-
logger.error(
|
|
217
|
+
logger.error("Authentication validation failed:", error);
|
|
218
218
|
return false;
|
|
219
219
|
}
|
|
220
220
|
}
|
|
@@ -233,13 +233,13 @@ export class WordPressAuth {
|
|
|
233
233
|
return {
|
|
234
234
|
authenticated: true,
|
|
235
235
|
method: this.authType,
|
|
236
|
-
user
|
|
236
|
+
user,
|
|
237
237
|
};
|
|
238
238
|
} catch (error) {
|
|
239
239
|
return {
|
|
240
240
|
authenticated: false,
|
|
241
241
|
method: this.authType,
|
|
242
|
-
error: (error as Error).message
|
|
242
|
+
error: (error as Error).message,
|
|
243
243
|
};
|
|
244
244
|
}
|
|
245
245
|
}
|
|
@@ -263,22 +263,22 @@ export class WordPressAuth {
|
|
|
263
263
|
const { clientId } = this.client.config.auth;
|
|
264
264
|
|
|
265
265
|
if (!clientId) {
|
|
266
|
-
throw new Error(
|
|
266
|
+
throw new Error("OAuth requires client ID");
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
const state = this.generateRandomState();
|
|
270
|
-
const redirectUri =
|
|
270
|
+
const redirectUri = "http://localhost:8080/oauth/callback";
|
|
271
271
|
|
|
272
|
-
const authUrl = new URL(
|
|
273
|
-
authUrl.searchParams.append(
|
|
274
|
-
authUrl.searchParams.append(
|
|
275
|
-
authUrl.searchParams.append(
|
|
276
|
-
authUrl.searchParams.append(
|
|
277
|
-
authUrl.searchParams.append(
|
|
272
|
+
const authUrl = new URL("/oauth/authorize", this.client.config.baseUrl);
|
|
273
|
+
authUrl.searchParams.append("client_id", clientId);
|
|
274
|
+
authUrl.searchParams.append("redirect_uri", redirectUri);
|
|
275
|
+
authUrl.searchParams.append("response_type", "code");
|
|
276
|
+
authUrl.searchParams.append("state", state);
|
|
277
|
+
authUrl.searchParams.append("scope", "read write");
|
|
278
278
|
|
|
279
279
|
return {
|
|
280
280
|
authUrl: authUrl.toString(),
|
|
281
|
-
state
|
|
281
|
+
state,
|
|
282
282
|
};
|
|
283
283
|
}
|
|
284
284
|
|
|
@@ -288,7 +288,7 @@ export class WordPressAuth {
|
|
|
288
288
|
async completeOAuthFlow(code: string, state: string): Promise<boolean> {
|
|
289
289
|
// This would implement the OAuth token exchange
|
|
290
290
|
// For now, this is a placeholder
|
|
291
|
-
throw new Error(
|
|
291
|
+
throw new Error("OAuth flow not yet implemented");
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
/**
|
|
@@ -296,8 +296,8 @@ export class WordPressAuth {
|
|
|
296
296
|
*/
|
|
297
297
|
private generateRandomState(length = 32): string {
|
|
298
298
|
const chars =
|
|
299
|
-
|
|
300
|
-
let result =
|
|
299
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
300
|
+
let result = "";
|
|
301
301
|
for (let i = 0; i < length; i++) {
|
|
302
302
|
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
303
303
|
}
|
|
@@ -312,38 +312,38 @@ export class WordPressAuth {
|
|
|
312
312
|
const auth = this.client.config.auth;
|
|
313
313
|
|
|
314
314
|
switch (this.authType) {
|
|
315
|
-
case
|
|
315
|
+
case "app-password":
|
|
316
316
|
if (auth.username && auth.appPassword) {
|
|
317
317
|
const credentials = Buffer.from(
|
|
318
|
-
`${auth.username}:${auth.appPassword}
|
|
319
|
-
).toString(
|
|
320
|
-
headers[
|
|
318
|
+
`${auth.username}:${auth.appPassword}`,
|
|
319
|
+
).toString("base64");
|
|
320
|
+
headers["Authorization"] = `Basic ${credentials}`;
|
|
321
321
|
}
|
|
322
322
|
break;
|
|
323
|
-
case
|
|
323
|
+
case "basic":
|
|
324
324
|
if (auth.username && auth.password) {
|
|
325
325
|
const credentials = Buffer.from(
|
|
326
|
-
`${auth.username}:${auth.password}
|
|
327
|
-
).toString(
|
|
328
|
-
headers[
|
|
326
|
+
`${auth.username}:${auth.password}`,
|
|
327
|
+
).toString("base64");
|
|
328
|
+
headers["Authorization"] = `Basic ${credentials}`;
|
|
329
329
|
}
|
|
330
330
|
break;
|
|
331
331
|
|
|
332
|
-
case
|
|
332
|
+
case "jwt":
|
|
333
333
|
if (auth.token) {
|
|
334
|
-
headers[
|
|
334
|
+
headers["Authorization"] = `Bearer ${auth.token}`;
|
|
335
335
|
}
|
|
336
336
|
break;
|
|
337
337
|
|
|
338
|
-
case
|
|
338
|
+
case "api-key":
|
|
339
339
|
if (auth.apiKey) {
|
|
340
|
-
headers[
|
|
340
|
+
headers["X-API-Key"] = auth.apiKey;
|
|
341
341
|
}
|
|
342
342
|
break;
|
|
343
343
|
|
|
344
|
-
case
|
|
344
|
+
case "cookie":
|
|
345
345
|
if (auth.nonce) {
|
|
346
|
-
headers[
|
|
346
|
+
headers["X-WP-Nonce"] = auth.nonce;
|
|
347
347
|
}
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
@@ -356,20 +356,20 @@ export class WordPressAuth {
|
|
|
356
356
|
*/
|
|
357
357
|
requiresSetup(): boolean {
|
|
358
358
|
switch (this.authType) {
|
|
359
|
-
case
|
|
359
|
+
case "jwt":
|
|
360
360
|
return !this.client.config.auth.secret;
|
|
361
|
-
case
|
|
361
|
+
case "api-key":
|
|
362
362
|
return !this.client.config.auth.apiKey;
|
|
363
|
-
case
|
|
363
|
+
case "app-password":
|
|
364
364
|
return (
|
|
365
365
|
!this.client.config.auth.username ||
|
|
366
366
|
!this.client.config.auth.appPassword
|
|
367
367
|
);
|
|
368
|
-
case
|
|
368
|
+
case "basic":
|
|
369
369
|
return (
|
|
370
370
|
!this.client.config.auth.username || !this.client.config.auth.password
|
|
371
371
|
);
|
|
372
|
-
case
|
|
372
|
+
case "cookie":
|
|
373
373
|
return false; // Cookie auth can work without additional setup
|
|
374
374
|
default:
|
|
375
375
|
return true;
|
|
@@ -381,7 +381,7 @@ export class WordPressAuth {
|
|
|
381
381
|
*/
|
|
382
382
|
getSetupInstructions(): string {
|
|
383
383
|
switch (this.authType) {
|
|
384
|
-
case
|
|
384
|
+
case "app-password":
|
|
385
385
|
return `
|
|
386
386
|
To set up Application Password authentication:
|
|
387
387
|
1. Log into your WordPress admin dashboard
|
|
@@ -393,7 +393,7 @@ To set up Application Password authentication:
|
|
|
393
393
|
7. Set WORDPRESS_USERNAME to your WordPress username
|
|
394
394
|
`;
|
|
395
395
|
|
|
396
|
-
case
|
|
396
|
+
case "jwt":
|
|
397
397
|
return `
|
|
398
398
|
To set up JWT authentication:
|
|
399
399
|
1. Install the "JWT Authentication for WP REST API" plugin
|
|
@@ -403,7 +403,7 @@ To set up JWT authentication:
|
|
|
403
403
|
5. Set WORDPRESS_USERNAME and WORDPRESS_PASSWORD
|
|
404
404
|
`;
|
|
405
405
|
|
|
406
|
-
case
|
|
406
|
+
case "api-key":
|
|
407
407
|
return `
|
|
408
408
|
To set up API Key authentication:
|
|
409
409
|
1. Install an API Key plugin (varies by plugin)
|
|
@@ -411,7 +411,7 @@ To set up API Key authentication:
|
|
|
411
411
|
3. Set WORDPRESS_API_KEY environment variable
|
|
412
412
|
`;
|
|
413
413
|
|
|
414
|
-
case
|
|
414
|
+
case "basic":
|
|
415
415
|
return `
|
|
416
416
|
To set up Basic authentication:
|
|
417
417
|
1. Set WORDPRESS_USERNAME to your WordPress username
|
|
@@ -419,14 +419,14 @@ To set up Basic authentication:
|
|
|
419
419
|
Note: This method is less secure than Application Passwords
|
|
420
420
|
`;
|
|
421
421
|
|
|
422
|
-
case
|
|
422
|
+
case "cookie":
|
|
423
423
|
return `
|
|
424
424
|
Cookie authentication is automatically configured when you're logged into WordPress.
|
|
425
425
|
For write operations, you may need to set WORDPRESS_COOKIE_NONCE.
|
|
426
426
|
`;
|
|
427
427
|
|
|
428
428
|
default:
|
|
429
|
-
return
|
|
429
|
+
return "No setup instructions available for this authentication method.";
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
432
|
}
|
|
@@ -436,7 +436,7 @@ For write operations, you may need to set WORDPRESS_COOKIE_NONCE.
|
|
|
436
436
|
*/
|
|
437
437
|
|
|
438
438
|
export class AppPasswordAuthProvider implements IAuthProvider {
|
|
439
|
-
readonly method: AuthMethod =
|
|
439
|
+
readonly method: AuthMethod = "app-password";
|
|
440
440
|
|
|
441
441
|
async authenticate(client: IWordPressClient): Promise<boolean> {
|
|
442
442
|
const auth = new WordPressAuth(client);
|
|
@@ -449,7 +449,7 @@ export class AppPasswordAuthProvider implements IAuthProvider {
|
|
|
449
449
|
}
|
|
450
450
|
|
|
451
451
|
export class JWTAuthProvider implements IAuthProvider {
|
|
452
|
-
readonly method: AuthMethod =
|
|
452
|
+
readonly method: AuthMethod = "jwt";
|
|
453
453
|
|
|
454
454
|
async authenticate(client: IWordPressClient): Promise<boolean> {
|
|
455
455
|
const auth = new WordPressAuth(client);
|
|
@@ -467,7 +467,7 @@ export class JWTAuthProvider implements IAuthProvider {
|
|
|
467
467
|
}
|
|
468
468
|
|
|
469
469
|
export class BasicAuthProvider implements IAuthProvider {
|
|
470
|
-
readonly method: AuthMethod =
|
|
470
|
+
readonly method: AuthMethod = "basic";
|
|
471
471
|
|
|
472
472
|
async authenticate(client: IWordPressClient): Promise<boolean> {
|
|
473
473
|
const auth = new WordPressAuth(client);
|
|
@@ -480,7 +480,7 @@ export class BasicAuthProvider implements IAuthProvider {
|
|
|
480
480
|
}
|
|
481
481
|
|
|
482
482
|
export class APIKeyAuthProvider implements IAuthProvider {
|
|
483
|
-
readonly method: AuthMethod =
|
|
483
|
+
readonly method: AuthMethod = "api-key";
|
|
484
484
|
|
|
485
485
|
async authenticate(client: IWordPressClient): Promise<boolean> {
|
|
486
486
|
const auth = new WordPressAuth(client);
|
|
@@ -493,7 +493,7 @@ export class APIKeyAuthProvider implements IAuthProvider {
|
|
|
493
493
|
}
|
|
494
494
|
|
|
495
495
|
export class CookieAuthProvider implements IAuthProvider {
|
|
496
|
-
readonly method: AuthMethod =
|
|
496
|
+
readonly method: AuthMethod = "cookie";
|
|
497
497
|
|
|
498
498
|
async authenticate(client: IWordPressClient): Promise<boolean> {
|
|
499
499
|
const auth = new WordPressAuth(client);
|
|
@@ -510,15 +510,15 @@ export class CookieAuthProvider implements IAuthProvider {
|
|
|
510
510
|
*/
|
|
511
511
|
export function createAuthProvider(method: AuthMethod): IAuthProvider {
|
|
512
512
|
switch (method) {
|
|
513
|
-
case
|
|
513
|
+
case "app-password":
|
|
514
514
|
return new AppPasswordAuthProvider();
|
|
515
|
-
case
|
|
515
|
+
case "jwt":
|
|
516
516
|
return new JWTAuthProvider();
|
|
517
|
-
case
|
|
517
|
+
case "basic":
|
|
518
518
|
return new BasicAuthProvider();
|
|
519
|
-
case
|
|
519
|
+
case "api-key":
|
|
520
520
|
return new APIKeyAuthProvider();
|
|
521
|
-
case
|
|
521
|
+
case "cookie":
|
|
522
522
|
return new CookieAuthProvider();
|
|
523
523
|
default:
|
|
524
524
|
throw new Error(`Unsupported authentication method: ${method}`);
|