我有一个rails应用程序来处理iOS客户端的api.我使用devise,omniauth-facebook for rails.对于iOS客户端,我使用帐户和社交框架进行facebook身份验证.我已经抓住oauth令牌并通过omniauth回调将其传递给rails进行身份验证,但我收到了此错误.有人可以指导我做错了什么吗?下面是我得到的日志.
Started POST "/users/auth/facebook/callback" for ::1 at 2015-01-12 10:59:22 +0800 I,[2015-01-12T10:59:22.928323 #99294] INFO -- omniauth: (facebook) Callback phase initiated. E,[2015-01-12T10:59:22.929737 #99294] ERROR -- omniauth: (facebook) Authentication failure! no_authorization_code: OmniAuth::Strategies::Facebook::NoAuthorizationCodeError,must pass either a code (via URL or by an fbsr_XXX signed request cookie) Processing by Users::OmniauthCallbacksController#failure as / Parameters: {"access_token"=>"tokenFromACFBiOS"} Redirected to localhost:3000/users/sign_in Completed 302 Found in 4ms (ActiveRecord: 0.0ms)
这是我的iOS和后端代码的要点. https://gist.github.com/chocnut/ae6f415accd95c8ef415
解决方法
我能够使用omniauth-facebook-access-token Gem实现这一目标.
https://github.com/SoapSeller/omniauth-facebook-access-token
https://github.com/SoapSeller/omniauth-facebook-access-token
在您的设备初始化程序中创建另一个名为“facebook_access_token”的oauth提供程序,它可以使用与facebook提供程序相同的凭据.
将令牌发布为参数’access_token’.如果您希望应用程序的最终响应返回为JSON,请在回调URL上使用查询字符串?format = json.