Shopify / omniauth-shopify-oauth2

Shopify OAuth2 Strategy for OmniAuth 1.0
http://shopify.github.io/omniauth-shopify-oauth2
91 stars 69 forks source link

Switching providers in the Rails app, based on the request.domain of a request? #67

Open ChristofferJoergensen opened 6 years ago

ChristofferJoergensen commented 6 years ago

The initializer for this gem is supposed to look like this:

# config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :shopify, ENV['SHOPIFY_API_KEY'], ENV['SHOPIFY_SHARED_SECRET']
end

However, in our Rails app resides a few different brands who offers the same functionality. Through out the entire app, the request.domain of a request determines which brand you are exposed to (brand1.example.com, brand2.example.com, etc.).

We can easily store brand specific credentials and redirect the users to the brand specific authorization path:

https://example.myshopify.com/admin/oauth/authorize?client_id=brand1&scope=read_orders,read_products&redirect_uri=https://brand1.example.com/auth/shopify/callback

But it's less clear how we administrate having different providers for the middleware, chosen based on the visited request.domain. Any idea how to set this up?