Ask for the authentication Example

Hi everyone

I cannot authenticate via angular $http request to my localhost while i use Web API from dihs.

Can somebody please help me to show example of authentication to DHIS via angular $http request?

Regards

Win Htaik Aung(WHA)
Contact on Skype winhtaikaung28

Hi Win,

the Web API currently only supports basic authentication. Docs here.

You can find a tutorial for angular + basic here.

regards,

Lars

···

On Wed, Jul 23, 2014 at 5:24 AM, winhtaik aung winhtaikaung28@hotmail.com wrote:

Hi everyone

I cannot authenticate via angular $http request to my localhost while i use Web API from dihs.

Can somebody please help me to show example of authentication to DHIS via angular $http request?

Regards

Win Htaik Aung(WHA)
Contact on Skype winhtaikaung28


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

Hi,

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.

You can find a tutorial for angular + basic here.

regards,

Lars


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

On Wed, Jul 23, 2014 at 5:24 AM, winhtaik aung winhtaikaung28@hotmail.com wrote:

Hi everyone

I cannot authenticate via angular $http request to my localhost while i use Web API from dihs.

Can somebody please help me to show example of authentication to DHIS via angular $http request?

Regards

Win Htaik Aung(WHA)
Contact on Skype winhtaikaung28


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp