I’ve toggled this two lines in routes.php
);
die();
}
+ return $endpoint;
}
- return $endpoint;
}, 99 );
}
This will force JWT Auth for any REST request – This dont answer my question, but it could be helpful for anyone else who wants to force a token for any rest endpoint 🙂
It could be helpful to add a switch for something like that – IMHO a lot of users only use the rest API for them self and dont want to provide them to public 🙂
BTW: Is there any Github repo to add pull requests ?
-
This reply was modified 5 years, 10 months ago by
lordofdoom.
Hello @lordofdoom,
The main idea of this plugin was to allow users to use JWT without having to change any code and having a simple UI.
Currently, all the settings for the plugin are stored in the database.
But, I can add an option, in the plugin settings, and allow you to use the value defined in wp-config.php. I think that you don’t want this value to be displayed in the UI.
I will add this feature on my todo list and I will let you know once it is implemented.
Also, I want to thank you for the suggestion for handling errors. I will also add that to my todo-list and I will come back with updates.
Best regards,
Nicu.
Hi @nicu_m ,
thank you for your answer 🙂 That’s exactly what I want, I’ve already modify the code locally to do this, that was also the reason why I’ve asked for a git pull request. So I could provide a working code for this (it also hides the key in the UI already and check if the bearer is defined globally (wp-config.php), if not it use the normal UI and saves to DB)
For the errors – A handling would be pretty great because in that case we could specify what permissions are needed on custom endpoints.
For the code I’ve provided above, it seems that it breaks Gutenberg (did not see this, I use classic editor)
Here is a fixed patch (for routes.php -> around line 51):
+ //Gutenberg compatibility
+ foreach ( $_COOKIE as $name => $value ) {
+ if ( 0 === strpos( $name, 'wordpress_logged_in_' ) ) {
+ return $endpoint;
+ }
+ }
$jwt = $jwtService->getJwtFromRequestHeaderOrCookie();
if ( ! empty( $jwt ) ) {
try {
add_action( 'rest_api_init', function () {
);
die();
}
+ return $endpoint;
}
- return $endpoint;
}, 99 );
}
Best regards and thank you for your work 🙂
-
This reply was modified 5 years, 10 months ago by
lordofdoom.
Hello @lordofdoom,
I’ve just released version 2.3.0.
Here you can set the Decryption Key in wp-config.php
You just need to go to Plugin settings -> General -> Decryption Key source and set it to “Code”.
Let me know what do you think.
Best regards,
Nicu.