我想在这个插件中使用WP REST API auth:https://github.com/Tmeister/wp-api-jwt-auth
我在POST上使用此req获取令牌:http:// localhost/wp_rest/wp-json/jwt-auth/v1/token
但我无法发布发布mehod的请求:localhost/wp_rest/wp-json/wp/v2/posts
我收到错误403:
{ "code": "rest_forbidden" "message": "You don't have permission to do this." "data": { "status": 403 } }
在我的标题中我有这个:
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL3dwX3Jlc3QiLCJpYXQiOjE0NTAzNDEwMTgsIm5iZiI6MTQ1MDM0MTAxOCwiZXhwIjoxNDUwOTQ1ODE4LCJkYXRhIjp7InVzZXIiOnsiaWQiOiIxIn19fQ.rGNPsU4EocClWLYWaSDs1hDJMODszg-eKfqnKSEsiw0
我正在尝试使用localhost/wp_rest/wp-json/jwt-auth/v1/token/validate但我收到此错误:
{ "code": "jwt_auth_no_auth_header", "message": "Authorization header not found.", "data": { "status": 403 } }
任何的想法?
您的请求中似乎没有包含授权标头.您需要添加'Authorization': 'Bearer PLACE_TOKEN_HERE'
请求标头.
作为样本:
var req = { method: 'POST', url: window.location.href + 'wp-json/wp/v2/posts', headers: { 'Authorization': 'Bearer ' + TOKEN_GOES_HERE } data: DATA TO PASS GOES HERE } $http(req);