Skip to content

Commit

Permalink
Merge pull request #1913 from Shopify/zoey/make-scopes-optional
Browse files Browse the repository at this point in the history
Add default value to Configuration.scope parameter to make it optional
  • Loading branch information
zzooeeyy authored Oct 25, 2024
2 parents c8e38c9 + d3560ac commit 753883e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Unreleased
----------
- Make `ShopifyApp.configuration.scope` default to empty list `[]` [1913](https://github.com/Shopify/shopify_app/pull/1913)

22.4.0 (August 22, 2024)
----------
Expand Down
20 changes: 20 additions & 0 deletions docs/shopify_app/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ Using token exchange will ensure that the access token retrieved will always hav
Authorization code grant flow is the OAuth flow that requires the app to redirect the user
to Shopify for installation/authorization of the app to access the shop's data. It is still required for apps that are not embedded.

If your app is not using [Shopify managed installation](https://shopify.dev/docs/apps/auth/installation#shopify-managed-installation) with declared scopes in your `.toml` file, you can change the requested access scopes during OAuth flow
by adding the `scope` to your configurations - `ShopifyApp.configuration` & `ShopifyAPI::Context.setup`.


```ruby
# config/initializers/shopify_app.rb

ShopifyApp.configure do |config|
...
config.scope = ["read_discounts", "write_products"]
...
end

ShopifyAPI::Context.setup(
...
scope: ShopifyApp.configuration.scope,
...
)
```

To perform [authorization code grant flow](https://shopify.dev/docs/apps/auth/get-access-tokens/authorization-code-grant), you app will need to handle
[begin OAuth](#begin-oauth) and [OAuth callback](#oauth-callback) routes.

Expand Down
1 change: 1 addition & 0 deletions lib/shopify_app/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def initialize
@scripttags_manager_queue_name = Rails.application.config.active_job.queue_name
@webhooks_manager_queue_name = Rails.application.config.active_job.queue_name
@disable_webpacker = ENV["SHOPIFY_APP_DISABLE_WEBPACKER"].present?
@scope = []

log_v23_deprecations
end
Expand Down
4 changes: 4 additions & 0 deletions test/shopify_app/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class ConfigurationTest < ActiveSupport::TestCase
assert_equal "auth/shopify/callback", ShopifyApp.configuration.login_callback_url
end

test "defaults scope" do
assert_equal [], ShopifyApp.configuration.scope
end

test "can set root_url which affects login_url" do
original_root = ShopifyApp.configuration.root_url

Expand Down

0 comments on commit 753883e

Please sign in to comment.