Ruby on rails - what is the best way to add social authentication in the project?
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.
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.
@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?
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
.
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.