我制作了一个测试Facebook应用程序,只是为了玩一下,并使用会话来存储身份验证。我正在使用Omniauth。当我从http://fbbtest.heroku.com/登录,然后刷新页面时,会话仍然保存,并显示我已登录。当我尝试从画布http://apps.facebook.com/herokutestapp/登录时,它会将我登录,重定向回来并显示我已登录,但是当我手动刷新时,它会显示我未登录。在Rails 3中,我是否需要做一些特殊的会话处理才能使其在Facebook画布中正常工作?
这是我当前在控制器和视图中拥有的内容。
这是我当前在控制器和视图中拥有的内容。
def index
end
def create
session['fb_auth'] = request.env['omniauth.auth']
session['fb_token'] = session['fb_auth']['credentials']['token']
session['fb_error'] = nil
redirect_to root_path
end
def destroy
clear_session
redirect_to root_path
end
def failure
clear_session
session['fb_error'] = 'In order to use this site you must allow us access to your Facebook data<br />'
redirect_to root_path
end
def clear_session
session['fb_auth'] = nil
session['fb_token'] = nil
session['fb_error'] = nil
end
索引视图
<div class="container">
<h1>Heroku FB Test application</h1><br />
<div class="center"><br />
<%=session[:fb_error]%>
<% if session[:fb_token] %>
<p>
Successfully logged in.
</p>
<a href='logout'>Logout</a>
<% else %>
<%= session[:fb_error] %><br />
<%= link_to "Log in with Facebook", "/auth/facebook",:class => "popup", :"data-width" => 600, :"data-height" => 400 %> <br />
<p>
please log in
</p>
<% end %>
</div>
</div>