title: Multiple models with devise + omniauth in Rails
body: <p>I am using devise + omniauth to enable facebook/linkedin/twitter login on my website. </p>
  
  <p>I have multiple models with totally different roles and both need social logins, I have been using devise+omniauth successfully unitl now as I needed that only for one login.</p>
  
  <p>However now devise gives error saying I cant use omniauthable on multiple models.</p>
  
  <p>I looked around and someone was helpful enough to create <a href="https://github.com/plataformatec/devise/wiki/OmniAuth-with-multiple-models" rel="nofollow">this wiki</a> explaining how to use omniauth with devise without omniauthable module.</p>
  
  <p>But I think since I would want to use it for different models, I would have to use different paths for signup, which this wiki doesnt explain.</p>
  
  <p>I looked into omniauth and it has some scarce details about options request_path and callback_path which seem to be relevant, but I couldn't figure out what exactly needs to be done.</p>
  
  <p>Any help will be much appreciated.</p>
  
  <p><strong>EDIT</strong>
  This is what I have done till now.</p>
  
  <pre><code># omniauth.rb
  
  Rails.application.config.middleware.use OmniAuth::Builder do
      FACEBOOK_AUTH_REGEX = /^\/(model1|model2)\/auth\/facebook\/$/
      FACEBOOK_CALLBACK_REGEX = /^\/(model1|model2)\/auth\/facebook\/callback\/$/
  
      LINKEDIN_AUTH_REGEX = /^\/(model1|model2)\/auth\/linkedin\/$/
      LINKEDIN_CALLBACK_REGEX = /^\/(model1|model2)\/auth\/linkedin\/callback\/$/
  
      facebook_callback_path = lambda do |env|
          env["PATH_INFO"] =~ FACEBOOK_CALLBACK_REGEX
      end
  
      linkedin_callback_path = lambda do |env|
          env["PATH_INFO"] =~ LINKEDIN_CALLBACK_REGEX
      end
  
      facebook_request_path = lambda do |env|
          match_data = FACEBOOK_AUTH_REGEX.match env["PATH_INFO"]
          if match_data
              "/#{match_data[1]}/auth/facebook/callback/"
          end
      end
      linkedin_request_path = lambda do |env|
          match_data = LINKEDIN_AUTH_REGEX.match env["PATH_INFO"]
          if match_data
              "/#{match_data[1]}/auth/linkedin/callback/"
          end
      end
      provider :facebook, FACEBOOK_ID, FACEBOOK_SECRET, :callback_path =&gt; facebook_callback_path, :request_path =&gt; facebook_request_path
      provider :linkedin, LINKEDIN_ID, LINKEDIN_SECRET, :callback_path =&gt; linkedin_callback_path, :request_path =&gt; linkedin_request_path
  end
  
  #routes.rb
  match "/:model_name/auth/:provider/callback/", :to =&gt; "recruiter_omniauth_callbacks#sync"
  </code></pre>
  
  <p>And it seems to work fine for linkedin but in facebook I get</p>
  
  <pre><code>{"error":{"message":"Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request","type":"OAuthException","code":100}}
  </code></pre>
  
  <p>Not Sure why I get this, what are the two urls it says should be same, I think I am using :model_name/auth/facebook/callback/ everywhere so not sure what is the problem it has.</p>
  
  <p>Any help?</p>