dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31761
Re: Ask for the authentication Example
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@xxxxxxxxx>
wrote:
> Hi Win,
>
> the Web API currently only supports basic authentication. Docs here
> <https://www.dhis2.org/doc/snapshot/en/user/html/ch32s02.html>.
>
> You can find a tutorial for angular + basic here
> <http://wemadeyoulook.at/en/blog/implementing-basic-http-authentication-http-requests-angular/>
> .
>
> regards,
>
> Lars
>
>
>
>
> On Wed, Jul 23, 2014 at 5:24 AM, winhtaik aung <winhtaikaung28@xxxxxxxxxxx
> > 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@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~dhis2-devs
>> More help : https://help.launchpad.net/ListHelp
>>
>>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dhis2-devs
> Post to : dhis2-devs@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dhis2-devs
> More help : https://help.launchpad.net/ListHelp
>
>
References