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
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!