【发布时间】:2019-11-05 09:07:28
【问题描述】:
在我的网络应用程序中,我使用iframe 加载“RocketChat”聊天实例。但是当我尝试使用window.postMessage() 登录火箭聊天时,浏览器给了我一个控制台错误。请找到下面的屏幕截图。
axios.post('https://myDomain.rocket.chat/api/v1/login', {
username: '<myUserName>',
password: '<myPassword>'
}).then(function (response) {
if (response.data.status === 'success') {
res.set('Content-Type', 'text/html');
res.send(`
<iframe id="iframe" width="400px" height="900px" src="https://myDomain.rocket.chat?origin=http://localhost:3030"></iframe>
<script>
window.parent.postMessage({
event: 'login-with-token',
loginToken: '${ response.data.data.authToken }'
}, 'https://myDomain.rocket.chat/'); // rocket.chat's URL 206.189.138.6:3000
</script>
`);
}
}).catch(function() {
res.sendStatus(401);
});
【问题讨论】:
标签: authentication iframe browser cross-domain rocket.chat