wordpress插件 jwt-auth与微慕小程序冲突
wordpress插件 jwt-auth与微慕小程序冲突,导致小程序获取文章显示:
{
"success": false,
"statusCode": 403,
"code": "jwt_auth_no_auth_header",
"message": "Authorization header not found.",
"data": []
}
解决办法
在jwt-auth修改如图所示代码,
在 default_whitelist 内部添加
“`
“`
原理说明
[usefulteam/jwt-auth: WordPress JSON Web Token Authentication](https://github.com/usefulteam/jwt-auth)
在jwt-auth添加了白名单,避免报错;
官网原文
Default Whitelisted Endpoints
We whitelist some endpoints by default. This is to prevent error regarding WordPress & WooCommerce. These are the default whitelisted endpoints (without trailing * char):
// Whitelist some endpoints by default (without trailing * char).
$default_whitelist = array(
// WooCommerce namespace.
$rest_api_slug . '/wc/',
$rest_api_slug . '/wc-auth/',
$rest_api_slug . '/wc-analytics/',
// WordPress namespace.
$rest_api_slug . '/wp/v2/',
);
You might want to remove or modify the existing default whitelist. You can use jwt_auth_default_whitelist
filter to do it. Please simply add this filter directly (without hook). Or, you can add it to plugins_loaded
. Adding this filter inside init
(or later) will not work.
If you’re adding the filter inside theme and the it doesn’t work, please create a small 1 file plugin and add your filter there. It should fix the issue.
add_filter( 'jwt_auth_default_whitelist', function ( $default_whitelist ) {
// Modify the $default_whitelist here.
return $default_whitelist;
} );