Faceboook login with Ruby on Rails and Devise gem


#1

Hi all,

I’ve problems with Rails Devise Facebook auth with Ionic 3. I’ve done the same with my webapp and I can login with Facebook, but I’m having problems to implement this on ionic 3.

I’ve followed this guide https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview and now I can login with Facebook on my webapp.

But on Ionic 3 I can not find any solutions.

Below the step that I’ve done in Ionic:

  1. API call from Ionic to server
return this.http.get(`${environment.apiUrl}users/auth/facebook`)
   .map((data: any) => {
   data = new User(data);
   return data;
})

The result is this message on rails server console:

Started GET “/users/auth/facebook” for 127.0.0.1 at 2017-11-22 17:16:19 +0100 I, [2017-11-22T17:16:19.074803 #1104] INFO – omniauth: (facebook) Request phase initiated.

And I have these errors in the chrome console:

Failed to load http://dev.knf.com:3000/users/auth/facebook: Redirect from ‘http://dev.knf.com:3000/users/auth/facebook’ to ‘https://www.facebook.com/v2.11/dialog/oauth?client_id=&redirect_uri=http://*k&response_type=code&scope=email&state=’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin 'http://*’ is therefore not allowed access.

No rails controllers are called.


If I use the json method:

API call from Ionic to server
return this.http.get(`${environment.apiUrl}users/auth/facebook.json`)
   .map((data: any) => {
   data = new User(data);
   return data;
})

The result is this message on rails server console:

Started GET “/users/auth/facebook.json” for 127.0.0.1 at 2017-11-22 17:19:42 +0100 Processing by Users::OmniauthCallbacksController#passthru as JSON
From: /Users/bistaff/knifeandfork/app/controllers/users/omniauth_callbacks_controller.rb @ line 55 Users::OmniauthCallbacksController#passthru:

    54: def passthru
 => 55:   binding.pry
    56:   super
    57: end
Rendering text template

Rendered text template (0.0ms)
Completed 404 Not Found in 4110ms (Views: 0.6ms | ActiveRecord: 0.0ms)
After that it does not do anymore operations.


There is someone that can help me to understand how I can do to solve this problem?

Thanks in advance.