Reputation: 11458
I am working in a Windows Auth environment, and have created a Cookie in Angular to hold the currently logged in user's fullname:
returnsApp.run(["$cookies", "UserService", function($cookies, userService) {
userService.getUser().then(function(user) {
$cookies["ss-id"] = user.data.result.fullName;
console.log($cookies["ss-id"]); // Outputs: BiffBaffBoff (correct!)
});
}]);
Then when I try and access this cookie on the Server, inside my Service (It's hosted on a different server if that helps?), the cookie is null:
Cookie cookie;
Request.Cookies.TryGetValue(SessionFeature.SessionId, out cookie);
if (cookie == null)
throw new ArgumentException("User not found!");
I think I am missing a step, perhaps passing this cookie value along in the header when I make the service call? FYI, here is how I am making the service call:
var createReturn = function (returnObj) {
return $http.post(url, returnObj);
};
Upvotes: 1
Views: 229
Reputation: 16066
Something similar happened to me, but the other way,setting up a cookie in the server and when I tried to read in the client it was always null, I think you need to configure SS to be able to create non HttpOnly cookies.
try to put this setting in your host configuration:
Config.AllowNonHttpOnlyCookies = true;
As far I know you wanted to access an OOB auth cookie, I'm not quite sure if that cookie is only available in the server side, if that's the case try to create another cookie with the information you want to share between the client in the server and set the HttpOnly = false, that worked for me and it's something like that:
var resp =service.RequestContext.Get<IHttpResponse>();
resp.Cookies.AddCookie(new Cookie { Name = "r", Path = "/", Value = "from server", HttpOnly = false, Discard = false, Expires = DateTime.Now.AddHours(12) });
I hope that helps
Upvotes: 2