I'm trying to build a phonegap (ionic, so it's Angular based) application that pulls data from a Wordpress Installation with the WP-API json plugin.
Retrieving the posts is super easy and it works. Retrieving the meta for a post requires authentication and it turns out to be pretty darn hard to do. I've chosen to try basic authentication.
So my factory looks like this:
.factory('SediMeta',['$resource', '$base64',
function($resource, $base64){
return $resource('http://fonda56.com/content/wp-json/posts/:id/meta/', {}, {
'get' : {
method: 'GET',
//params: {},
isArray: true,
/* Note the headers property */
headers: {
Authorization : 'Basic YWRtaW46cHJpbWF0ZTIwNQ=='
},
cache: false
}
});
}
]);
The controller looks like this:
$scope.sedi.$promise.then(function(){
retrieve the meta
angular.forEach($scope.sedi,function(value, key) {
//console.log(value.ID);
$http.defaults.useXDomain = true;
SediMeta.get({id: value.ID}, function(l,getResponseHeaders){
$scope.hide();
console.log(l);
//console.log(getResponseHeaders);
});
});
});
The problems are:
the get request turns into an option and it fails;
I've got some problems with the header('Access-Control-Allow-Origin: *');
, it works for a non authorized call but it fails for the authorized ones and i get a: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true.