Java Auth and auth lib changes v1.0

This commit is contained in:
Meena Peri 2023-10-02 12:43:50 -05:00
parent 1133bd580f
commit e1a582d9d8
3 changed files with 32 additions and 19 deletions

View File

@ -66,10 +66,10 @@ AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider = AWSA
.build(); .build();
com.squareup.okhttp.Request signedRequest = new com.squareup.okhttp.Request signedRequest = new
AWSSigV4Signer(awsAuthenticationCredentialsProvider.getCredentials()) AWSSigV4Signer(awsAuthenticationCredentialsProvider)
.sign(request); .sign(request);
``` ```
Note **AWSSigV4 Authentication is now optional**
## LWAAccessTokenCache ## LWAAccessTokenCache
Interface to implement cache for access token that is returned in LWAClient and reuse the access token until time to live. 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* *Example*
``` ```
com.squareup.okhttp.Request request = new Request.Builder() com.squareup.okhttp.Request request = new Request.Builder()
.url(...) .url(...)
... ...
@ -89,8 +88,9 @@ com.squareup.okhttp.Request request = new Request.Builder()
.rateLimitPermit(...) .rateLimitPermit(...)
.waitTimeOutInMilliSeconds(...) .waitTimeOutInMilliSeconds(...)
.build(); .build();
``` ```
## Version
Selling Partner API Authentication/Authorization Library version 1.0
## Resources ## Resources
This package features Mustache templates designed for use with [swagger codegen](https://swagger.io/tools/swagger-codegen/). This package features Mustache templates designed for use with [swagger codegen](https://swagger.io/tools/swagger-codegen/).

View File

@ -1049,11 +1049,22 @@ public class ApiClient {
} }
request = lwaAuthorizationSigner.sign(request); 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; 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. * Build full URL by concatenating base path, the given sub path and query parameters.
* *

View File

@ -333,10 +333,6 @@ public class {{classname}} {
public {{classname}} build() { public {{classname}} build() {
if (awsAuthenticationCredentials == null && awsAuthenticationCustomCredentialsProvider == null) {
throw new RuntimeException("Neither AWSAuthenticationCredentials or AWSAuthenticationCustomCredentialsProvider are set");
}
if (lwaAuthorizationCredentials == null) { if (lwaAuthorizationCredentials == null) {
throw new RuntimeException("LWAAuthorizationCredentials not set"); throw new RuntimeException("LWAAuthorizationCredentials not set");
} }
@ -345,15 +341,16 @@ public class {{classname}} {
throw new RuntimeException("Endpoint not set"); throw new RuntimeException("Endpoint not set");
} }
AWSSigV4Signer awsSigV4Signer; AWSSigV4Signer awsSigV4Signer = null;
if (awsAuthenticationCustomCredentialsProvider != null ) { if (awsAuthenticationCustomCredentialsProvider != null ) {
awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCustomCredentialsProvider); awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCustomCredentialsProvider);
} }
else if (awsAuthenticationCredentialsProvider == null) { else if (awsAuthenticationCredentials != null) {
awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCredentials); if (awsAuthenticationCredentialsProvider == null) {
} awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCredentials);
else { } else {
awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCredentials,awsAuthenticationCredentialsProvider); awsSigV4Signer = new AWSSigV4Signer(awsAuthenticationCredentials, awsAuthenticationCredentialsProvider);
}
} }
LWAAuthorizationSigner lwaAuthorizationSigner = null; LWAAuthorizationSigner lwaAuthorizationSigner = null;
@ -367,11 +364,16 @@ public class {{classname}} {
lwaAuthorizationSigner = new LWAAuthorizationSigner(lwaAuthorizationCredentials,lwaAccessTokenCache); lwaAuthorizationSigner = new LWAAuthorizationSigner(lwaAuthorizationCredentials,lwaAccessTokenCache);
} }
return new {{classname}}(new ApiClient() ApiClient apiClient = new ApiClient()
.setAWSSigV4Signer(awsSigV4Signer)
.setLWAAuthorizationSigner(lwaAuthorizationSigner) .setLWAAuthorizationSigner(lwaAuthorizationSigner)
.setBasePath(endpoint) .setBasePath(endpoint)
.setRateLimiter(rateLimitConfiguration)); .setRateLimiter(rateLimitConfiguration);
if (awsSigV4Signer != null) {
apiClient.setAWSSigV4Signer(awsSigV4Signer);
}
return new {{classname}}(apiClient);
} }
} }
} }