Skip to content

Commit e3226e7

Browse files
authored
Update method to use grant_options (#847)
1 parent 9cdf23f commit e3226e7

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Under the hood, the `create_permission_url` method is preparing the app to make
149149
* ``scope`` – Required – The list of required scopes (explained here: https://shopify.dev/tutorials/authenticate-with-oauth#scopes)
150150
* ``redirect_uri`` – Required – The URL where you want to redirect the users after they authorize the client. The complete URL specified here must be identical to one of the Application Redirect URLs set in the app's section of the Partners dashboard.
151151
* ``state`` – Optional – A randomly selected value provided by your application, which is unique for each authorization request. During the OAuth callback phase, your application must check that this value matches the one you provided during authorization. [This mechanism is essential for the security of your application](https://tools.ietf.org/html/rfc6819#section-3.6).
152-
* ``grant_options[]`` - Optional - Set this parameter to `per-user` to receive an access token that respects the user's permission level when making API requests (called online access). We strongly recommend using this parameter for embedded apps.
152+
* ``grant_options`` - Optional - Set this parameter to `per-user` to receive an access token that respects the user's permission level when making API requests (called online access). We strongly recommend using this parameter for embedded apps.
153153

154154
### 4) Trading your `code` for an access token.
155155

lib/shopify_api/session.rb

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def initialize(domain:, token:, access_scopes: nil, api_version: ShopifyAPI::Bas
103103
def create_permission_url(scope, redirect_uri, options = {})
104104
params = { client_id: api_key, scope: ShopifyAPI::ApiAccess.new(scope).to_s, redirect_uri: redirect_uri }
105105
params[:state] = options[:state] if options[:state]
106+
params["grant_options[]".to_sym] = options[:grant_options] if options[:grant_options]
106107
construct_oauth_url("authorize", params)
107108
end
108109

test/session_test.rb

+16
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,22 @@ def setup
338338
)
339339
end
340340

341+
test "create_permission_url returns correct url with grant_options[]" do
342+
ShopifyAPI::Session.setup(api_key: "My_test_key", secret: "My test secret")
343+
session = ShopifyAPI::Session.new(
344+
domain: 'http://localhost.myshopify.com',
345+
token: 'any-token',
346+
api_version: any_api_version
347+
)
348+
scope = []
349+
permission_url = session.create_permission_url(scope, "http://my_redirect_uri.com", grant_options: "per-user")
350+
assert_equal(
351+
"https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&" \
352+
"scope=&redirect_uri=http://my_redirect_uri.com&grant_options[]=per-user",
353+
permission_url
354+
)
355+
end
356+
341357
test "raise exception if code invalid in request token" do
342358
ShopifyAPI::Session.setup(api_key: "My test key", secret: "My test secret")
343359
session = ShopifyAPI::Session.new(

0 commit comments

Comments
 (0)