画布 Facebook 应用程序中来自 IFrame 的 HTTP 请求未维护会话关联性
我正在将 Facebook 画布应用程序从 FBML 迁移到基于 iframe 的。
用于与 Facebook API 通信的 Facebook 客户端类被放置在用户第一次访问我的应用程序时的 HTTP 会话中。对于后续请求,我检索存储在会话中的 Facebook 客户端对象,并使用同一客户端与 facebook.com 进行通信。
Facebook 画布应用程序有两种类型,即 facebook.com 内的应用程序。:
- FBML 版本
- iframe 版本
FBML 版本的应用程序维护会话关联性,即应用程序服务器针对来自同一应用程序的请求使用相同的会话对象。脸书用户。
因此,我能够检索放置在会话中的 Facebook 客户端并使用相同的会话对象,但如果是基于 iframe 的画布应用程序,即应用程序显示在 iframe 中,则不会使用相同的会话对象,但每次创建了一个新会话,因此我之前放置的 Facebook 客户端消失了。
不维护会话关联性,并且不断创建新会话。进一步检查cookie,发现在iframe画布应用程序的情况下,名为JSESSIONID的cookie在HttpServletRequest对象中不可用。
转储从 Facebook 应用程序到我的服务器的连续请求所采取的 cookie 和会话:
FBML APP:
--------------------Cookies-------------------
JSESSIONID==6E8792ADDF2AF192BF71864C353DE8E5==null
----------------Session-----------------
Session ID : 6E8792ADDF2AF192BF71864C353DE8E5
Creation time : Thu Sep 08 16:36:19 IST 2011
--------------------Cookies-------------------
JSESSIONID==6E8792ADDF2AF192BF71864C353DE8E5==null
----------------Session-----------------
Session ID : 6E8792ADDF2AF192BF71864C353DE8E5
Creation time : Thu Sep 08 16:36:19 IST 2011
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
IFrame App:
---------------------------------------------
--------------------Cookies-------------------
null
----------------Session-----------------
Session ID : D03845C95FC49E79EF7EED1FE8377799
Creation time : Thu Sep 08 16:39:09 IST 2011
--------------------Cookies-------------------
null
----------------Session-----------------
Session ID : 7466CDB69784FA10C570122BC866DB14
Creation time : Thu Sep 08 16:39:19 IST 2011
--------------------Cookies-------------------
null
----------------Session-----------------
Session ID : 4A23EA79AF929E6C2BD4114173AB250F
Creation time : Thu Sep 08 16:39:45 IST 2011
由于此问题,会话关联性无法维持。但我无法解释为什么会发生这种情况。我正在使用 Struts 2 和普通 servlet。解决方案是使 iframe 画布应用程序能够维护会话关联性,即在每个请求中返回 JSESSIONID cookie。我应该做什么或者有其他解决方案吗?
I am migrating a Facebook canvas application from FBML to iframe based.
The Facebook client class that is used to communicate with Facebook APIs is placed in the HTTP session for the first time user accessed my application. For subsequent requests, I retrieve the Facebook client object stored in the session and communicate to facebook.com with the same client.
There are two types of Facebook canvas applications, that is, applications within facebook.com.:
- FBML version
- iframe version
The FBML version of the application maintains session affinity, that is, the same session object is used by the application server for requests from same Facebook user.
Hence, I am able to retrieve the Facebook client placed in the session and use the same, but in case of an iframe based canvas application, that is, the application is displayed within an iframe, the same session object is not used but each time a new session is created and hence the Facebook client that I placed earlier vanishes.
No session affinity is maintained and new sessions keeps getting created. On further inspecting the cookies, it is found that the cookie named JSESSIONID is not available in HttpServletRequest object in case of iframe canvas application.
Dump of cookies and session taken for consecutive requests from the Facebook application to my server:
FBML APP:
--------------------Cookies-------------------
JSESSIONID==6E8792ADDF2AF192BF71864C353DE8E5==null
----------------Session-----------------
Session ID : 6E8792ADDF2AF192BF71864C353DE8E5
Creation time : Thu Sep 08 16:36:19 IST 2011
--------------------Cookies-------------------
JSESSIONID==6E8792ADDF2AF192BF71864C353DE8E5==null
----------------Session-----------------
Session ID : 6E8792ADDF2AF192BF71864C353DE8E5
Creation time : Thu Sep 08 16:36:19 IST 2011
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
IFrame App:
---------------------------------------------
--------------------Cookies-------------------
null
----------------Session-----------------
Session ID : D03845C95FC49E79EF7EED1FE8377799
Creation time : Thu Sep 08 16:39:09 IST 2011
--------------------Cookies-------------------
null
----------------Session-----------------
Session ID : 7466CDB69784FA10C570122BC866DB14
Creation time : Thu Sep 08 16:39:19 IST 2011
--------------------Cookies-------------------
null
----------------Session-----------------
Session ID : 4A23EA79AF929E6C2BD4114173AB250F
Creation time : Thu Sep 08 16:39:45 IST 2011
It is due to this issue the session affinity is not maintained. But I am not able to reason out why this is happening. I am using Struts 2 and plain servlets. The solution would be to enable a iframe canvas application to maintain session affinity, that is, return the JSESSIONID cookie with every request. What should I do or are there alternative solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了将会话 cookie 保留在 iframe 中,您需要添加 HTTP 标头
P3P
。我不知道确切的值,但在互联网上找到的以下内容对我有用。In order for the session cookie to be preserved in an iframe you need to add the HTTP header
P3P
. I do not know the exact value, but the following found on the Internet worked for me.