derek5. 2016-05-23 07:16 采纳率: 100%
浏览 355

Wordpress Rest API登录

I am using the Wordpress Rest API on my WinJS Universalapplication and would like to somehow login my users before I let them browse products which I also get from the API.

I have tried something like this

var settings = {
    "async": true,
    "crossDomain": true,
    "url": "http://example.com/wp-json/users/me",
    "method": "GET",
    "headers": {
        "authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ==",
        "cache-control": "no-cache"
    }
}

$.ajax(settings).done(function(response) {
    console.log(response);
});

But I get

DENIED - The requested resource requires user authentication. (XHR): GET - http://example.com/wp-json/users/me

I have also tried it using Postman and got this back

[{"code":"json_not_logged_in","message":"You are not currently logged in."}]

I am not really sure what I am doing wrong since I am trying to log in with a username/password combination which is in the Users list in Wordpress.

UPDATE:

After installing a basic authentication plugin I am now able to get the it working but now when I enter a wrong username or password Windows 10 jumps in and opens its own login form instead of letting me handle it.

I'll have to figure out now how to supress this behaviour

  • 写回答

1条回答 默认 最新

  • weixin_33743880 2017-07-25 05:15
    关注

    Glad you figured it out. I'd recommend you to use Application Passwords plugin instead of the Basic Authentication one since the latter is only for testing/dev purposes and not so secure for production!

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料