Hi guys,
I am new to both Keystone JS and Node.js and I am having trouble understanding how I can authenticate with basic auth on my route endpoints.
Currently all my calls get redirected to signin unless I login to the backend and create a session.
My layout is as follows:
Basic project created with generator-keystone in yeoman.
I did not add the blog feature, so it is pretty barebone.
I have added custom models and api routes (they work, but I must be logged in to use them).
In keystone/public I have added my Angular JS 1.x frontend which is supposed to do the api calls.
The following is the request header in my Angular app:
var requestObj = {
url: 'http://localhost:3000/keystone/api',
usr: 'us...@email.com',
pass: 'password',
withCredentials: true,
method: 'POST'
};
requestObj.auth = window.btoa(requestObj.usr + ':' + requestObj.pass);
requestObj.headers = {"Authorization": "Basic " + requestObj.auth};
var data = _handleRequest(requestObj);
_handleRequest looks like the following:
var _handleRequest = function(requestObj) {
var data = {};
if(requestObj.method === undefined) {
requestObj.method = 'GET';
}
return $http(requestObj, {headers: $keystoneApi.headers})
.then(
function success(response) {
return response.data;
},
function error(response) {
// todo; handle error
$log.info(response);
}
);
};
Could anyone please guide me in the right direction?
I feel like there is probably something essential and possibly simple that I am missing.
With the exception from adding routes and models I have not done anything else to alter my keystone installation.