Skip to content

Commit 39eda8b

Browse files
authored
Merge pull request #1343 from Shopify/zoey/make-scope-optional
Add default value to Context::scope parameter to make it optional
2 parents dbf36b7 + 0d384c2 commit 39eda8b

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Note: For changes to the API, see https://shopify.dev/changelog?filter=api
44
## Unreleased
55

6+
- [#1343](https://github.com/Shopify/shopify-api-ruby/pull/1343) Make ShopifyAPI::Context::scope parameter optional. `scope` defaults to empty list `[]`.
7+
68
## 14.6.0
79

810
- [#1337](https://github.com/Shopify/shopify-api-ruby/pull/1337) Fix type for Shop#google_apps_login_enabled

docs/usage/oauth.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ class ShopifyCallbackController < ApplicationController
123123
```
124124

125125
#### 3. Begin OAuth
126+
To request access scopes from the shop during authorization code grant OAuth flow,
127+
configure access scopes needed by adding the `scope` parameter to the `ShopifyAPI::Context.setup` method in your configuration.
128+
129+
```ruby
130+
ShopifyAPI::Context.setup(
131+
api_key: <SHOPIFY_API_KEY>,
132+
api_secret_key: <SHOPIFY_API_SECRET>,
133+
api_version: <SHOPIFY_API_VERSION>,
134+
scope: <SHOPIFY_API_SCOPES>, # Accepts array or string: "read_orders, write_products" or ["read_orders", "write_products"]
135+
...
136+
)
137+
```
138+
126139
Use [`ShopifyAPI::Auth::Oauth.begin_auth`](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/auth/oauth.rb#L22) method to start OAuth process for your app.
127140

128141
#### Input
@@ -131,6 +144,7 @@ Use [`ShopifyAPI::Auth::Oauth.begin_auth`](https://github.com/Shopify/shopify-ap
131144
| `shop` | `String` | Yes | - | A Shopify domain name in the form `{exampleshop}.myshopify.com`. |
132145
| `redirect_path` | `String` | Yes | - | The redirect path used for callback with a leading `/`. The route should be allowed under the app settings. |
133146
| `is_online` | `Boolean` | No | `true` | `true` if the session is online and `false` otherwise. |
147+
| `scope_override`| `String` or `[String]` | No | `nil` | `nil` will request access scopes configured in `ShopifyAPI::Context.setup` during OAuth flow. Modify this to override the access scopes being requested. Accepts array or string: "read_orders, write_products" or ["read_orders", "write_products"]. |
134148

135149
#### Output
136150
`begin_auth` method will return a hash result in the form of:

lib/shopify_api/context.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class << self
3333
api_key: String,
3434
api_secret_key: String,
3535
api_version: String,
36-
scope: T.any(T::Array[String], String),
3736
is_private: T::Boolean,
3837
is_embedded: T::Boolean,
38+
scope: T.any(T::Array[String], String),
3939
log_level: T.any(String, Symbol),
4040
logger: T.untyped,
4141
host_name: T.nilable(String),
@@ -51,9 +51,9 @@ def setup(
5151
api_key:,
5252
api_secret_key:,
5353
api_version:,
54-
scope:,
5554
is_private:,
5655
is_embedded:,
56+
scope: [],
5757
log_level: :info,
5858
logger: ::Logger.new($stdout),
5959
host_name: nil,

test/context_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ def test_send_a_warning_if_log_level_is_invalid
165165
)
166166
end
167167

168+
def test_scope_config_can_be_optional_and_defaults_to_empty
169+
ShopifyAPI::Context.setup(
170+
api_key: "",
171+
api_secret_key: "",
172+
api_version: "2023-10",
173+
host_name: "",
174+
is_private: false,
175+
is_embedded: true,
176+
)
177+
178+
assert_equal(ShopifyAPI::Auth::AuthScopes.new, ShopifyAPI::Context.scope)
179+
end
180+
168181
def teardown
169182
ShopifyAPI::Context.deactivate_session
170183
end

0 commit comments

Comments
 (0)