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)
Here's the gist of my iOS and backend code. https://gist.github.com/chocnut/ae6f415accd95c8ef415
I was able to achieve this using the omniauth-facebook-access-token Gem. https://github.com/SoapSeller/omniauth-facebook-access-token
Create another oauth provider in your devise initializer called 'facebook_access_token', it can use the same credentials as the facebook provider.
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.
When you creates a facebook(fb) app, you should indicate where is located the url callback, probably you set it in fb as: http://localhost:3000/bla/bla
It works fine if you are testing in your own machine but to be able to test in your ios device then you should change localhost
for something like your machine's ip (Ex. 192.168.1.1)
来源:https://stackoverflow.com/questions/27908836/omniauth-for-rails-and-ios-authentication