Closed
Description
Describe the bug
I'm migrating from the v1 to the v2 version of the library. In the v1 the scope
argument worked well, but with v2 I'm receiving a 400 Bad Request
response.
To Reproduce
- Pass the
scope
argument to theClientCredentials
constructor, like this:
const CLIENT_ID = 'my_client_id';
const CLIENT_SECRET = 'my_client_secret';
const SCOPE = 'manage_project';
$clientCredentials = new ClientCredentials(CLIENT_ID, CLIENT_SECRET, SCOPE);
- Get the
400 Bad Request
response error:
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://auth.us-central1.gcp.commercetools.com/oauth/token` resulted in a `400 Bad Request` response:
{"statusCode":400,"message":"Malformed parameter: scope: Invalid scope.","errors":[{"code":"invalid_scope","message":"Ma (truncated...)
in /var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
- Remove the
scope
argument from the constructor, like this:
-$clientCredentials = new ClientCredentials(CLIENT_ID, CLIENT_SECRET, SCOPE);
+$clientCredentials = new ClientCredentials(CLIENT_ID, CLIENT_SECRET);
and see that the error disappears.
Expected behavior
The scope
argument should not produce the error.
So, maybe in the v2 of the API, the scope should be passed via a different way?
Screenshots/Code snippet
Here is a code to reproduce the problem:
use Commercetools\Api\Client\ApiRequestBuilder;
use Commercetools\Api\Client\ClientCredentialsConfig;
use Commercetools\Api\Client\Config;
use Commercetools\Client\ClientCredentials;
use Commercetools\Client\ClientFactory;
require_once __DIR__ . '/vendor/autoload.php';
const CLIENT_ID = 'my_client_id';
const CLIENT_SECRET = 'my_client_secret';
const PROJECT_KEY = 'my_project_key';
const OAUTH_URL = 'https://auth.us-central1.gcp.commercetools.com/oauth/token';
const API_URL = 'https://api.us-central1.gcp.commercetools.com';
const SCOPE = 'manage_project';
$clientCredentials = new ClientCredentials(CLIENT_ID, CLIENT_SECRET, SCOPE);
// $clientCredentials = new ClientCredentials(CLIENT_ID, CLIENT_SECRET);
$authConfig = new ClientCredentialsConfig($clientCredentials, [], OAUTH_URL);
$config = new Config([], API_URL);
$client = ClientFactory::of()->createGuzzleClient($config, $authConfig);
$builder = new ApiRequestBuilder($client);
$request = $builder->withProjectKey(PROJECT_KEY)->get();
$response = $request->execute();
Stack information (please complete the following information):
- PHP: 8.1
- SDK: 10.3.0