Get HTTP cookie from browser

I am an AngularJS user, I want to prevent the default cookie from being saved from the server because it is set to session. Or, just get this cookie, get the authentication value, and store it in your own cookie, which I will use to authenticate the request. But now I cannot get this cookie using AngularJS or JavaScript. I can only see "__ngdebug" or "5984_recent". "AuthSession" cookie checked by HTTP as true,

I've tried the clock headers with $ http, but there is no name "Set-Cookie", the server example should return:

HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 43
Content-Type: application/json
Date: Mon, 03 Dec 2012 01:23:14 GMT
Server: CouchDB (Erlang/OTP)
Set-Cookie: AuthSession=cm9vdDo1MEJCRkYwMjq0LO0ylOIwShrgt8y-UkhI-c6BGw; Version=1; Path=/; HttpOnly

      

My controller looks like this:

ctr.controller("loginController", ["$scope", "$cookieStore", "$http",
  function($scope, $cookieStore, $http) {

    $scope.userCedential = {};

    $scope.login = function() {

        var headers = {};
        headers["Content-Type"] = "application/json";

        var res = $http.post("/_session", $scope.userCedential, headers);

        res.success(function(data, status, headers, config) {
                var s = headers("Set-Cookie");

            });

        res.error(function(data, status, headers, config) {

            });
    };

  }]);

      

+3


source to share


1 answer


You can not.

By definition, HttpOnly cookie cannot be accessed from NON-Http interfaces. those. JavaScript

http://en.wikipedia.org/wiki/HTTP_cookie#HttpOnly_cookie



Also see this SO answer for more information on AJAX and HttpOnly interaction:

How do HttpOnly cookies work with AJAX requests?

+3


source







All Articles