Objective : To share cookies across domains
Our UI is running in a server 'A' at port P1 and our services is up and running in the same server 'A' at port P2.
UI (Server 'A', Port P1) ----> Services (Server 'A', Port P2)
While making rest calls from UI to Services cookies are not sent as a part of request.
I understand that cookies are not getting shared between domains. Tried the approach suggested in Why is jquery's .ajax() method not sending my session cookie?, but to no luck.
$.ajax({
url: a_cross_domain_url,
xhrFields: {
withCredentials: true
}
});
Planning to try the below approaches, any inputs or thoughts on achieving our objective would be appreciated. Thanks.
Approaches :
To set the required cookie in Cookie header attribute as suggested in https://www.drupal.org/node/1133084
$.ajax({ url: a_cross_domain_url, xhrFields: { withCredentials: true }, // headers: {'Cookie' : 'cookieName=cookieValue'}, beforeSend: function(xhr) { xhr.setRequestHeader("Cookie", 'cookieName=cookieValue'); });
To host and access UI and Services using a common VIP (lets say : https://example.com), in this way browser won't feel the request is made across domains.
UI (https://example.com) ----> Services (https://example.com/service1)
Update :
We went ahead with 2nd approach, as both the applications were getting accessed by a common VIP the cookies were sent across by the browser.