You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -4,6 +4,56 @@ A simple plugin to add [JSON Web Token (JWT)](https://tools.ietf.org/html/rfc751
4
4
5
5
To know more about JSON Web Tokens, please visit [http://jwt.io](http://jwt.io).
6
6
7
+
## Description
8
+
9
+
This plugin seamlessly extends the WP REST API, enabling robust and secure authentication using JSON Web Tokens (JWT). It provides a straightforward way to authenticate users via the REST API, returning a standard JWT upon successful login.
10
+
11
+
### Key features of this free version include:
12
+
13
+
***Standard JWT Authentication:** Implements the industry-standard [RFC 7519](https://tools.ietf.org/html/rfc7519) for secure claims representation.
14
+
***Simple Endpoints:** Offers clear `/token` and `/token/validate` endpoints for generating and validating tokens.
15
+
***Configurable Secret Key:** Define your unique secret key via `wp-config.php` for secure token signing.
16
+
***Optional CORS Support:** Easily enable Cross-Origin Resource Sharing support via a `wp-config.php` constant.
For users requiring more advanced capabilities such as multiple signing algorithms (RS256, ES256), token refresh/revocation, UI-based configuration, or priority support, consider checking out **[JWT Authentication PRO](https://jwtauth.pro/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=description_link)**.
20
+
21
+
**Support and Requests:** Please use [GitHub Issues](https://github.com/Tmeister/wp-api-jwt-auth/issues). For priority support, consider upgrading to [PRO](https://jwtauth.pro/support/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=description_support_link).
22
+
23
+
## JWT Authentication PRO
24
+
25
+
Elevate your WordPress security and integration capabilities with **JWT Authentication PRO**. Building upon the solid foundation of the free version, the PRO version offers advanced features, enhanced security options, and a streamlined user experience:
26
+
27
+
***Easy Configuration UI:** Manage all settings directly from the WordPress admin area.
28
+
***Token Refresh Endpoint:** Allow users to refresh expired tokens seamlessly without requiring re-login.
29
+
***Token Revocation Endpoint:** Immediately invalidate specific tokens for enhanced security control.
30
+
***Customizable Token Payload:** Add custom claims to your JWT payload to suit your specific application needs.
31
+
***Granular CORS Control:** Define allowed origins and headers with more precision directly in the settings.
32
+
***Rate Limiting:** Protect your endpoints from abuse with configurable rate limits.
33
+
***Audit Logs:** Keep track of token generation, validation, and errors.
34
+
***Priority Support:** Get faster, dedicated support directly from the developer.
35
+
36
+
**[Upgrade to JWT Authentication PRO Today!](https://jwtauth.pro/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=pro_section_cta)**
37
+
38
+
### Free vs. PRO Comparison
39
+
40
+
Here's a quick look at the key differences:
41
+
42
+
| Feature | Free Version | JWT Auth Pro (starts at $59/yr) |
You can use a string from herehttps://api.wordpress.org/secret-key/1.1/salt/
109
+
You can generate a secure key from:https://api.wordpress.org/secret-key/1.1/salt/
59
110
60
-
### Configurate CORs Support
111
+
**Looking for easier configuration?**[JWT Authentication PRO](https://jwtauth.pro/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=config_secret_key_link) allows you to manage all settings through a simple admin UI.
61
112
62
-
The **wp-api-jwt-auth** plugin has the option to activate [CORs](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) support.
113
+
### Configure CORS Support
63
114
64
-
To enable the CORs Support edit your wp-config.php file and add a new constant called **JWT_AUTH_CORS_ENABLE**
115
+
The **wp-api-jwt-auth** plugin has the option to activate [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) support.
65
116
117
+
To enable CORS Support, edit your wp-config.php file and add a new constant called **JWT_AUTH_CORS_ENABLE**:
66
118
67
119
```php
68
120
define('JWT_AUTH_CORS_ENABLE', true);
69
121
```
70
122
71
-
72
-
Finally activate the plugin within the plugin dashboard.
123
+
Finally, activate the plugin within your wp-admin.
73
124
74
125
## Namespace and Endpoints
75
126
76
-
When the plugin is activated, a new namespace is added.
77
-
127
+
When the plugin is activated, a new namespace is added:
78
128
79
129
```
80
130
/jwt-auth/v1
81
131
```
82
132
133
+
Also, two new endpoints are added to this namespace:
83
134
84
-
Also, two new endpoints are added to this namespace.
**Need more functionality?**[JWT Authentication PRO](https://jwtauth.pro/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=endpoints_pro_note) includes additional endpoints for token refresh and revocation.
91
141
92
142
## Usage
93
143
### /wp-json/jwt-auth/v1/token
94
144
95
-
This is the entry point for the JWT Authentication.
145
+
This is the entry point for JWT Authentication.
96
146
97
-
Validates the user credentials, *username* and *password*, and returns a token to use in a future request to the API if the authentication is correct or error if the authentication fails.
147
+
It validates the user credentials, *username* and *password*, and returns a token to use in future requests to the API if the authentication is correct, or an error if authentication fails.
The **wp-api-jwt-auth** will intercept every call to the server and will look for the authorization header, if the authorization header is present, it will try to decode the token and will set the user according with the data stored in it.
221
+
The **wp-api-jwt-auth**plugin will intercept every call to the server and will look for the Authorization Header. If the Authorization header is present, it will try to decode the token and will set the user according to the data stored in it.
180
222
181
-
If the token is valid, the API call flow will continue as always.
223
+
If the token is valid, the API call flow will continue as normal.
182
224
183
225
**Sample Headers**
184
226
185
-
```
227
+
```http
186
228
POST /resource HTTP/1.1
187
229
Host: server.example.com
188
230
Authorization: Bearer mF_s9.B5f-4.1JqM
189
231
```
190
232
191
-
###Errors
233
+
## Errors
192
234
193
-
If the token is invalid an error will be returned. Here are some samples of errors:
235
+
If the token is invalid, an error will be returned. Here are some sample errors:
194
236
195
237
**Invalid Credentials**
196
238
@@ -234,9 +276,11 @@ If the token is invalid an error will be returned. Here are some samples of erro
This is a simple helper endpoint to validate a token; you only will need to make a POST request sending the Authorization header.
283
+
This is a simple helper endpoint to validate a token. You only need to make a POST request with the Authorization header.
240
284
241
285
Valid Token Response:
242
286
@@ -251,11 +295,11 @@ Valid Token Response:
251
295
252
296
## Available Hooks
253
297
254
-
The **wp-api-jwt-auth** is dev friendly and has five filters available to override the default settings.
298
+
The **wp-api-jwt-auth**plugin is developer-friendly and provides five filters to override the default settings.
255
299
256
-
####jwt_auth_cors_allow_headers
300
+
### jwt_auth_cors_allow_headers
257
301
258
-
The **jwt_auth_cors_allow_headers** allows you to modify the available headers when the CORs support is enabled.
302
+
The **jwt_auth_cors_allow_headers**filter allows you to modify the available headers when CORS support is enabled.
259
303
260
304
Default Value:
261
305
@@ -265,7 +309,7 @@ Default Value:
265
309
266
310
### jwt_auth_not_before
267
311
268
-
The **jwt_auth_not_before** allows you to change the [**nbf**](https://tools.ietf.org/html/rfc7519#section-4.1.5) value before the token is created.
312
+
The **jwt_auth_not_before**filter allows you to change the [**nbf**](https://tools.ietf.org/html/rfc7519#section-4.1.5) value before the token is created.
269
313
270
314
Default Value:
271
315
@@ -275,7 +319,7 @@ Creation time - time()
275
319
276
320
### jwt_auth_expire
277
321
278
-
The **jwt_auth_expire** allows you to change the value [**exp**](https://tools.ietf.org/html/rfc7519#section-4.1.4) before the token is created.
322
+
The **jwt_auth_expire**filter allows you to change the [**exp**](https://tools.ietf.org/html/rfc7519#section-4.1.4) value before the token is created.
279
323
280
324
Default Value:
281
325
@@ -285,7 +329,7 @@ time() + (DAY_IN_SECONDS * 7)
285
329
286
330
### jwt_auth_token_before_sign
287
331
288
-
The **jwt_auth_token_before_sign** allows you to modify all the token data before to be encoded and signed.
332
+
The **jwt_auth_token_before_sign**filter allows you to modify all token data before it is encoded and signed.
289
333
290
334
Default value:
291
335
@@ -304,8 +348,11 @@ $token = array(
304
348
);
305
349
```
306
350
351
+
**Want easier customization?**[JWT Authentication PRO](https://jwtauth.pro/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=hook_payload_pro_note) allows you to add custom claims directly through the admin UI.
352
+
307
353
### jwt_auth_token_before_dispatch
308
-
The **jwt_auth_token_before_dispatch** allows you to modify all the response array before to dispatch it to the client.
354
+
355
+
The **jwt_auth_token_before_dispatch** filter allows you to modify the response array before it is sent to the client.
309
356
310
357
Default value:
311
358
@@ -320,7 +367,8 @@ $data = array(
320
367
```
321
368
322
369
### jwt_auth_algorithm
323
-
The **jwt_auth_algorithm** allows you to modify the signing algorithm.
370
+
371
+
The **jwt_auth_algorithm** filter allows you to modify the signing algorithm.
324
372
325
373
Default value:
326
374
@@ -340,13 +388,35 @@ $token = JWT::decode(
340
388
);
341
389
```
342
390
391
+
**Need more advanced algorithms?**[JWT Authentication PRO](https://jwtauth.pro/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=algorithm_hook_link) supports multiple signing algorithms (RS256, ES256) that you can easily configure through the UI.
392
+
393
+
## Frequently Asked Questions
394
+
395
+
### Does this plugin support algorithms other than HS256?
396
+
The free version only supports HS256. For support for RS256, ES256, and other algorithms, please consider [JWT Authentication PRO](https://jwtauth.pro/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=faq_algorithms_link).
397
+
398
+
### Can I manage settings without editing wp-config.php?
399
+
The free version requires editing `wp-config.php`. [JWT Authentication PRO](https://jwtauth.pro/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=faq_config_link) provides a full settings UI within the WordPress admin.
400
+
401
+
### Is there a way to refresh or revoke tokens?
402
+
Token refresh and revocation features are available in [JWT Authentication PRO](https://jwtauth.pro/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=faq_refresh_revoke_link).
403
+
404
+
### Where can I get faster support?
405
+
Priority support is included with [JWT Authentication PRO](https://jwtauth.pro/support/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=faq_support_link). For free support, please use the [GitHub issues tracker](https://github.com/Tmeister/wp-api-jwt-auth/issues).
406
+
407
+
### How secure is JWT authentication?
408
+
JWT authentication is very secure when implemented correctly. Make sure to use a strong secret key and keep it confidential. [JWT Auth PRO](https://jwtauth.pro/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=faq_security_link) offers additional security features like rate limiting and token revocation.
409
+
343
410
## Testing
344
-
I've created a small app to test the basic functionality of the plugin; you can get the app and read all the details on the [JWT-Client Repo](https://github.com/Tmeister/jwt-client)
411
+
I've created a small app to test the basic functionality of the plugin. You can get the app and read all the details in the [JWT-Client Repo](https://github.com/Tmeister/jwt-client).
345
412
346
413
## Credits
347
414
[WP REST API V2](http://v2.wp-api.org/)
348
415
349
416
[PHP-JWT from firebase](https://github.com/firebase/php-jwt)
Want to enhance your JWT authentication with advanced features like token refresh, revocation, UI-based configuration, multiple algorithms, and more? Check out [JWT Authentication PRO](https://jwtauth.pro/?utm_source=github_readme&utm_medium=link&utm_campaign=pro_promotion&utm_content=footer_cta)!
0 commit comments