简体   繁体   English

Facebook Canvas应用:强制SSL

[英]Facebook Canvas app: Force SSL

after searching the web for a while, I am still not able to find the correct solution to my problem; 在网上搜索了一段时间后,我仍然找不到解决我问题的正确方法; How to make sure the browser is redirected to the https app url. 如何确保浏览器重定向到https应用程序的URL。 Since the canvas app is an iframe, we don't have access to change the window.top.location to the https equivalent. 由于canvas应用是iframe,因此我们无权将window.top.location更改为等效的https。

If the visitor comes to 如果访客来

http://apps.facebook.com/app_name/ http://apps.facebook.com/app_name/

I want him redirected to 我希望他重定向到

https://apps.facebook.com/app_name/ https://apps.facebook.com/app_name/

Totally unable to fix it with javascript in the app loaded in the canvas since top.location is impossible to tamper with due to cross-domain origin rules. 由于跨域来源规则无法对top.location进行篡改,因此完全无法使用画布中加载的应用中的javascript对其进行修复。 It could have been fixed easily with a redirect rule implemented by Facebook, and I am surprised it's not a checkbox in the Facebook app setup to enforce SSL. 可以使用Facebook实现的重定向规则轻松修复该问题,我很惊讶这不是Facebook应用程序设置中用于强制SSL的复选框。 We do not want our game to be accessible over http. 我们不希望通过http访问我们的游戏。

I have tested to set both Canvas URL and Secure Canvas URL to point to the https url, but that gives this error (cross-domain trouble): Unsafe JavaScript attempt to access frame with URL http://apps.facebook.com/app_name/ from frame with URL https://s-static.ak.facebook.com/ 我已经测试过将Canvas URL和Secure Canvas URL都设置为指向https url,但是会出现此错误(跨域问题):不安全的JavaScript尝试使用URL http://apps.facebook.com/app_name访问框架/来自具有URL https://s-static.ak.facebook.com/的框架

Please advice. 请指教。

Ok, so it is possible to redirect the top window. 好了,就可以重定向顶部窗口。 I must have had a typo when I tested it the first time. 第一次测试时我一定有错字。 This tiny script does the trick: 这个小脚本可以达到目的:

<script>
if ( window.location.protocol == 'http:' ) {
    window.top.location = 'https://apps.facebook.com/app_name/';
}
</script>

However, I still don't understand why this isn't an option in the app setup on Facebook. 但是,我仍然不明白为什么在Facebook上的应用程序设置中没有此选项。 It would have been a lot more efficient and user friendly with a server side redirect rule. 使用服务器端重定向规则,本来可以提高效率和用户友好性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM