Shopify / Shopify/shopify_app

ShopStrategy#update_access_scopes? should only be true when user needs to approve new scopes

Open
#1,820 7 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
1.9k
Forks
739
Avg merge
21h 2m
Merged PRs (30d)
1

Description

Issue summary

Before opening this issue, I have:

  • Upgraded to the latest version of the package
    • shopify_app version:
    • Ruby version: 3.2.0
    • Operating system: Ubuntu
  • Set log_level: :debug in my configuration, if applicable
  • Found a reliable way to reproduce the problem that indicates it's a problem with the package
  • Looked for similar issues in this repository
  • Checked that this isn't an issue with a Shopify API

We are dynamically requesting access scopes based on what features our clients want. This means that config.scope = ''.

When a store requests a certain feature, we prompt him to go through the OAuth flow with the additional scopes. This works fine. However...

Expected behavior

When a user logs out & signs in again, the shop access scopes should not change.

Actual behavior

When a user logs out & signs in again, the shop access scopes are reset to config.scope. The reason for that is this method:

module ShopifyApp
  module AccessScopes
    class ShopStrategy
      class << self
        def update_access_scopes?(shop_domain)
          shop_access_scopes = shop_access_scopes(shop_domain)
          configuration_access_scopes != shop_access_scopes
        end

It should only return true if the shop is missing some scopes, not when it has more that are set in config.scope. I believe UserStrategy is already following this logic - it only asks a user to confirm the new scopes when it's a superset of the existing ones.

A potential fix

module ShopifyApp
  module AccessScopes
    class ShopStrategy
      class << self
        def update_access_scopes?(shop_domain)
          shop_access_scopes = shop_access_scopes(shop_domain)
          (configuration_access_scopes.to_a - shop_access_scopes.to_a).present?
        end
      end
    end
  end
end

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate ShopifyApp::AccessScopes::ShopStrategy#update_access_scopes? and compare its behavior with UserStrategy. Verify the scope comparison preserves scopes already granted to a shop and only triggers OAuth when configuration_access_scopes contains missing scopes; the proposed reproduction is logging out and signing in again with dynamically requested scopes.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
authorization
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.