Skip to content

Commit

Permalink
Only require lwaRefreshToken when calling grantless operations
Browse files Browse the repository at this point in the history
  • Loading branch information
jlevers committed Aug 16, 2021
1 parent 02b7479 commit 165018f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The array passed to the `Configuration` constructor accepts the following keys:

* `lwaClientId (string)`: Required. The LWA client ID of the SP API application to use to execute API requests.
* `lwaClientSecret (string)`: Required. The LWA client secret of the SP API application to use to execute API requests.
* `lwaRefreshToken (string)`: Required. The LWA refresh token of the SP API application to use to execute API requests.
* `lwaRefreshToken (string)`: The LWA refresh token of the SP API application to use to execute API requests. Required, unless you're only using the `Configuration` instance to call [grantless operations](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/developer-guide/SellingPartnerApiDeveloperGuide.md#grantless-operations).
* `awsAccessKeyId (string)`: Required. AWS IAM user Access Key ID with SP API ExecuteAPI permissions.
* `awsSecretAccessKey (string)`: Required. AWS IAM user Secret Access Key with SP API ExecuteAPI permissions.
* `endpoint (array)`: Required. An array containing a `url` key (the endpoint URL) and a `region` key (the AWS region). There are predefined constants for these arrays in [`lib/Endpoint.php`](https://github.com/jlevers/selling-partner-api/blob/main/lib/Endpoint.php): (`NA`, `EU`, `FE`, and `NA_SANDBOX`, `EU_SANDBOX`, and `FE_SANDBOX`. See [here](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/developer-guide/SellingPartnerApiDeveloperGuide.md#selling-partner-api-endpoints) for more details.
Expand Down
9 changes: 6 additions & 3 deletions lib/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Authentication

private $lwaClientId;
private $lwaClientSecret;
private $refreshToken;
private $refreshToken = null;
private $endpoint;

private $onUpdateCreds;
Expand Down Expand Up @@ -50,7 +50,7 @@ public function __construct(array $configurationOptions)
{
$this->client = new Client();

$this->refreshToken = $configurationOptions['lwaRefreshToken'];
$this->refreshToken = $configurationOptions['lwaRefreshToken'] ?? null;
$this->onUpdateCreds = $configurationOptions['onUpdateCredentials'];
$this->lwaClientId = $configurationOptions['lwaClientId'];
$this->lwaClientSecret = $configurationOptions['lwaClientSecret'];
Expand All @@ -72,7 +72,7 @@ public function __construct(array $configurationOptions)
/**
* @param string|null $scope
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \GuzzleHttp\Exception\GuzzleException|\RuntimeException
*/
public function requestLWAToken(?string $scope = null): array
{
Expand All @@ -87,6 +87,9 @@ public function requestLWAToken(?string $scope = null): array
if ($scope !== null) {
$jsonData["scope"] = $scope;
} else {
if ($this->refreshToken === null) {
throw new RuntimeException('lwaRefreshToken must be specified when calling non-grantless API operations');
}
$jsonData["refresh_token"] = $this->refreshToken;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Configuration
* @const array[string]
*/
public const REQUIRED_CONFIG_KEYS = [
"lwaClientId", "lwaClientSecret", "lwaRefreshToken", "awsAccessKeyId", "awsSecretAccessKey", "endpoint"
"lwaClientId", "lwaClientSecret", "awsAccessKeyId", "awsSecretAccessKey", "endpoint"
];

/**
Expand Down

0 comments on commit 165018f

Please sign in to comment.