Devise + Omniauth for google only login

authentication, devise, ruby, ruby-on-rails-3

Solution

In your User model you will have a line that looks like this:

  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable, :omniauthable

What you want to do is simply remove the strategies you don't want. An explaination of what each one is can be found on the devise repository's page.

Effectively, you want to keep `:omniauthable` and remove `:database_authenticatable` which provides password-based authentication.

Problem

I'm developing a web application that will interact with google APIs. Since the only way to use the application is though a google account I want to only allow login through a google account. I think I'll be using the "omniauth-google-oauth2" strategy, since OAuth2 is the preferred way to access google APIs. To handle the login itself I'd like to use Devise, since I don't like to write it from scratch (thus reinventing the wheel and having to care with all security issues related to a login system). My questions is can I disable Devise login for non-google accounts?

Original source