question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

transfer the sessionID from one domain to another

See original GitHub issue

Hi everyone! Any ideas on how I can transfer the sessionID from one domain to another and write it to the client cookie?

domain number 1 - general site domain number 2 - etherpad

There is an ep_auth_session plugin, but it does not work in my case (You do not have permission to access this pad), since I use the following settings:

{
  "ip": "127.0.0.1",
  "trustProxy": true,
  "requireSession": true
}

plus proxy_pass

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
joassouzacommented, Jun 19, 2020

We have something like it. In our case we have a main page that is an iframe that wraps the Etherpad editor. I don’t know if it’s your case, if so, these snippets may help.

Send Message via PostMessage from the wrapper

Window.postMessage(message, '*')

Listen to API calls from outside (Etherpad plugin)

var _listenToAPICallsToSetSessionOnCookie = function() {
  // listen to outbound calls of this API
  window.addEventListener('message', function(e) {
      ... check the content of 'e'
      setSessionOnCookie(e.data.sessionID, e.data.expires)
    }
  });
}

Add the session id (Etherpad plugin)

var setSessionOnCookie = function(sessionID, expires) {
  var existingSessionIDs = getSessionID(); // get existent sessions id
  var sessionIDAlreadyStored = existingSessionIDs.indexOf(sessionID) !== -1;

  if (!sessionIDAlreadyStored) {
    // need to append new session id to the end of existing list
    var allSessionIDs = existingSessionIDs.length ? existingSessionIDs + ',' : '';
    allSessionIDs += sessionID;

    // include expiration, if provided
    var expiration = expires ? ';expires=' + (new Date(expires).toUTCString()) : '';

    document.cookie = 'sessionID=' + allSessionIDs + expiration + ';secure';
  }
}

More info about postMessage API https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

1reaction
JohnMcLearcommented, Jun 19, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Preserving session variables across different domains
Session ids are passed around using cookies by default. Since your websites are on different domains the session cookie does not transfer over,...
Read more >
Cross-Origin Web Sessions
Using the query parameters approach is a simple and effective way to transfer credentials from one domain to another. The server generates a...
Read more >
Can a user session be transferred from one domain to another?
use a form post to transfer from one domain to another. for each session variable, create a hidden form element that uses the...
Read more >
How to share a session details to multiple domain?
Session What you CAN do is post the data to your second site and put it in session variable in the second application....
Read more >
Sharing a Session Across Multiple Domains
Session sharing generally requires a JSESSIONID cookie whose session identifier is shared among all sites within the same session.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found