Ask A Question

Notifications

You’re not receiving notifications from this thread.

Ruby on rails - what is the best way to add social authentication in the project?

theshashiverma asked in Rails

I want to add social authentication in my project like user can also login with Facebook, Github, and Google.

I have already added the simple authentication with the devise gem. And now I want to add the social authentication also.

I found many articles on the Internet and I majorly found two way to do that

devise + omniauth
omniauth
So, can anyone suggest me what is the best way to have social authentication

This is the article of omniauth https://richonrails.com/articles/google-authentication-in-ruby-on-rails And this one is of devise+omniauth https://scotch.io/tutorials/integrating-social-login-in-a-ruby-on-rails-application that I followed.

Thank You.

Reply

Devise + Omniauth is typically the easiest route. Devise will handle the regular email logins and social auth via Omniauth.

I've done several videos on this.

https://gorails.com/search?utf8=%E2%9C%93&q=omniauth

Reply

@ChrisOliver Thank you sir for the reply, one more thing to ask,when i am using omniauth+devise, is it necessary to keep the client id and secret in the .env(environment variable) file because for that i have to install a dotenv gem and then to run the project i have to run "dotenv rails server" command. Can I keep the id and secret in omniauth.rb file which is customly created by in the initializer folder?

Reply

You shouldn't keep the client id and secret in your codebase unless it's encrypted. That way if you shared your repo with someone, they wouldn't be able to steal access to all the user's social accounts.

If you're using Rails 5.2, you can put them in the encrypted credentials file by running rails credentials:edit.

Reply

Thank you for the reply sir, yes, I am using 5.2 and you have tell me the new way to keep the secrets and id of providers, I will try to attempt like this.
but, now what i did, I kept the id and secret in devise.rb file and that was also working fine, and now I am suffering from another issue that is how to add multiple provider . can you please check this out https://github.com/plataformatec/devise/issues/5017

and I have one more thing to ask : few days ago I read an article on internet that in upcoming rails6 we are going to use some kind of webpack or webpacker and then we dont need to use the coffeescript in our project or may be it would not be compulsory to use the coffeescript anymore. and it will be fine if we use js. Is it right ? because in project i have used almost coffeescript.

Thank you so much.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,329+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.