Devise OmniAuth with a Multi-tenant Rails 5 App

177 views
Skip to first unread message

Will Olson

unread,
Feb 1, 2017, 2:10:02 PM2/1/17
to omniauth

Here is the situation. I have a multi-tenant rails app using the apartment gem where I need to implement a LinkedIn OmniAuth Strategy.

As you can see by my routes, Devise users, and the associated routes, are only persisted on the individual schemas of the subdomains.


Example Route:

Good: https://frank.example.io/users/sign_in

Bad: https://example.io/users/sign_in


Routes

class SubdomainPresent
  def self.matches?(request)
    request.subdomain.present?
  end
end

class SubdomainBlank
  def self.matches?(request)
    request.subdomain.blank?
  end
end

Rails.application.routes.draw do
  constraints(SubdomainPresent) do

    ...

    devise_for :users, controllers: { 
      omniauth_callbacks: 'omniauth_callbacks'
    }
    devise_scope :user do
      get '/users/:id', to: 'users/registrations#show', as: "show_user"
    end

    ...

  end
end


My specific problem is that LinkedIn does not support wildcards with their callback URLs so I am lost on how I might be able to direct users to the right domain after OAuth authentication.


My question is originally posted here if you want to get credit for a correct answer on Stack Overflow: http://stackoverflow.com/q/41971165/3347828

Reply all
Reply to author
Forward
0 new messages