Generator for using Devise & Omniauth with Multiple Providers. I wrote this because I got tired of repeating the same code in every app that required multiple providers.
Basically, to have multiple providers working in a brand new application, all you need to do is run the following:
gem "devise"
rails generate devise:install
rails generate devise User
rails generate domp User facebook twitter
You can list as many providers as you want, check out a full list of them.
Note: this is not an engine but rather a generator which will generate models, controllers and setup configs for you. You are free to change everything. You are the king.
$ gem install domp
First, you need to have devise already installed and your model generated:
rails generate devise:install
rails generate devise User
Run the domp generator:
rails generate domp User facebook twitter
During the generation you will be promted for the provider's application id and secret key.
Model & migration. Will be populated with the providers you specify.
Model & migration.
Here's what the User model will look like:
classUser < ActiveRecord::Basehas_many:authentications,class_name: 'UserAuthentication',dependent: :destroydevise:omniauthable,:database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:validatabledefself.create_from_omniauth(params)attributes={email: params['info']['email'],password: Devise.friendly_token}createattributesendendHere goes all the logic of creating multiple authentications. You are free to change everything, it's just a boilerplate that will make sense in most of the apps.
devise_for:users,controllers: {omniauth_callbacks: 'users/omniauth_callbacks'}The following will be added to config/initializers/devise.rb:
config.omniauth:facebook,'x','x'config.omniauth:twitter,'x','x'gem "omniauth"
gem "omniauth-facebook"
gem "omniauth-twitter"
This gem is released under the MIT License.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request