首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >X-WP-Nonce == Cookie nonce无效

X-WP-Nonce == Cookie nonce无效
EN

Stack Overflow用户
提问于 2017-10-06 20:12:37
回答 1查看 2.7K关注 0票数 4

在我的WordPress REST端点上,我登录了wordpress,返回了一个nonce,如下所示:

PHP

代码语言:javascript
复制
$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将nonce返回到PHP以验证它,并且它工作了!

JS:

代码语言:javascript
复制
let axiosSettings = {
        baseURL: "http://site.localhost",
        url: "/wp-json/id3/test/verify",
        method: "POST",
        data: {
            n: this.state.nonce
        }
}

但是当我把nonce放在报头X-WP-Nonce中时,

代码语言:javascript
复制
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 nonce无效,拒绝访问我的REST API。为什么会这样呢?

EN

回答 1

Stack Overflow用户

发布于 2017-10-06 21:21:04

后来进行了大量的搜索...操作需要是"wp_rest“。

How to get current logged in user using Wordpress Rest Api?

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46605470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档