1

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 :

  1. 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');
      });
    
  2. 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.

sideshowbarker
  • 62,215
  • 21
  • 143
  • 153
Murali Rao
  • 2,267
  • 9
  • 17
  • Good read : http://techblog.constantcontact.com/software-development/using-cors-for-cross-domain-ajax-requests/ – Murali Rao Mar 15 '15 at 09:13
  • What is common VIP? Please, when you solve problem, be little detailed, because a lot of people will have the same problem like you. You will save it's time, like they can save yours in other hand. – М.Б. Oct 06 '17 at 08:32

1 Answers1

-1

i feel second approach is cleaner.I have tried & it works.

Kalava
  • 205
  • 1
  • 4
  • 15