0
在我的WordPress REST終點,我做了WordPress的登錄返回像這樣一個隨機數:X-WP-杜撰==餅乾現時無效
PHP
$authenticated = wp_authenticate($userID , $password);
$isAuthenticated = ($authenticated instanceof \WP_User) ? TRUE : FALSE;
if ($isAuthenticated)
{
$responseData[ "nonce" ] = wp_create_nonce("rest");
return rest_ensure_response($responseData);
}
然後我返回的隨機數通過axios回到PHP來驗證它,它的工作原理!
JS:
let axiosSettings = {
baseURL: "http://site.localhost",
url: "/wp-json/id3/test/verify",
method: "POST",
data: {
n: this.state.nonce
}
}
但是,當我把現時在頭X-WP-隨機數,
let axiosSettings = {
baseURL: "http://site.localhost",
url: "/wp-json/id3/test/pc",
method: "POST",
data: {
n: this.state.nonce
},
withCredentials: true,
headers: {
"X-WP-Nonce": this.state.nonce
}
};
它告訴我
Cookie的隨機數是無效的,並拒絕訪問我的REST API。爲什麼?