public static function createAuthRequest($scopes, $redirectUrl = null, $state = null, $options = null, $return = false)
    {
        $config = ShopifySDK::$config;

        if(!isset($config['ShopUrl']) || !isset($config['ApiKey'])) {
            throw new SdkException("ShopUrl and ApiKey are required for authentication request. Please check SDK configuration!");
        }

        if (!$redirectUrl) {
            if(!isset($config['SharedSecret'])) {
                throw new SdkException("SharedSecret is required for getting access token. Please check SDK configuration!");
            }

            //If redirect url is the same as this url, then need to check for access token when redirected back from shopify
            if(isset($_GET['code'])) {
                return self::getAccessToken($config);
            } else {
                $redirectUrl = self::getCurrentUrl();
            }
        }

        if (is_array($scopes)) {
            $scopes = join(',', $scopes);
        }
        if(!empty($state)) {
            $state = '&state=' . $state;
        }
        if(!empty($options)) {
            $options = '&grant_options[]=' . join(',', $options);
        }
        // Official call structure
        // https://{shop}.myshopify.com/admin/oauth/authorize?client_id={api_key}&scope={scopes}&redirect_uri={redirect_uri}&state={nonce}&grant_options[]={option}
        $authUrl = $config['AdminUrl'] . 'oauth/authorize?client_id=' . $config['ApiKey'] . '&redirect_uri=' . $redirectUrl . "&scope=$scopes" . $state . $options;

        if ($return) {
            return $authUrl;
        }

        header("Location: $authUrl");
    }
public static function createAuthRequest($scopes, $redirectUrl = null, $state = null, $options = null, $return = false)
    {
        $config = ShopifySDK::$config;

        if(!isset($config['ShopUrl']) || !isset($config['ApiKey'])) {
            throw new SdkException("ShopUrl and ApiKey are required for authentication request. Please check SDK configuration!");
        }

        if (!$redirectUrl) {
            if(!isset($config['SharedSecret'])) {
                throw new SdkException("SharedSecret is required for getting access token. Please check SDK configuration!");
            }

            //If redirect url is the same as this url, then need to check for access token when redirected back from shopify
            if(isset($_GET['code'])) {
                return self::getAccessToken($config);
            } else {
                $redirectUrl = self::getCurrentUrl();
            }
        }

        if (is_array($scopes)) {
            $scopes = join(',', $scopes);
        }
        if(!empty($state)) {
            $state = '&state=' . $state;
        }
        if(!empty($options)) {
            $options = '&grant_options[]=' . join(',', $options);
        }
        // Official call structure
        // https://{shop}.myshopify.com/admin/oauth/authorize?client_id={api_key}&scope={scopes}&redirect_uri={redirect_uri}&state={nonce}&grant_options[]={option}
        $authUrl = $config['AdminUrl'] . 'oauth/authorize?client_id=' . $config['ApiKey'] . '&redirect_uri=' . $redirectUrl . "&scope=$scopes" . $state . $options;

        if ($return) {
            return $authUrl;
        }

        header("Location: $authUrl");
    }
public static function createAuthRequest ( $ scopes , $ redirectUrl = null , $ state = null , $ options = null , $ return = false ) { $ config = ShopifySDK :: $ config ; if ( ! isset ( $ config [ 'ShopUrl' ] ) || ! isset ( $ config [ 'ApiKey' ] ) ) { throw new SdkException ( "ShopUrl and ApiKey are required for authentication request. Please check SDK configuration!" ) ; } if ( ! $ redirectUrl ) { if ( ! isset ( $ config [ 'SharedSecret' ] ) ) { throw new SdkException ( "SharedSecret is required for getting access token. Please check SDK configuration!" ) ; } //If redirect url is the same as this url, then need to check for access token when redirected back from shopify if ( isset ( $ _GET [ 'code' ] ) ) { return self :: getAccessToken ( $ config ) ; } else { $ redirectUrl = self :: getCurrentUrl ( ) ; } } if ( is_array ( $ scopes ) ) { $ scopes = join ( ',' , $ scopes ) ; } if ( ! empty ( $ state ) ) { $ state = '&state=' . $ state ; } if ( ! empty ( $ options ) ) { $ options = '&grant_options[]=' . join ( ',' , $ options ) ; } // Official call structure // https://{shop}.myshopify.com/admin/oauth/authorize?client_id={api_key}&scope={scopes}&redirect_uri={redirect_uri}&state={nonce}&grant_options[]={option} $ authUrl = $ config [ 'AdminUrl' ] . 'oauth/authorize?client_id=' . $ config [ 'ApiKey' ] . '&redirect_uri=' . $ redirectUrl . "&scope=$scopes" . $ state . $ options ; if ( $ return ) { return $ authUrl ; } header ( "Location: $authUrl" ) ; }
Redirect the user to the authorization page to allow the app access to the shop

@see https://help.shopify.com/api/guides/authentication/oauth#scopes For allowed scopes

@param string|string[] $scopes Scopes required by app
@param string $redirectUrl
@param string $state
@param string[] $options
@param bool $return If true, will return the authentical url instead of auto-redirecting to the page.
@throws SdkException if required configuration is not provided in $config

@return void|string
Redirect the user to the authorization page to allow the app access to the shop