WordPress Rest API login

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

Read More
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

Related posts

Leave a Reply

1 comment