Skip to content

Commit ff7bad1

Browse files
authored
Added $state and $options parameters to $authUrl
I need that the AuthHelper accept all the parameters available in the official call url. So I added $state and $options variable to the createAuthRequest method sign (with null default) and passed to the $authUrl construction. https://{shop}.myshopify.com/admin/oauth/authorize?client_id={api_key}&scope={scopes}&redirect_uri={redirect_uri}&state={nonce}&grant_options[]={option}
1 parent 5e57dd6 commit ff7bad1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/AuthHelper.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static function verifyShopifyRequest()
8585
*
8686
* @return void
8787
*/
88-
public static function createAuthRequest($scopes, $redirectUrl = null)
88+
public static function createAuthRequest($scopes, $redirectUrl = null, $state = null, $options = null)
8989
{
9090
$config = ShopifySDK::$config;
9191

@@ -109,7 +109,15 @@ public static function createAuthRequest($scopes, $redirectUrl = null)
109109
if (is_array($scopes)) {
110110
$scopes = join(',', $scopes);
111111
}
112-
$authUrl = $config['AdminUrl'] . 'oauth/authorize?client_id=' . $config['ApiKey'] . '&redirect_uri=' . $redirectUrl . "&scope=$scopes";
112+
if(!empty($state)) {
113+
$state = '&state=' . $state;
114+
}
115+
if(!empty($options)) {
116+
$options = '&grant_options[]=' . join(',', $options);
117+
}
118+
// Official call structure
119+
// https://{shop}.myshopify.com/admin/oauth/authorize?client_id={api_key}&scope={scopes}&redirect_uri={redirect_uri}&state={nonce}&grant_options[]={option}
120+
$authUrl = $config['AdminUrl'] . 'oauth/authorize?client_id=' . $config['ApiKey'] . '&redirect_uri=' . $redirectUrl . "&scope=$scopes" . $state . $options;
113121

114122
header("Location: $authUrl");
115123
}
@@ -144,4 +152,4 @@ public static function getAccessToken()
144152
throw new SdkException("This request is not initiated from a valid shopify shop!");
145153
}
146154
}
147-
}
155+
}

0 commit comments

Comments
 (0)