Basic authentication with angular is a bit tricky. There is no generic solution, it all depends how your app is modelled. What is the dhis url? from where are you running the app?
For example - even if you have both the app and dhis on local host if the request comes from another port angular and your browser think of CROS and initiate a preflight, where your authentication header is never sent to the server… hence the server sending you a redirect to login page which angular ignores during preflight.
I think there could be something we could do from the dhis side so that it returns proper CORS response - may be Morten can say more on this.
But tell us more how your app and server are configured. As a start up take a look into the following…
var credentials = $.param({j_username: 'admin', j_password: 'district'});
var config = {headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}};
$http.post('DHIS_LOGIN_URL', credentials, config).success(function (data) {
//see the length of data - if data has some value, it means dhis2 redirect page, then login has failed
//otherwise login success proceed with your api calls…
});
Abyot.
···
On Wed, Jul 23, 2014 at 8:30 AM, Lars Helge Øverland larshelge@gmail.com wrote:
Hi Win,
the Web API currently only supports basic authentication. Docs here.