由於目前處理的 wordpress 網站使用了,使用php
qtranslate-x
多語言插件JWT Authentication for WP REST API
插件 rest api 登陸調用wp-json/jwt-auth/v1/token
能夠登陸成功,但經過 jwt.io 網站中的 Debugger
,發現 token的 末尾多了 語言後綴 ,如圖:json
由於 get_bloginfo('url')
方法獲取到的是沒有 語言後綴或 默認語言的 wordpress 站點地址(URL)api
只能修改 jwt-authentication-for-wp-rest-api/public/class-jwt-auth-public.php
的 validate_token
方法wordpress
將網站
$token = JWT::decode($token, $secret_key, array('HS256')); /** The Token is decoded now validate the iss */ if ($token->iss != get_bloginfo('url')) { /** The iss do not match, return error */ return new WP_Error( 'jwt_auth_bad_iss', __('The iss do not match with this server', 'wp-api-jwt-auth'), array( 'status' => 403, ) ); }
修改成this
$token = JWT::decode($token, $secret_key, array('HS256')); //get_bloginfo('url') $iss_url = defined('JWT_AUTH_ISS_URL') ? JWT_AUTH_ISS_URL : get_bloginfo('url'); /** The Token is decoded now validate the iss */ if ($token->iss != $iss_url) { /** The iss do not match, return error */ return new WP_Error( 'jwt_auth_bad_iss', __('The iss do not match with this server', 'wp-api-jwt-auth'), array( 'status' => 403, ) ); }
最後在站點的 wp-config.php
中,添加一個url
// this value equal `WordPress Address (URL)` define('JWT_AUTH_ISS_URL','http://192.168.1.184/test');