Skip to content

Commit 024d946

Browse files
committed
Refactor create_permission_url to handle optional scope.
Modified `create_permission_url` to make `scope` optional, allowing it to be omitted when specified in the app's configuration (TOML). Updated the README to reflect this change and clarify usage. This improves flexibility and simplifies configuration management.
1 parent 7229004 commit 024d946

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ pip install --upgrade ShopifyAPI
6666
api_version = '2024-07'
6767
state = binascii.b2a_hex(os.urandom(15)).decode("utf-8")
6868
redirect_uri = "http://myapp.com/auth/shopify/callback"
69+
# `scope` should be omitted if provided by app's TOML
6970
scopes = ['read_products', 'read_orders']
7071

7172
newSession = shopify.Session(shop_url, api_version)
72-
auth_url = newSession.create_permission_url(scopes, redirect_uri, state)
73+
# `scope` should be omitted if provided by app's TOML
74+
auth_url = newSession.create_permission_url(redirect_uri, scopes, state)
7375
# redirect to auth_url
7476
```
7577

shopify/session.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ def __init__(self, shop_url, version=None, token=None, access_scopes=None):
5353
self.access_scopes = access_scopes
5454
return
5555

56-
def create_permission_url(self, scope, redirect_uri, state=None):
57-
query_params = dict(client_id=self.api_key, scope=",".join(scope), redirect_uri=redirect_uri)
58-
if state:
59-
query_params["state"] = state
56+
def create_permission_url(self, redirect_uri, scope=None, state=None):
57+
query_params = dict(client_id=self.api_key, redirect_uri=redirect_uri)
58+
# `scope` should be omitted if provided by app's TOML
59+
if scope: query_params["scope"] = ",".join(scope)
60+
if state: query_params["state"] = state
6061
return "https://%s/admin/oauth/authorize?%s" % (self.url, urllib.parse.urlencode(query_params))
6162

6263
def request_token(self, params):

0 commit comments

Comments
 (0)