用于 rails 和 ios 身份验证的 omniauth [英] omniauth for rails and ios authentication

查看:12
本文介绍了用于 rails 和 ios 身份验证的 omniauth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个为 iOS 客户端处理 API 的 rails 应用程序.我使用设计,omniauth-facebook for rails.对于 iOS 客户端,我使用帐户和社交框架进行 facebook 身份验证.我已经获取了 oauth 令牌并通过 omniauth 回调将其传递给 rails 进行身份验证,但我收到此错误.有人可以指导我做错什么吗?下面是我得到的日志.

I have a rails app that handles the api for an iOS client. I use devise, omniauth-facebook for rails. for the iOS client I'm using Accounts and Social framework for the facebook authentication. I've grabbed the oauth token and passing it to rails via the omniauth callback to authenticate but I was getting this error. Can someone please guide me on what I'm doing wrong? below here is the log that I'm getting.

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

Here's the gist of my iOS and backend code. https://gist.github.com/chocnut/ae6f415accd95c8ef415

推荐答案

我能够使用 omniauth-facebook-access-token Gem 实现这一目标.https://github.com/SoapSeller/omniauth-facebook-access-token

I was able to achieve this using the omniauth-facebook-access-token Gem. https://github.com/SoapSeller/omniauth-facebook-access-token

在您的设计初始值设定项中创建另一个名为facebook_access_token"的 oauth 提供程序,它可以使用与 facebook 提供程序相同的凭据.

Create another oauth provider in your devise initializer called 'facebook_access_token', it can use the same credentials as the facebook provider.

将令牌作为参数access_token"发布.如果您希望应用程序的最终响应以 JSON 形式返回,请在回调 url 上使用查询字符串 ?format=json.

Post the token as the param 'access_token'. Use the query string ?format=json on the callback url if you want the final response from your app returned as JSON.

这篇关于用于 rails 和 ios 身份验证的 omniauth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆