Skip to content

Commit 753883e

Browse files
authored
Merge pull request #1913 from Shopify/zoey/make-scopes-optional
Add default value to Configuration.scope parameter to make it optional
2 parents c8e38c9 + d3560ac commit 753883e

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Unreleased
22
----------
3+
- Make `ShopifyApp.configuration.scope` default to empty list `[]` [1913](https://github.com/Shopify/shopify_app/pull/1913)
34

45
22.4.0 (August 22, 2024)
56
----------

docs/shopify_app/authentication.md

+20
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ Using token exchange will ensure that the access token retrieved will always hav
6363
Authorization code grant flow is the OAuth flow that requires the app to redirect the user
6464
to Shopify for installation/authorization of the app to access the shop's data. It is still required for apps that are not embedded.
6565

66+
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
67+
by adding the `scope` to your configurations - `ShopifyApp.configuration` & `ShopifyAPI::Context.setup`.
68+
69+
70+
```ruby
71+
# config/initializers/shopify_app.rb
72+
73+
ShopifyApp.configure do |config|
74+
...
75+
config.scope = ["read_discounts", "write_products"]
76+
...
77+
end
78+
79+
ShopifyAPI::Context.setup(
80+
...
81+
scope: ShopifyApp.configuration.scope,
82+
...
83+
)
84+
```
85+
6686
To perform [authorization code grant flow](https://shopify.dev/docs/apps/auth/get-access-tokens/authorization-code-grant), you app will need to handle
6787
[begin OAuth](#begin-oauth) and [OAuth callback](#oauth-callback) routes.
6888

lib/shopify_app/configuration.rb

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def initialize
6161
@scripttags_manager_queue_name = Rails.application.config.active_job.queue_name
6262
@webhooks_manager_queue_name = Rails.application.config.active_job.queue_name
6363
@disable_webpacker = ENV["SHOPIFY_APP_DISABLE_WEBPACKER"].present?
64+
@scope = []
6465

6566
log_v23_deprecations
6667
end

test/shopify_app/configuration_test.rb

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class ConfigurationTest < ActiveSupport::TestCase
4141
assert_equal "auth/shopify/callback", ShopifyApp.configuration.login_callback_url
4242
end
4343

44+
test "defaults scope" do
45+
assert_equal [], ShopifyApp.configuration.scope
46+
end
47+
4448
test "can set root_url which affects login_url" do
4549
original_root = ShopifyApp.configuration.root_url
4650

0 commit comments

Comments
 (0)