Auto login in embedded chat

I’m using RocketChat engine to create 1 to 1 chats for my community users, without the need to go to the rocket chat interface, using the “embedded” feature, so, I create the room, add the 2 users, and show both the URL in an iframe (like mychatserver/channel/channel_name?layout=embedded)

The problem is that I need to auto login each user before showing the iFrame, if not, Rocket Chat goes to the login window.

I have the username, id, password, … of each one since I create them with the RocketChat API Rest.

I have tried the documentation explained here (

and I did a test:

  event: 'login-with-token',
  loginToken: 'your-token'
}, '');

But the browser says:

Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘chatservercom’) does not match the recipient window’s origin (‘mywebpagecom’).

How can I load the channel with the user logged?

Thank you !