401 Unauthorized with Wordpress基本认证插件

o4tp2gmn  于 9个月前  发布在  WordPress
关注(0)|答案(6)|浏览(125)

我已经安装了WordPress团队制作的插件:https://github.com/WP-API/Basic-Auth
我在Wordpress 4.9.4中提出了这个请求:

GET http://somehostname.com/index.php?rest_route=%2Fwp%2Fv2%2Fposts&per_page=100&page=2&context=edit HTTP/1.1
Host: somehostname.com
Authorization: Basic [****base64encoded username+":"+pass *******]
Accept-Encoding: gzip, deflate
User-Agent: [some user agent name]

字符串
回应:

HTTP/1.1 401 Unauthorized
Date: Tue, 13 Feb 2018 14:26:12 GMT
Server: Apache
X-Powered-By: PHP/7.1.12
X-Robots-Tag: noindex
Link: <http://somehostname.com/wp-json/>; rel="https://api.w.org/"
X-Content-Type-Options: nosniff
Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages
Access-Control-Allow-Headers: Authorization, Content-Type
Vary: Accept-Encoding,User-Agent
Content-Length: 127
Content-Type: application/json; charset=UTF-8

{"code":"rest_forbidden_context","message":"Sorry, you are not allowed to edit posts in this post type.","data":{"status":401}}

j2datikz

j2datikz1#

请在htaccess文件中添加以下代码。

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

字符串
如果你登录作为一个WordPress的管理员现在比它将不允许你创建一个职位,所以第一次从WordPress的管理员注销,然后尝试提出请求.
这两个解决方案解决了我的问题。

vuktfyat

vuktfyat2#

我从你的问题中推断出这是不应该发生的。你期待的是一些不是4xx类型的响应代码。
从标题:“401 Unauthorized with Wordpress Basic Auth Plugin”,我也在做一个飞跃,但你可能认为插件不允许你在任何意义上访问该路由。
所以,考虑到这一点,我想指出的是,错误数据告诉你一些非常精确的东西:该 * 用户 * 不允许编辑该类型的帖子。这与该 * 用户 * 的凭据无效相同。

{
    "code": "rest_forbidden_context",
    "message": "Sorry, you are not allowed to edit posts in this post type.",
    "data": {
        "status": 401
    }
}

字符串
尝试确认您以[****base64encoded username+":"+pass *******]提供的凭据的用户是管理员/作者/编辑器(或其他角色),有权编辑您试图访问的类型的帖子。
编辑:请参阅WP-API的这一行,错误可能源于此

brjng4g3

brjng4g33#

我得到了这个修复刚才这样做的评论是建议:修复基本的OAuth不知道如果这个修复有任何副作用,虽然?

kzmpq1sx

kzmpq1sx4#

我按照这个非常简短的建议修复了auth问题
https://github.com/WordPress/application-passwords/wiki/Basic-Authorization-Header----Missing
我还不得不把WordPress块移到htaccess的顶部

rur96b6h

rur96b6h5#

我已通过以下步骤修复了此问题:
1.验证是否安装了password protected插件,然后
1.后藤密码保护插件的设置
1.选中“允许REST API访问”*
1.保存更改
100d1x

的字符串

ffscu2ro

ffscu2ro6#

您可以在.htaccess中添加此代码段来解决此错误

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=REMOTE_USER:%{HTTPS:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

字符串

相关问题