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 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教