How to integrate Google authentication with Devise gem? - ruby-on-rails

I'm setting up a rails app with both normal signup and google authentication combined. For normal Signup, I will use Devise gem and I want to integrate an optional google login. How do I integrate Devise Authentication and Google Authentication properly?
For my rails applications, I have implemented Google authentication alone successfully and I have also implemented Devise Authentication successfully. But I don't know how to combine both together with a single "User" table for user records.
The expected login is this:
https://prnt.sc/m004wf

You need to use omniauth-oauth2 and omniauth-google-oauth2.
Implementation is provided in it.
For facebook login, you can use, omniauth-facebook
Also you have to create project on google cloud console to use google plus authentication where you can get oauth client id & secret key, which will be used in your application.

You can certainly do that, using the devise_two_factor gem.

Related

Using Devise + OmniAuth for Twitter OAuth 2

I'm using devise (4.8.1) and omniauth-twitter and I have "Login with Twitter" working. A user can sign in (a User is created if it doesn't exist yet), the session is persisted and I can store their access token in the database to do further API requests.
For some new Twitter API endpoints I have to upgrade to OAuth 2:
https://developer.twitter.com/en/docs/authentication/oauth-2-0
I'm wondering what's the current way of accomplishing that, I can see there's a [omniauth-oauth2][1] gem but I don't see how this hooks into Twitter and Devise.
I could just implement the callback endpoints from the Twitter's OAuth 2 but I'm unsure how I'd feed that information to Devise then so it takes care of the session persistence.
Any idea where to start?
Thanks!

Integrating Facebook and Google Login to an existing REST API in Ruby on Rails

I have a Rest API written in Ruby on Rails which is having a regular SignUp and SignIn via a username and password. The SignUp and SignIn flows are currently handled through "devise" and "simple_token_authentication" Ruby Gems.
Now I need to integrate Facebook and Google Login to the existing SignUp and SignIn flows. Therefore, I'm looking for a recommendation to implement this easily.
I have already done some research and found, that I could use Koala for Facebook integration and I personally feel like Koala is a heavy Gem only to handle Facebook Login.
Would you recommend using it or does anyone else have an alternative approach. Or even writing a custom code to validate the Facebook access token in the server end sending back the application specific authentication token back to the client would be better.
PS : Is there a possibility of using the Omniauthable module in Devise to authenticate Facebook and Google users via the REST API.

Unlink omniauth provider

I'm building a simple authentication system that will allow multiple providers for a single user. I'm using omniauth and devise. Is there a way to unlink a particular provider for a single user from my application?
By unlinking provider I mean removing the user from oauth application and removing data (uid and things like that) about this particular provider (Facebook, Twitter) from my database. That is, the user will not be able to sign in using Facebook, for example, anymore after unlinking.
I've already checked this and it does not helper too much. I've also checked out devise and omniauth docs. It seems that there's no built in way of achieving this. Do I have to make requests by myself to each provider in order to unlink an OAuth token?
No, OmniAuth and Devise do not have this "feature" built-in. You would have to implement it as a separate controller, that would manage user providers.

How to Use Omniauth after the Authentication?

Im developing and application that will need constant updates from users that will be gathered from their social networks (twitter, facebook, linkedin and g+), but omniauth just allows me to get this data on the authentication.
I need to get them after (with a delayed_job). I could manage to do so on facebook using Koala, but I don't really know how to do it for the other networks...
What I need to activate omniauth outside the authentication process?
You should use OmniAuth to authenticate user. Also you now have their token. Just use it to make API calls required for your task. Don't forget to have all privileges needed.

Authenticating to Spring Security after authenticating to Twitter / Facebook

I have a grails app configured with spring-security-core and I need to allow Facebook / Twitter logins. I'm using the facebook plugin for grails and I'm using twitter4j for twitter authentication. Currently, I am successfully authenticating against Twitter and Facebook.
I'm wondering how I am to integrate those logins with Spring security. If a user logs in with Twitter I am assuming I need to create an account in my database and then use that account to process a login for Spring Security so that it wires up the session appropriately and all the authentication checks happen based on my #Secured annotations and tag usage in my views.
Something similar, I am guessing, needs to happen based on Facebook logins. Can someone point me in the right direction to get this implemented correctly?
A really good resource for understanding how to integrate an external authentication source is this article by Luke Taylor:
http://blog.springsource.com/2010/08/02/spring-security-in-google-app-engine/
Grant

Resources