iframe-auth-example icon indicating copy to clipboard operation
iframe-auth-example copied to clipboard

Getting Error : Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://localhost:3000') does not match the recipient window's origin ('http://localhost:3030')

Open vpkreddi opened this issue 7 years ago • 11 comments

Hi, I am getting error when trying to submit login

Ubuntu 18.04 Rocket chat server running on http://localhost:3000 This application running on http://localhost:3030 Error in console : Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://localhost:3000') does not match the recipient window's origin ('http://localhost:3030')

vpkreddi avatar Sep 25 '18 06:09 vpkreddi

Same problem here. Are we misunderstanding something, it is a ssl problem?

juliandehne avatar Nov 02 '18 11:11 juliandehne

I just got this running fine with following configs on rocket.chat image

are you guys trying with same configs?

sampaiodiego avatar Nov 08 '18 11:11 sampaiodiego

Same problem for me, i just need understand whats is Iframe Url and API URL, because i have my application and rocketchat in different domains.

MalinaliRap avatar Aug 02 '19 19:08 MalinaliRap

I am have the same problem. Did you find a solution?

giterium avatar Aug 06 '19 14:08 giterium

  1. You log in to the rocket chat programmatically and get a token
  2. you create on a certain URL (Iframe URL) the output of js code performing authorization in the window where it is displayed and the received token is already present in it
  3. the web interface only works through the receipt of this code, the web interface always requests a token code for this url
  4. you cannot log in directly through the web interface

yes? this is not very nice because the chat is used in different ways at the same time :)

giterium avatar Aug 06 '19 15:08 giterium

And to be able to get a token from the current session it is necessary that the domains of the site and chat were the same. No other options?

giterium avatar Aug 07 '19 12:08 giterium

Same problem here, I need acces from https://localhost to development tests. I Try change cors permssion and nothing happens..

salviof avatar Dec 06 '19 15:12 salviof

Any news about this? I facing the same issues!

anasappsaya avatar Aug 14 '20 10:08 anasappsaya

Honestly, I don't get how I should identify the user when the iframe calls sso route. I mean it ´is an iframe - I cannot access any cookie which I set before on the parent host.

From My understanding, they want you to drop the ifrmye in the html: <iframe width="100%;" height="100%" src="https://my.rocketchat.com/channel/general?layout=embedded" frameborder="0"></iframe> Then the iframe will try to call the sso route if this is not working it will try to call the login route.

So the frontend has to insert the script tag or to save the token somehow. But this nowhere shown. So I am kinda confused. I appreciate the example but it seems that it needs a little more explanation.

@giterium did you figure out a way to request it from a different domain?

snake-py avatar Jan 16 '21 03:01 snake-py

I fixed the issue by navigating to "General" tab under the "Administration" settings and unchecked "Restrict access inside any Iframe"

        <script>
            console.log('initializing the chat box');
            let host = 'https://rocket.rdicorp.com';
            fetch(host + '/api/v1/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
                },
                body: 'user=' + encodeURIComponent('username_goes_here') + '&password=' + encodeURIComponent('password_goes_here')
            }).then((response) => response.json())
              .then((respose) => {
                  console.log('chat logged in', respose, respose.data.authToken);
                  let container = document.getElementById('chat-box-holder');

                  if (respose.status == 'success') {

                      var frame = document.createElement('iframe');
                      frame.src = host +'/channel/general/?layout=embedded';
                      frame.title = 'Chat box';
                      frame.scrolling = 'no';
                      frame.frameBorder = '0';

                      container.appendChild(frame);

                      frame.contentWindow.postMessage({
                          event: 'login-with-token',
                          loginToken: respose.data.authToken
                      }, host);


                  }
               });
        </script>

MikeAlhayek avatar Mar 31 '21 16:03 MikeAlhayek