How to implement a cookie-based authentification

Hi everybody!

I am making a ionic app using angularjs and and I’d like to login the user to a third-party API. The API login system is based o cookies (basically the app post on /login the credentials, and the xml response contains an entry cookie which contains the cookie that should be sent when needed to be logged in). I got the cookie, now, how do I send it?

Thanks in advance guys :smile:

I come across the same problem!I don’t know what to do?

The cookie should be sent automatically if you are using $http

Hi, you don’t use the standard cookie angularjs, but use angular-cookie (https://github.com/ivpusic/angular-cookie) because the native implementation have a problem with domain/directory.

However if you want to use $http:

login : function(user) {
            return $http({method : 'post',
                url : 'http://MYDOMAIN/rest/user/login',
                headers : { 'X-CSRF-Token' : ipCookie('csrftoken')},
                data : { 'username': user.username, 'password' : user.password}
            })
        },

Or if you want to use restangular:

login: function (params) {
   return this.restfulBase().post('user/login',params,{},{ 'X-CSRF-Token' : sharedService.csrf});
},

(Code takes from 2 different angularjs SAPs)

If I can: you use restangular and not the native $http.

M.

PS: sorry for bad english.

Thanks, but it turns out that I can’t even make http requests Can’t make http request

will this (angular cookie) solve my x-csrf-token issue i stated here --> Need Help With X-CSRF-Token issue ! :(

Can you help me with this ? Help is appreciated !