diff --git a/clients/sellingpartner-api-aa-csharp/README.md b/clients/sellingpartner-api-aa-csharp/README.md index 7ae8977e..ea3118bb 100644 --- a/clients/sellingpartner-api-aa-csharp/README.md +++ b/clients/sellingpartner-api-aa-csharp/README.md @@ -61,7 +61,7 @@ AWSAuthenticationCredentials awsAuthenticationCredentials = new AWSAuthenticatio restRequest = new AWSSigV4Signer(awsAuthenticationCredentials) .Sign(restRequest, restClient.BaseUrl.Host); ``` -Note the IRestRequest reference is treated as **mutable** when signed. +Note the IRestRequest reference is treated as **mutable** when signed. **AWSSigV4 Authentication is now optional** ## RateLimitConfiguration @@ -77,6 +77,8 @@ RateLimitConfiguration rateLimitConfig = new RateLimitConfigurationOnRequests }; ``` +## Version +Selling Partner API Authentication/Authorization Library version 1.0 ## Resources This package features Mustache templates designed for use with [swagger codegen](https://swagger.io/tools/swagger-codegen/). diff --git a/clients/sellingpartner-api-aa-csharp/src/Amazon.SellingPartnerAPIAA/resources/swagger-codegen/templates/ApiClient.mustache b/clients/sellingpartner-api-aa-csharp/src/Amazon.SellingPartnerAPIAA/resources/swagger-codegen/templates/ApiClient.mustache index faad4692..9a750567 100644 --- a/clients/sellingpartner-api-aa-csharp/src/Amazon.SellingPartnerAPIAA/resources/swagger-codegen/templates/ApiClient.mustache +++ b/clients/sellingpartner-api-aa-csharp/src/Amazon.SellingPartnerAPIAA/resources/swagger-codegen/templates/ApiClient.mustache @@ -49,7 +49,11 @@ namespace {{packageName}}.Client private void InterceptRequest(IRestRequest request) { lwaAuthorizationSigner.Sign(request); - awsSigV4Signer.Sign(request, RestClient.BaseUrl.Host); + + if(awsSigV4Signer != null && RestClient.BaseUrl.Host.Contains("business-api.amazon.com")) + { + awsSigV4Signer.Sign(request, RestClient.BaseUrl.Host); + } } /// @@ -74,7 +78,10 @@ namespace {{packageName}}.Client {{/netStandard}} lwaAuthorizationSigner = new LWAAuthorizationSigner(Configuration.AuthorizationCredentials); - awsSigV4Signer = new AWSSigV4Signer(Configuration.AuthenticationCredentials); + if(Configuration.AuthenticationCredentials != null) + { + awsSigV4Signer = new AWSSigV4Signer(Configuration.AuthenticationCredentials); + } rateLimitConfig = Configuration.RateLimitConfig; if(rateLimitConfig != null) { diff --git a/clients/sellingpartner-api-aa-csharp/src/Amazon.SellingPartnerAPIAA/resources/swagger-codegen/templates/api.mustache b/clients/sellingpartner-api-aa-csharp/src/Amazon.SellingPartnerAPIAA/resources/swagger-codegen/templates/api.mustache index 32b375e0..20756376 100644 --- a/clients/sellingpartner-api-aa-csharp/src/Amazon.SellingPartnerAPIAA/resources/swagger-codegen/templates/api.mustache +++ b/clients/sellingpartner-api-aa-csharp/src/Amazon.SellingPartnerAPIAA/resources/swagger-codegen/templates/api.mustache @@ -464,18 +464,19 @@ namespace {{packageName}}.{{apiPackage}} throw new NullReferenceException("LWAAuthoriztionCredentials not set"); } - if (awsAuthenticationCredentials == null) - { - throw new NullReferenceException("AWSAuthenticationCredentials not set"); - } {{packageName}}.Client.Configuration configuration = new {{packageName}}.Client.Configuration() { AuthorizationCredentials = lwaAuthorizationCredentials, - AuthenticationCredentials = awsAuthenticationCredentials, RateLimitConfig = rateLimitConfiguration }; + + if(awsAuthenticationCredentials != null) + { + configuration.AuthenticationCredentials = awsAuthenticationCredentials; + } + // default HTTP connection timeout (in milliseconds) configuration.Timeout = 100000; diff --git a/clients/sellingpartner-api-aa-java/README.md b/clients/sellingpartner-api-aa-java/README.md index 1b9acfd9..44620d68 100644 --- a/clients/sellingpartner-api-aa-java/README.md +++ b/clients/sellingpartner-api-aa-java/README.md @@ -66,10 +66,10 @@ AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider = AWSA .build(); com.squareup.okhttp.Request signedRequest = new - AWSSigV4Signer(awsAuthenticationCredentialsProvider.getCredentials()) + AWSSigV4Signer(awsAuthenticationCredentialsProvider) .sign(request); - ``` +Note **AWSSigV4 Authentication is now optional** ## LWAAccessTokenCache Interface to implement cache for access token that is returned in LWAClient and reuse the access token until time to live. @@ -79,7 +79,6 @@ Interface to set and get rateLimit configurations that are used with RateLimiter *Example* ``` - com.squareup.okhttp.Request request = new Request.Builder() .url(...) ... @@ -89,8 +88,9 @@ com.squareup.okhttp.Request request = new Request.Builder() .rateLimitPermit(...) .waitTimeOutInMilliSeconds(...) .build(); - ``` +## Version +Selling Partner API Authentication/Authorization Library version 1.0 ## Resources This package features Mustache templates designed for use with [swagger codegen](https://swagger.io/tools/swagger-codegen/). diff --git a/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/ApiClient.mustache b/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/ApiClient.mustache index 993d2e24..bf10a3fa 100644 --- a/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/ApiClient.mustache +++ b/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/ApiClient.mustache @@ -1049,11 +1049,22 @@ public class ApiClient { } request = lwaAuthorizationSigner.sign(request); - request = awsSigV4Signer.sign(request); - + // Only sign the request using awsSigV4Signer if its setup and request is to an AmazonBusiness endpoint + if(awsSigV4Signer != null && isABEndpoint()) { + request = awsSigV4Signer.sign(request); + } return request; } + /** + * Find if the endpoint is for AmazonBusiness + * + * @return True, if client is setup with an AmazonBusiness endpoint else return false + */ + public boolean isABEndpoint() { + return basePath.contains("business-api.amazon.com"); + } + /** * Build full URL by concatenating base path, the given sub path and query parameters. * diff --git a/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/api.mustache b/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/api.mustache index 8850f1a9..19c7c8fb 100644 --- a/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/api.mustache +++ b/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/api.mustache @@ -333,10 +333,6 @@ public class {{classname}} { public {{classname}} build() { - if (awsAuthenticationCredentials == null && awsAuthenticationCustomCredentialsProvider == null) { - throw new RuntimeException("Neither AWSAuthenticationCredentials or AWSAuthenticationCustomCredentialsProvider are set"); - } - if (lwaAuthorizationCredentials == null) { throw new RuntimeException("LWAAuthorizationCredentials not set"); } @@ -345,15 +341,16 @@ public class {{classname}} { throw new RuntimeException("Endpoint not set"); } - AWSSigV4Signer awsSigV4Signer; + AWSSigV4Signer awsSigV4Signer = null; if (awsAuthenticationCustomCredentialsProvider != null ) { awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCustomCredentialsProvider); } - else if (awsAuthenticationCredentialsProvider == null) { - awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCredentials); - } - else { - awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCredentials,awsAuthenticationCredentialsProvider); + else if (awsAuthenticationCredentials != null) { + if (awsAuthenticationCredentialsProvider == null) { + awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCredentials); + } else { + awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCredentials, awsAuthenticationCredentialsProvider); + } } LWAAuthorizationSigner lwaAuthorizationSigner = null; @@ -367,11 +364,16 @@ public class {{classname}} { lwaAuthorizationSigner = new LWAAuthorizationSigner(lwaAuthorizationCredentials,lwaAccessTokenCache); } - return new {{classname}}(new ApiClient() - .setAWSSigV4Signer(awsSigV4Signer) + ApiClient apiClient = new ApiClient() .setLWAAuthorizationSigner(lwaAuthorizationSigner) .setBasePath(endpoint) - .setRateLimiter(rateLimitConfiguration)); + .setRateLimiter(rateLimitConfiguration); + + if (awsSigV4Signer != null) { + apiClient.setAWSSigV4Signer(awsSigV4Signer); + } + + return new {{classname}}(apiClient); } } }