jwt-auth icon indicating copy to clipboard operation
jwt-auth copied to clipboard

Fix bugs for a multisite environment.

Open baxtian opened this issue 5 years ago • 4 comments

Use get_home_url to creat the rest URI. Use apache_request_header in case $_SERVER didn't retrieve it.

baxtian avatar Jun 06 '19 02:06 baxtian

The get_home_url is the change I did to allow your plugin to work on my environment. Without it, the script can't figure the exact URL for the site where it have to ask for the information. I'm using a multisite with directories, not subdomains if this can help to clarify.

I'm using apache locally, and the information in the $_SERVER array didn't get the authorization information. It requires to use apache_request_headers to get this data.

These are the changes I made. Hope it clarifies any doubt you have.

Chears.

El vie., 5 jul. 2019 a las 17:12, Derek Herman ([email protected]) escribió:

@valendesigns commented on this pull request.

In wp-includes/rest-api/auth/class-wp-rest-token.php https://github.com/WP-API/jwt-auth/pull/15#discussion_r300804399:

@@ -762,6 +762,14 @@ public function get_auth_header() { $header = sanitize_text_field( $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ); }

  • //Maybe apache?
    

This doesn't have anything to do with Multisite though. Can you describe the problem you're having with Multisite so I can understand why you are changing the rest endpoint?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/WP-API/jwt-auth/pull/15?email_source=notifications&email_token=ABQPMPNYNBJ5ZCD3QKSIP5LP57BMZA5CNFSM4HUUM6X2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB5UU4VY#discussion_r300804399, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQPMPPVVVGYKP5AVJEIIMTP57BMZANCNFSM4HUUM6XQ .

-- Juan Sebastián Echeverry www.sebaxtian.com

baxtian avatar Jul 05 '19 23:07 baxtian

This PR will fix the issue #19 , it's directly related.

arctouch-carlosbarreto avatar Nov 05 '19 15:11 arctouch-carlosbarreto

@valendesigns hello I tried to solve this more programmatically using this approach:

public static function get_rest_uri() {
	$blog_id = get_current_blog_id();
	$prefix  = 'index.php?rest_route=';

	if ( is_multisite() && get_blog_option( $blog_id, 'permalink_structure' ) || get_option( 'permalink_structure' ) ) {
				
	    $multisite_domain = strstr($_SERVER['REQUEST_URI'], 'wp-admin', true);
	    $prefix = $multisite_domain['0'] == '/' ? substr($multisite_domain, 1) . rest_get_url_prefix() : $multisite_domain  . rest_get_url_prefix();
	}
	return sprintf( '/%s/%s/%s', $prefix, self::_NAMESPACE_, self::_REST_BASE_ );
}

Although it works, it would certainly break the tests because of the hardcoded uris in test_get_rest_uri

public function test_get_rest_uri() {
	$this->assertEquals( '/index.php?rest_route=/wp/v2/key-pair', WP_REST_Key_Pair::get_rest_uri() );
	$this->set_permalink_structure( '/%postname%/' );
	$this->assertEquals( '/wp-json/wp/v2/key-pair', WP_REST_Key_Pair::get_rest_uri() );
	$this->set_permalink_structure( '' );
}

I was wondering if would be a good idea to build dynamically the uris in the test function.

Edely avatar Nov 19 '19 23:11 Edely

sorry guys for using this ticket for something totally unrelated ...

@baxtian the comment box at http://www.sebaxtian.com/acerca-de/schreikasten does not work any longer (Ha habido un error crítico en tu web. Aprende más sobre la depuración en WordPress.). I searched around on the internet but i couldn't find a way to contact you as i didn't see an e-mail address or a public repository you made where i can comment on.

Below the comment that i was going to post there


Hi sebaxtian, thank you for the plugin. Would you consider uploading the source code to github / gitlab for more collaboration? People can send in fixes for the code as pull requests and make bug reports in separate tickets. We only have the release SVN, which is not for development, at https://plugins.trac.wordpress.org/browser/schreikasten/

I would also be very interested in all the ideas that you have for improvements to a shoutbox (possibly as new implementation instead of new version). You write:

There are too many reasons why, but to give just 3 of them: to use a template language, to use jQuery, to use WordPress own custom post type generator.

If you can spare the time a full list of possible improvements would be very appreciated (perhaps in a github ticket / wiki).


You can contact me at [email protected] so we don't have to use this ticket for communication.

flip111 avatar May 03 '20 09:05 flip111