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