From bb1cd277adf182d422cbb69a7f208100f1840bba Mon Sep 17 00:00:00 2001 From: Alexey Murz Korepov Date: Fri, 14 Jun 2024 10:32:05 +0400 Subject: [PATCH] Add docs about configuring Scope --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 3caa9afaf8d..74a56e8717b 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,8 @@ $project = $request->mapFromResponse($promise->wait()); $response = $client->send($request); $project = $request->mapFromResponse($response); ``` + + ### Custom endpoint for different regions By default, the library uses `api.europe-west1.gcp.commercetools.com` endpoint. If you use a different region, you can configure the client to use a custom endpoint. Here is an example for the `us-central1` region: @@ -107,6 +109,21 @@ $client = ClientFactory::of()->createGuzzleClient( ``` Note that the auth endpoint should contain the `/oauth/token` suffix, but the API endpoint - don't. + +### Configuring the scope + +The scope is needed when you have a client with multiple permissions but you want only a token for a specific scope. If you need to define the scope, you should combine the scope name with the project key, like this: + +```php +const PROJECT_KEY = 'my_project_key'; +const SCOPE = 'manage_project:my_project_key'; +$clientCredentials = new ClientCredentials(CLIENT_ID, CLIENT_SECRET, SCOPE); +$client = ClientFactory::of()->createGuzzleClient($new ClientCredentialsConfig($clientCredentials), new Config()); +``` + +The oauth server will default a token request to the client permissions if the scope is being omitted. The best practice is to create a client in the Merchant Center with the needed permissions and omit the scope when requesting the token. + + ### Migration Guidelines To migrate from the 1.x to the 2.x, there is a guideline below: * [Migration guidelines from v1 to v2](./Migration.md)