我正在使用带有iframe的oauth2。在 app.rb 中的redirect_uri方法中,我正在重定向到"/"。但是,这导致我的"/"页面显示在 iframe 中,而不是顶层。我可以在我的红宝石代码中解决这个问题吗?或者,我是否需要更改我的 HTML 或 Javascript?
在我的 HTML 中,我有:
<form action="https://XXX.XXXX.com/XXX/authorize" method="get" id="XXXForm" target="XXX">
<input type="hidden" name="client_id" value="my_id"/>
<input type="hidden" name="redirect_uri" value="https://somesite.com/redirect/XXX/"/>
</form>
并且,在 HTML 文件的末尾:
<script type="text/javascript">
$('#XXX').show();
$('#XXXForm').submit();
</script>
而且,在我的app.rb中,我有:
get '/redirect/XXX/' do
redirect_to_url = '/login'
if params[:code] then # authorized okay
# other processing, e.g., get token
redirect_to_url = '/'
end
p "redirect #{redirect_to_url}"
redirect to redirect_to_url
end
看看 https://stackoverflow.com/a/168488/335847,看看是否有帮助。
如果你打算使用javascript,那么我会:
- 改为 Ajax 调用
- 不要打扰辛纳屈内部的重定向
- 只需返回请求的状态(2xx 表示成功,4xx 或 5xx 表示失败)
- 记得使用
halt
以免返回尸体(除非你愿意,但你仍然可以使用halt
) - 如果需要,请使用
request.xhr?
- 使用成功处理程序(或类似处理程序)重定向页面,可能通过使用全局
window
。