Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Latest omniauth-facebook gem breaks devise

ruby '2.6.3' gem 'rails', '~> 6.0.2', '>= 6.0.2.1'

I'm using the latest omniauth-facebook and devise together Gemfile: gem 'devise' gem 'omniauth-facebook'

Getting this error when starting the server:

/versions/2.6.3/lib/ruby/gems/2.6.0/gems/devise-4.7.3/lib/devise/omniauth.rb:12:in `': You are using an old OmniAuth version, please ensure you have 1.0.0.pr2 version or later installed. (RuntimeError)

The problem is that if I try to use older omniauth-facebook versions the server works but then the Facebook authentication stops working properly (e.g. fails including emails despite

scope: 'email', info_fields: 'email,name'

in devise.rb. )

I have tried many different version combinations of omniauth-facebook and devise. Either Facebook-authentication stops working properly or the server fails (see above).

like image 670
jco40 Avatar asked Jan 13 '21 13:01

jco40


People also ask

What is omniauth in Ruby on rails?

Devise is a ruby on rails gem which handles all user authentication features in your rails application in a very flexible manner. Omniauth on Facebook enables users to login/signup using their facebook credentials (using their existing account). Devise and omniauth can be used to authenticate users in the same way as a third-party service. Dr.

How do I set up omniauth with Facebook?

You can register as a new user by visiting http//:localhost:3000/users/sign_up. Go ahead and create one! Add a new column called uid to the model that Devise generated. Go into config/initializers/devise.rb and under the omniAuth section add: This requires that you have FACEBOOK_KEY and FACEBOOK_SECRET in your environment.

What is the difference between devise and omniauth-Facebook?

Devise is a ruby on rails gem which handles all user authentication features in your rails application in a very flexible manner. Omniauth-facebook on the other hand enables user authentication (login/signup) using their existing facebook account.

What is omniauth and how do I integrate it?

Omniauth allows you to easily integrate more than sixty authentication providers, including Facebook, Google, Twitter and GitHub. In this tutorial, I’m going to explain how to integrate these authentication providers into your app. For the purpose of this tutorial, we are going to call our new app omniapp.


5 Answers

Please downgrade OmniAuth:

gem "omniauth", "~> 1.9.1"

That's worked for me.

like image 178
Almaty Almaty Avatar answered Oct 23 '22 11:10

Almaty Almaty


Devise 4.8.0 (shipped yesterday) resolves this.

like image 21
Tom Fast Avatar answered Oct 23 '22 09:10

Tom Fast


Using

gem 'devise', github: 'heartcombo/devise', branch: 'ca-omniauth-2'

In Gemfile will fix the problem, awaiting a merge.

Updated my answer based on Carlos answer below, I was in a rush when I posted this using ref.

Thank You, Carlos for maintaining Devise.

like image 29
user706001 Avatar answered Oct 23 '22 09:10

user706001


This is Carlos, Devise maintainer. Please keep an eye on that Pull Request linked above, I just shared how you can test it in your app there:

I'd recommend using the branch ref instead of the git ref directly:

gem 'devise', github: 'heartcombo/devise', branch: 'ca-omniauth-2'

With that you should be able to run bundle update devise omniauth which should hopefully give you OmniAuth 2 and this Devise branch. That should allow the app to boot up.

Lastly, if you've copied over the Devise shared links on your app, or if you have your own links to initiate the OmniAuth authentication flow, you need to make sure they're changed to use a form. (you can do that by using link_to with method: :post option for example, or using button_to, if that works for your app.) Please note that this is a requirement change in how OmniAuth work due to a security issue, read more.

If you run into any issues please comment back in GitHub, and we'll work to get them resolved soon so we can release a new Devise version that fully supports OmniAuth 2. Thanks.

like image 24
Carlos Antonio Avatar answered Oct 23 '22 10:10

Carlos Antonio


I'm pretty sure the issue is related to this devise PR, https://github.com/heartcombo/devise/pull/5327

Devise currently has a version check that doesn't include OmaniAuth > 1.x.x

like image 22
xion Avatar answered Oct 23 '22 11:10

xion