Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
16
rated 0 times [  20] [ 4]  / answers: 1 / hits: 16852  / 9 Years ago, wed, october 7, 2015, 12:00:00

I'm using a Web RestFUL API from my client in AngularJS.



app.controller('LoginController', [
'$http',
'$cookies',

function($http, $cookies) {
this.credentials = {};

this.http = $http;

this.login = function() {
console.log(this.credentials);

var authdata = btoa(
this.credentials.username +
':' +
this.credentials.password
);

$http.defaults.headers.common['Authorization'] = 'Basic ' + authdata;

console.log($http);

var res = $http.post(http://API_NAME/library);

res.success(function(data, status, header){
alert('Successfull func');

console.log($cookies.get('JSESSIONID'));
});

res.error(function(data, status, headers, config) {
console.log('Error Log');
});
};
},
]);


Then, i have this Http headers Response



Set-Cookie:JSESSIONID=azekazEXAMPLErezrzez; Path=/; HttpOnly


I'm using ngCookies to get the JSESSIONID value and then create it manually in my browser, but i can't access it.



I already saw all the posts about this in StackOverflow, but they are deprecated or completely unclear.



Thanks for your interest and help.


More From » angularjs

 Answers
6

You can't get HttpOnly cookies with JavaScript. That is the whole purpose of the HttpOnly flag.



That said, you shouldn't need to. The cookie should be sent automatically with any request to the same server. If you are dealing with cross-origin XHR requests, set your_XHR_instance.withCredentials to true to include cookies.


[#64810] Monday, October 5, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dezmondhumbertob

Total Points: 79
Total Questions: 112
Total Answers: 107

Location: Morocco
Member since Fri, May 22, 2020
4 Years ago
;