【发布时间】:2019-05-24 03:29:22
【问题描述】:
我已经使用 JWT api 命名空间创建了一个端点,但似乎无法让身份验证部分正常工作,我已经使用 wp-json/jwt-auth/v1/token 来获得对令牌的访问权限,但是我该怎么做验证自定义端点?
下面是一些代码,我已经尝试在邮递员中进行测试,但是从 403 到找不到与 URL 和请求方法匹配的路由
函数 wp_register_crm_routes() {
// register_rest_route() handles more arguments but we are going to stick to the basics for now.
register_rest_route( '/wp-json/jwt-auth/v1', 'addproduct', array(
// By using this constant we ensure that when the WP_REST_Server changes our readable endpoints will work as intended.
'methods' =>'POST',
// Here we register our callback. The callback is fired when this endpoint is matched by the WP_REST_Server class.
'callback' => 'addProductFromCRM',
'permission_callback' => function ($request) {
if (current_user_can('edit_others_posts'))
return true;
}
) );
【问题讨论】: