Wordpress api wp-api v2 + JWT 401错误

时间:2017-08-08 18:58:24

标签: wordpress .htaccess jwt http-authentication wp-api

我在尝试连接 WP-API + JWT 时遇到了问题。

我的请求获得401回复

"code":"rest_not_logged_in","message":"No estas conectado.","data":{"status":401}

请求标题:

Request URL:https://mysite/mywpsite/wp-json/wp/v2/users/me
Request Method:GET
Status Code:401 
Remote Address:77.104.154.224:443
Referrer Policy:no-referrer-when-downgrade

Response 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:http://localhost:8100
access-control-expose-headers:X-WP-Total, X-WP-TotalPages
allow:GET
cache-control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
content-type:application/json; charset=UTF-8
date:Tue, 08 Aug 2017 18:26:36 GMT
expires:Thu, 19 Nov 1981 08:52:00 GMT
host-header:192fc2e7e50945beb8231a492d6a8024
link:<https://mysite/mywpsite/wp-json/>; rel="https://api.w.org/"
pragma:no-cache
server:nginx
set-cookie:PHPSESSID=m47mbn67jn9bs6hd4honundml2; path=/
status:401
vary:Origin
x-content-type-options:nosniff
x-robots-tag:noindex

Request Headers
:authority:mysite
:method:GET
:path:/mywpsite/wp-json/wp/v2/users/me
:scheme:https
accept:application/json, text/plain, */*
accept-encoding:gzip, deflate, br
accept-language:en-US,en;q=0.8,es-419;q=0.6,es;q=0.4
authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvZXN0ZWJhbnJvbWVyby5tZVwvYWRzYXBwIiwiaWF0IjoxNTAyMjE0MTc3LCJuYmYiOjE1MDIyMTQxNzcsImV4cCI6MTUwMjgxODk3NywiZGF0YSI6eyJ1c2VyIjp7ImlkIjoiMTAifX19.EUs5b26cHx1d8UObxpuXYGyb2UYGfzrdsAv6zPpqiBs
cache-control:no-cache
content-type:text/plain
origin:http://localhost:8100
pragma:no-cache
referer:http://localhost:8100/?ionicplatform=ios&ionicstatusbarpadding=true&http://localhost:8100/ionic-lab
user-agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36 

我的主机提供商是Siteground,我已经更改了.htaccess

RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

当我改为:

RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%0]

我收到403错误:

我不知道我做错了什么,我非常感谢你的帮助。

1 个答案:

答案 0 :(得分:0)

安装插件“JSON基本身份验证”,https://github.com/WP-API/Basic-Auth,以及活动和测试。