I spent the better part of the last two days getting this to work, but it finally is working, but it feels extremely redundant.I am following a belongs_to method for a table called 'authorizations' - I want a user to be able to sign up via Email, or any Omniauth channel I implement that has an Email(I'll give it a Devise password), and freely link/unlink authorized apps.Auth Controllerclass AuthenticationsController < ApplicationController  skip_before_action :verify_authenticity_token, :only => :steam  def index    @authentications = current_user.authentications.all  end  # <%= link_to 'Authentications', authentications_path %>  def home  end  def twitter     omni = request.env[omniauth.auth]     authentication = Authentication.find_by_provider_and_uid(omni['provider'], omni['uid'])     if authentication      flash[:notice] = Logged in Successfully      sign_in_and_redirect User.find(authentication.user_id)     elsif current_user      token = omni['credentials'].token      token_secret = omni['credentials'].secret      current_user.authentications.create!(:provider => omni['provider'],                                           :uid => omni['uid'],                                           :token => token,                                           :token_secret => token_secret)      flash[:notice] = Authentication successful.      sign_in_and_redirect current_user     else      user = User.new      user.apply_omniauth(omni)      if user.save         flash[:notice] = Logged in.         sign_in_and_redirect User.find(user.id)                   else         session[:omniauth] = omni.except('extra')         redirect_to new_user_registration_path      end     end    end   def destroy     @authentication = Authentication.find(params[:id])     @authentication.destroy     redirect_to authentications_url, :notice => Successfully destroyed authentication.   end   def facebook     omni = request.env[omniauth.auth]     authentication = Authentication.find_by_provider_and_uid(omni['provider'], omni['uid'])     if authentication      flash[:notice] = Logged in Successfully      sign_in_and_redirect User.find(authentication.user_id)     elsif current_user      token = omni['credentials'].token      token_secret =       current_user.authentications.create!(:provider => omni['provider'],                                            :uid => omni['uid'],                                            :token => token,                                            :token_secret => token_secret)      flash[:notice] = Authentication successful.      sign_in_and_redirect current_user     else      user = User.new      user.email = omni['extra']['raw_info'].email       user.apply_omniauth(omni)      if user.save         flash[:notice] = Logged in.         sign_in_and_redirect User.find(user.id)                   else         session[:omniauth] = omni.except('extra')         redirect_to new_user_registration_path      end     end   end    def steam        omni = request.env[omniauth.auth]        authentication = Authentication.find_by_provider_and_uid(omni['provider'], omni['uid'])        if authentication            flash[:notice] = Logged in Successfully            sign_in_and_redirect User.find(authentication.user_id)        elsif current_user        token = omni['extra']['raw_info'].steamid        # render :text => request.env[omniauth.auth].info.to_hash.inspect        puts token        token_secret =             current_user.authentications.create!(:provider => omni['provider'],                                                  :uid => omni['uid'],                                                  :token => token,                                                  :token_secret => token_secret)            flash[:notice] = Authentication successful.            sign_in_and_redirect current_user        else            user = User.new            user.apply_omniauth(omni)        end        if user.save            flash[:notice] = Logged in.            sign_in_and_redirect User.find(user.id)                     else            session[:omniauth] = omni.except('extra')            redirect_to new_user_registration_path        end    endendThis part is extremely redundant, esp when I made more modifications last night to finally get steam to even work. The function it uses within the user modelUser.rb  def apply_omniauth(omni)    authentications.build(:provider => omni['provider'],                           :uid => omni['uid'],                          :token => omni['credentials'].token,                           :token_secret => omni['credentials'].secret)  end  def password_required?    (authentications.empty? || !password.blank?) && super #&& provider.blank?  end  def self.from_omniauth(auth)      where(provider: auth.provider, uid: auth.uid).first_or_create do |user|        user.provider = auth.provider        user.uid = auth.uid        user.email = auth.info.email        user.password = Devise.friendly_token[0,20]      end  endI'm populating fake data for Steam, just as I am for Twitter.I finally do have the joins working on every form, though the final 'else' (Not signed up, trying to freshly join) isn't working as I'd expect I'm trying to see about minimizing redundancies before I bug test.
Rails5/Devise/Omniauth (Multiple Providers)
ruby;ruby on rails;authentication;twitter;facebook