Kev*_*vin 6 ruby facebook ruby-on-rails omniauth
我做了一个测试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
Run Code Online (Sandbox Code Playgroud)
索引视图
<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>
Run Code Online (Sandbox Code Playgroud)
您可能遇到的问题是Rails CSRF伪造检测正在使您的身份验证的某些部分成为现实,因为请求是作为HTTP方法POST进行的.
ApplicationController中的第一行可能是这样的:
class ApplicationController < ActionController::Base
protect_from_forgery
[...]
Run Code Online (Sandbox Code Playgroud)
删除'protect_from_forgery'行,看看这是否有助于解决您的问题.如果事实证明是这种情况,请返回并在更有限的基础上进行设置(仅限相关控制器,请参阅此处的文档:http: //api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html)
有一个很好的例子让Omniauth在http://www.communityguides.eu/articles/16上工作,完整的示例代码在https://github.com/markusproske/omniauth_pure.在那,他们有以下:
class ServicesController < ApplicationController
before_filter :authenticate_user!, :except => [:create, :signin, :signup, :newaccount, :failure]
protect_from_forgery :except => :create
Run Code Online (Sandbox Code Playgroud)
你需要这两行的一些变体来使omniauth,facebook和rails会话很好地协同工作.如果这对您不起作用,请将您的OmniAuth :: Builder信息从environment/production.rb(详细信息已删除)以及用于身份验证的控制器中的任何其他相关代码发布,这将有助于调试此问题.
使用facebook开发使用http://tunnlr.com或其他服务(或仅仅是ssh隧道http://blog.kenweiner.com/2007/09/reverse-ssh-tunnel-for)进行调试的rails应用程序可能会更容易-facebook.html),它允许您在本地计算机上运行调试器,这对于解决这些问题非常有帮助.
如果我cookies.permanent.signed[:fb_auth]这样做,它允许我返回 Facebook 中的应用程序,而无需重新登录。这是解决无法通过 iFrames 进行会话的最佳方法吗?
| 归档时间: |
|
| 查看次数: |
2277 次 |
| 最近记录: |