GithubHelp home page GithubHelp logo

Comments (6)

nicumicle avatar nicumicle commented on June 19, 2024 1

Hello @shotor @melomontoya @kristjanmar,

The tag 3.4.0 has this functionality. You can not secure all rest endpoints or only specific endpoints with a JWT.
Also, when you secure all endpoints, you can set a specific list that can be whitelisted.

Please let me know what do you think.

Best regards,
Nicu.

from simple-jwt-login.

melomontoya avatar melomontoya commented on June 19, 2024

Or is there a way to validate the token tru PHP? I would like to validate the token on some endpoints.

from simple-jwt-login.

nicumicle avatar nicumicle commented on June 19, 2024

Have you tried the "Force login" (https://wordpress.org/plugins/wp-force-login/) plugin?

from simple-jwt-login.

melomontoya avatar melomontoya commented on June 19, 2024

Hi, "Force login" plugin doesn't fit 'cause it checks for "if( ! is_user_logged_in())" which doesn't work with JWT or nothing compatible with our APP. Is there a proper/safe way to make the "whitelist" work. We have tried the "1 file plugin" and "function.php" but it doesn't work.
Thanks

from simple-jwt-login.

melomontoya avatar melomontoya commented on June 19, 2024

Ok, after some digging we figured it out. Seems like the problem was the "array_merge" between both arrays. We changed it fot a foreach loop that "pushes" each endpoint and now it works. Oh, btw, it is also a one file plugin 'cause it wouldn't work on the functions.php

This is the final code

`/////////////////////////////////////////
//////// JWT WHITELIST para endpoints sin verificacion
/////////////////////////////////////////

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

/----------------------------------------------------------------------------/
/**

  • JWT whitelist
    */

add_filter(
'jwt_auth_whitelist',
function ( $endpoints ) {
$whitelists = array(
'/wp-json/MYENDPOINT/v1/home',
'/wp-json/MYENDPOINT/v1/stripewebhook'
);

	foreach ( $whitelists as $whitelist ) {
		if ( ! in_array( $whitelist, $endpoints, true ) ) {
			array_push( $endpoints, $whitelist );
		}
	}

	return $endpoints;
}

);

?>
`

from simple-jwt-login.

kristjanmar avatar kristjanmar commented on June 19, 2024

I'm interested in this as well. What did you do to restrict the endpoints before adding the whitelist code?

from simple-jwt-login.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.