Search code examples
ruby-on-railsdeviseomniauthfacebook-loginomniauth-facebook

Rails API Omniauth (Facebook) Login


I have a Rails API which is stateless, with Devise gem for authentication and using Devise generated auth_token to authorise each request. Now I want to add login via Facebook with following flow:

  1. User authorise the Facebook app to get required data.
  2. Redirect to certain page according to Facebook settings (/auth/facebook/callbacks).
  3. Get or create user (if not registered yet).
  4. Redirect to previous page (before we click login with facebook) with auth_token.

The problem is in step 4, how do I get the auth_token via json after redirect. Anyway, the auth_token is generated each time user created or signed in successfully (via email & password).

Any best example for this?

Thanks


Solution

  • I ended up using Facebook Javascript SDK (using FB.login()). Instead of Devise Facebook Omniauth. Then I send the response to the back end API.