Search code examples
wordpressauthenticationjwtwp-api

Authentication WP API with JWT switching method


I have a basic WP site set up with the WP API 2 (beta13.1) and JWT plugins. If I make a call to the /token endpoint while i'm already logged into WP, I get a successful response.

However, if I'm not logged in, I get a "No route was found matching the URL and request method" message.

Upon further digging I can see in my servers access logs that the POST request is getting recieved as a GET request, so must be getting changed somewhere along the line, hence the error message I am seeing!

127.0.0.1 - - [06/Jun/2016:16:19:04 +0000] "GET /test/wp-json/jwt-auth/v1/token HTTP/1.1" 404 450 "http://localhost/test/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:46.0) Gecko/20100101 Firefox/46.0"

If I add a valid "wordpress_logged_in" cookie to the request, it works fine.

I can't figure out whats happening, the request to login a user shouldn't require the user to already be logged in!


Solution

  • Just incase anyone else stumbles upon this question, the issue for me was Varnish. If you have return (lookup) in the Varnish config, then in an attempt to cache the the request, it get converted to GET

    See: https://serverfault.com/questions/563560/varnish-transforming-post-to-get