Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users aren't signed into a new shop when clicking app link and already signed in #80

Open
shkm opened this issue May 2, 2019 · 0 comments

Comments

@shkm
Copy link

shkm commented May 2, 2019

Background

We just upgraded to the latest version of Shopify app from 7.2.0 to 9.0.1 (omniauth-shopify_oauth2 1.5.0 -> 2.1.0) and we're seeing an issue involving users clicking app links from their shop. We're not using an embedded app.

Scenario

  1. User is signed into app as shop1.myshopify.com
  2. User clicks app link from shop2.myshopify.com
  3. User redirects to app and remains signed in as shop1.myshopify.com

Problem

This seems to me because of the following code:

 option :setup, proc { |env|
        strategy = env['omniauth.strategy']

        shopify_auth_params = strategy.session['shopify.omniauth_params'] && strategy.session['shopify.omniauth_params'].with_indifferent_access
        shop = if shopify_auth_params && shopify_auth_params['shop']
          "https://#{shopify_auth_params['shop']}"
        else
          ''
        end

        strategy.options[:client_options][:site] = shop
}

i.e. we're not checking the params for the request params for the shop domain.

Fix

Changing the code to the following seems to resolve the issue:

  strategy = env["omniauth.strategy"]
  request = Rack::Request.new(env)

  shop = request.params.fetch("shop", strategy.session["shopify.omniauth_params"]&.[](:shop))
  strategy.options[:client_options][:site] = shop ? "https://#{shop}" : ""

i.e. use the shop in params if it exists, or fall back to usual behaviour.

Is there anything wrong with this approach? Am I missing something as to why this isn't the normal behaviour?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant