I am trying to create a Rails 5 API only app to create signin functionality with Facebook.
I am using the following gems:
devise_token_auth
omniauth_facebook
I have followed documentation on devise_token_auth to create the app. The demo app provided by them also have similar error.
I am able to sign in successfully. User's receiving token, it is increasing sign_in_count but after that callback is going to http://localhost:8000/auth/facebook/callback#_=_ with a blank page.
Below is the console log of the requests:
Started GET "/omniauth/facebook?resource_class=User" for 127.0.0.1 at <timestamp>
I, [2017-10-05T18:10:34.005009 #21485] INFO -- omniauth: (facebook) Request phase initiated.
Started GET "/omniauth/facebook/callback?code=<code>" for 127.0.0.1 at <timestamp>
I, [2017-10-05T18:10:34.402585 #21485] INFO -- omniauth: (facebook) Callback phase initiated.
Processing by DeviseTokenAuth::OmniauthCallbacksController#redirect_callbacks as HTML
Parameters: {"code"=>"<code>", "state"=>"<state>", "provider"=>"facebook"}
Redirected to http://localhost:8000/auth/facebook/callback
Completed 302 Found in 1ms (ActiveRecord: 0.0ms)
Started GET "/auth/facebook/callback" for 127.0.0.1 at <timestamp>
Processing by DeviseTokenAuth::OmniauthCallbacksController#omniauth_success as HTML
Parameters: {"provider"=>"facebook"}
User Load (0.4ms) SELECT <SQL QUERY>
(0.2ms) begin transaction
SQL (3.8ms) UPDATE <SQL QUERY>
(388.3ms) commit transaction
(0.1ms) begin transaction
(0.1ms) commit transaction
Completed 200 OK in 566ms (Views: 0.2ms | ActiveRecord: 394.6ms)
I have also added omniauth_callbacks_controller.rb but it has no effect.
Code: https://github.com/tannakartikey/rails_api/
Just like with vanilla Devise you need to pass an option in the routes to specify a non-standard controller or it will generate routes to the default controllers provided by the gem:
Rails.application.routes.draw do
mount_devise_token_auth_for 'User', at: 'auth', controllers: {
omniauth_callbacks: 'users/omniauth_callbacks'
}
mount_devise_token_auth_for 'Admin', at: 'admin_auth', controllers: {
omniauth_callbacks: 'admins/omniauth_callbacks'
}
as :admin do
# Define routes for Admin within this block.
end
#scope module: 'api' do
#namespace :v1 do
#resources :users, only: [:show, :index]
#end
#end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With