Etherpad-lite: transfer the sessionID from one domain to another

Created on 19 Jun 2020  路  6Comments  路  Source: ether/etherpad-lite

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

Question

All 6 comments

I guess some logic on site a that when session is initially made it posts the sessionID to etherpad. A plugin in Etherpad would be required.

@JohnMcLear from domain number 1, we cannot set cookies on domain number 2

cookies must be set directly on domain number 2

is there such a plugin or need to be developed?

It will need to be developed. See how I set cookies in ep_what_have_i_missed

It will need to be developed. See how I set cookies in ep_what_have_i_missed

https://github.com/ether/ep_what_have_i_missed 404 not found

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

Was this page helpful?
0 / 5 - 0 ratings