Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook login on iPhone. Authenticate with Rails Backend (Devise+Omniauth)

I am trying to implement a facebook user authentication in my iOS6 App through my Rails Backend running with Devise using omniauth. I am looking for a step by step guide how to setup my API and Devise + Authentication.

I only have a only have a rough knowledge about how to do that.

  1. (on App) check if the user signs in on his facebook on iPhone
  2. iPhone is authenticated client sided on Facebook. FB passes me his mobile auth token
  3. I send my auth token or auth hash to my rails backend via API RESTful SSL.
  4. Rails receives the Token and checks if it is valid. ( What command uses the least traffic against FB Graph API? with Koala Gem)
  5. If valid. Check if the user already exists. If not, create a new user.
  6. Create a new session.

Is this correct?

Are there any good examples?

Thank you very much.

like image 352
zer02 Avatar asked Sep 12 '13 18:09

zer02


2 Answers

I'm not familiar with the iPhone piece, but your approach after that is generally accurate. The only exception is that you would typically use provider + uid to find or create a user, rather than a token. That might be what you meant by your #5, but it wasn't clear to me.

Beyond that, there is a good (paid) Railscast on the subject of Omniauth + Devise, which would probably be worth the price for you:

http://railscasts.com/episodes/235-devise-and-omniauth-revised

It covers how you can receive and handle the auth hash, and it gives you a nice starting point for what your methods will look like.

like image 63
Tyler Avatar answered Sep 29 '22 23:09

Tyler


if you don't access to pro episodes i have some links to help.

http://jessewolgamott.com/blog/2012/01/19/the-one-with-a-json-api-login-using-devise/

you can also look into it

http://net.tutsplus.com/tutorials/ruby/how-to-use-omniauth-to-authenticate-your-users/

Nice and easy to code

http://blog.joshsoftware.com/2010/12/16/multiple-applications-with-devise-omniauth-and-single-sign-on/

I hope these will work for you :)

http://www.orhancanceylan.com/rails-twitter-and-facebook-authentications-with-omniauth-and-devise/

like image 31
Fahad Idrees Avatar answered Sep 30 '22 01:09

Fahad Idrees