SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Set cookie from external javascript on different domain

    I am trying to implement a very basic single sign-on between two of my domains.

    Lets call my domains DomainA and DomainB. Currently, users need to login to DomainA and DomainB separately. What I want to enable is that when a user logs in to DomainA, DomainB is "somehow" contacted and generates a cookie with proper settings so when the user visits DomainB, he doesn't have to login.

    I thought I might be able to do this with javascript. I have all the bits and pieces working except for the following:

    I have an external javascript located on DomainB which accepts some params sent from DomainA. This js sets a cookie for DomainB. If I call this external js from a page on DomainB, the cookie is set correctly. However, if I call it from DomainA no cookies are set.

    I understand that a cookie can be set only for the domain which is setting it, but isn't the fact that the javascript is located on DomainB enough to allow the cookie to be set? Is there any way that this can be done (Page on DomainA invokes js on DomainB which sets a cookie for DomainB)?

    Am I missing something here? Can this be done in another way? Any pointers would be greatly appreciated.

  2. #2
    SitePoint Guru
    Join Date
    Feb 2005
    Posts
    602
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do DomainA and DomainB have the same domain suffix? That is, is it like msdn.microsoft.com and support.microsoft.com? If that's the case, on both pages (the one on DomainA and the one on DomainB), do document.domain = shared_domain_suffix.

    If not, you'll need to send a HTTP request from DomainA to DomainB. This can be done in a couple ways:
    - submitting a hidden form with action pointing to the page on DomainB (GET or POST)
    - load page on DomainB in a hidden iframe (GET only)
    - XMLHttpRequest/ActiveXObject('Msxml2.XMLHTTP') (GET or POST)
    - document.implementation.createDocument/ActiveXObject('Microsoft.XMLDOM') (GET only)

  3. #3
    SitePoint Member
    Join Date
    May 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Maian. They are on completely different domains. I will try some of your other suggestions.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •