【问题标题】:BigCommerce OAuth "Invalid scope" errorBigCommerce OAuth“无效范围”错误
【发布时间】:2018-10-31 19:07:38
【问题描述】:

我正在尝试从 BigCommerce 检索访问令牌。我正在按照此页面上的说明进行操作:https://developer.bigcommerce.com/apps/callback

当我尝试检索访问令牌时,我收到了无效范围错误。代码如下:

    public function access_token_get(){

            print_r($_GET);

            $tokenUrl = "https://login.bigcommerce.com/oauth2/token";
            $connection = new Connection();
            $connection->setCipher('RC4-SHA');
            $connection->verifyPeer(false);
            $response = $connection->post($tokenUrl, array(
                "client_id" => "123456",
                "client_secret" => "123456",
                "redirect_uri" => "https://my-registered-auth-callback.com/",
                "grant_type" => "authorization_code",
                "code" => urlencode($_GET['code']),
                "scope" => urlencode($_GET['scope']),
                "context" => urlencode($_GET['context'])
            ));

            print_r($response);
            print_r($connection->getLastError());

            $token = $response->access_token;

            print_r($token);
    }

当这段代码运行时,我得到一个空的$response。我添加了getLastError() 行以查看发生了什么,它正在输出:

stdClass Object ( [error] => Invalid scope(s). )

这些是 GET 请求输出的参数:

Array ( [code] => 2idy1ozvee8s0ddlbg3jgquzgtr55gd [context] => stores/xxxxxx [scope] => store_v2_orders store_v2_products store_v2_customers store_v2_content store_v2_marketing store_v2_information_read_only users_basic_information )

为什么我会收到此“无效范围”错误?我还尝试对单个范围进行硬编码以查看是否可行,例如,只执行"scope"=>"store_v2_orders",但是当我这样做时,我收到一条错误消息,提示该范围尚未被用户授予。

【问题讨论】:

    标签: php oauth bigcommerce


    【解决方案1】:

    看起来问题在于我不需要对代码、范围和上下文进行 urlencode。删除 urlencode 函数解决了这个问题。

    【讨论】:

    • 这就是我在查看您的代码时注意到的。很高兴你明白了。
    猜你喜欢
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    • 2020-06-19
    • 2013-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多