Support for Omniauth and Multiple Providers.
Omniauth::MultipleProviders requires User
model and current_user
helper, like Devise.
You should create User model, before rails g omniauth:multiple_providers:install
.
ex) do rails g devise User
You should setup Omniauth configuration, before rails g omniauth:multiple_providers:install
.
ex) create config/initializers/omniauth.rb file.
gem 'devise'
gem 'omniauth'
gem 'omniauth-facebook' # etc you needs
gem 'omniauth-twitter' # etc you needs
Add this line to your application's Gemfile:
gem 'omniauth'
gem 'omniauth-facebook' # etc you needs
# ...
gem 'omniauth-multiple_providers'
And then execute:
$ bundle
Or install it yourself as:
$ gem install omniauth-multiple_providers
app/models/user.rb
(generated by Devise) do not use :omniauthable
.
# app/models/user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable # <= do not use
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
# ...
end
$ rails generate omniauth:multiple_providers:install
$ rake db:migrate # => create provider_users table
You can use new_omniauth_path(provider: :provider_name)
, and It redirect_to /auth/:provider_name
.
And automatically receive callback, and Save to ProviderUser
(app/models/provider_user.rb).
%ul
%li
= link_to new_omniauth_path(provider: :twitter) do
Signup with Twitter
%li
= link_to new_omniauth_path(provider: :facebook) do
Signup with Facebook
%li
= link_to new_omniauth_path(provider: :github) do
Signup with Github
And if you remove connection to Providers,
= link_to omniauth_path(:twitter), method: :delete do
cancel connection
- Drop Dependency of Devise
- Configuratable with initializer
- 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