Setting cookies for the subdomain

I am making a web application in a relaxed way. For my client side, I use angularJs, the same thing is hosted on - say - https://domain.com

My backend is built on spring boot, and I call all resources from a subdomain - let's say - https://xyz.domain.com

Now that the user is logged in, the backend sends a cookie to the http client. I see a cookie in the response header, but it is not set in the browser cookies.

After a little research, I tried to send a cookie with the domain = .domain.com, but that did not work either.

Is there a way to set a cookie from xyz.domain.com for my client side at domain.com

(Note - I do not use www.domain.com)

Any help or hint would be great.

Thank you for solving my question.

+1
source share
2 answers

The problem you describe is related to cross-domain cookie policies. I do not know your specific use case, but viewing the header CORSand P3Pshould give you a good start. As an option, you can try setting your cookie manually using Javascript.

+2
source

Doing CORS work is not enough, you also need to include withCredentials in angular.

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials

Example:

angular.module('example', []).config(function ($httpProvider) {
    $httpProvider.defaults.withCredentials = true;
});
+1
source

Source: https://habr.com/ru/post/1606708/


All Articles