iframe 中的自动登录远程站点内部 [英] auto login remote site inner in iframe

查看:105
本文介绍了iframe 中的自动登录远程站点内部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的远程站点,可以访问身份验证,现在我想使用 iframe 将此站点合并到我自己的站点中.是否有任何解决方案可以帮助在加载 iframe 时自动登录远程站点?

I have an existing remote site which has Authentication to access, now I want to combine this site in my own site using iframe. Is there any solution which can help to auto login remote site when load the iframe?

<iframe src="http://remote.com/list"></iframe>

如果想访问 http://remote.com/list,需要登录并且只发布用户名/密码才有效.加载 iframe 时如何自动登录?

If want to access http://remote.com/list, login require and only post username/password works. How to auto login when iframe loaded?

这里有一些限制

  • 登录仅适用于 post 方法
  • iframe/javascript 存在跨域问题
  • 不提供登录 API
  • 不能在远程站点进行其他修改

推荐答案

一切皆有可能.但是,由于泄露了对远程页面的访问详细信息,以下解决方案非常不安全.

Everything's possible. However the solution below is very insecure due to disclosure of access details to the remote page.

<form id="login" target="frame" method="post" action="http://remote.com/login">
    <input type="hidden" name="username" value="login" />
    <input type="hidden" name="password" value="pass" />
</form>

<iframe id="frame" name="frame"></iframe>

<script type="text/javascript">
    // submit the form into iframe for login into remote site
    document.getElementById('login').submit();

    // once you're logged in, change the source url (if needed)
    var iframe = document.getElementById('frame');
    iframe.onload = function() {
        if (iframe.src != "http://remote.com/list") {
            iframe.src = "http://remote.com/list";
        }
    }
</script>

usernamepassword 输入的值在客户端是可读的.

The values of username and password inputs are readable on the client side.

这篇关于iframe 中的自动登录远程站点内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆