Proper status code on preflight OPTIONS request
-
I’m attempting to query my WordPress site via the REST API by fetching from javascript. To handle authentication, I have installed the JWT Auth plugin. I am able to successfully generate and return an access token. However, when I attempt to use that access token for future requests, the preflight OPTIONS request encounters a
403 Forbidden
status code. A200 Okay
is needed to proceed with the request. I expect this is something in the configuration of my WordPress site or, more likely, in the server on which it is hosted. I expect WordPress or the JWT Auth plugin should be handling this response properly, but that may not be. Full response and request headers are below.I’ve been scouring the internet for fixes to this and haven’t been able to locate any good direction on how to proceed. Any assistance or thoughts will be appreciated. Thanks!
Note: I realize this endpoint doesn’t need authentication, but others I plan to hit will.
—–
General:
Request URL: https://[redacted].com/wp-json/wp/v2/posts
Request Method: OPTIONS
Status Code: 403 Forbidden
Remote Address: #.#.#.#:443
Referrer Policy: strict-origin-when-cross-originResponse Headers:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Authorization, Content-Type
Access-Control-Allow-Methods: OPTIONS, GET, POST, PUT, PATCH, DELETE
Access-Control-Allow-Origin: https://type.test
Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages
Connection: Keep-Alive
Content-Length: 110
Content-Type: application/json; charset=UTF-8
Date: Fri, 12 Jul 2019 13:59:26 GMT
Keep-Alive: timeout=5, max=99
Link: <https://[redacted].com/wp-json/>; rel=”https://api.w.org/”
Server: Apache/2.4.29 (Ubuntu)
Vary: Origin
X-Content-Type-Options: nosniff
X-Robots-Tag: noindexRequest Headers
?? Provisional headers are shown
Access-Control-Request-Headers: authorization
Access-Control-Request-Method: GET
DNT: 1
Origin: https://type.test
Referer: https://type.test/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36—–
Here’s the error I receive in my console:
OPTIONS https://[redacted]/wp-json/wp/v2/posts 403 (Forbidden)
Access to fetch at ‘https://[redacted].com/wp-json/wp/v2/posts’ from origin ‘https://type.test’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.
- The topic ‘Proper status code on preflight OPTIONS request’ is closed to new replies.