selling-partner-api-models/clients/sellingpartner-api-aa-java/README.md

104 lines
4.0 KiB
Markdown
Raw Permalink Normal View History

2020-08-06 08:53:39 +08:00
# Selling Partner API Authentication/Authorization Library
This library provides helper classes for use when signing HTTP requests for Amazon Selling Partner APIs. It is intended for use
with the Selling Partner API Client Libraries generated by [swagger codegen](https://swagger.io/tools/swagger-codegen/)
using the OkHttp library. It can also be integrated into custom projects.
## LWAAuthorizationSigner
Obtains and signs a request with an access token from LWA (Login with Amazon) for the specified endpoint using the provided LWA credentials.
*Example*
```
com.squareup.okhttp.Request request = new Request.Builder()
.url(...)
...
.build();
// Seller APIs
LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
.clientId("...")
.clientSecret("...")
.refreshToken("...")
.endpoint("...")
.build();
/* Sellerless APIs
The Selling Partner API scopes can be retrieved from the ScopeConstants class and passed as argument(s) to either the withScope(String scope) or withScopes(String... scopes) method during lwaAuthorizationCredentials object instantiation. */
import static com.amazon.SellingPartnerAPIAA.ScopeConstants.SCOPE_NOTIFICATIONS_API;
LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
.clientId("...")
.clientSecret("...")
.withScopes("...")
.endpoint("...")
.build();
com.squareup.okhttp.Request signedRequest = new LWAAuthorizationSigner(lwaAuthorizationCredentials)
.sign(request);
```
## LWAAccessTokenCache
Interface to implement cache for access token that is returned in LWAClient and reuse the access token until time to live.
2021-08-12 02:16:42 +08:00
## RateLimitConfiguration
2021-08-12 02:07:16 +08:00
Interface to set and get rateLimit configurations that are used with RateLimiter. RateLimiter is used on client side to restrict the rate at which requests are made. RateLimiter Configuration takes Permit, rate which requests are made and TimeOut
*Example*
```
com.squareup.okhttp.Request request = new Request.Builder()
.url(...)
...
.build();
RateLimitConfiguration rateLimitOption = RateLimitConfigurationOnRequests.builder()
.rateLimitPermit(...)
.waitTimeOutInMilliSeconds(...)
.build();
```
2023-09-30 06:37:57 +08:00
## Exception
This package returns a custom LWAException when there is an error returned during LWA authorization. LWAException provides additional details like errorCode and errorDescription to help fix the issue.
*Example*
```
catch (LWAException e) {
System.err.println("LWA Exception when calling Selling partner API");
System.err.println(e.getErrorCode());
System.err.println(e.getErrorMessage());
e.printStackTrace();
}
```
## Version
Selling Partner API Authentication/Authorization Library version 2.0.
2020-08-06 08:53:39 +08:00
## Resources
This package features Mustache templates designed for use with [swagger codegen](https://swagger.io/tools/swagger-codegen/).
When you build Selling Partner API Swagger models with these templates, they help generate a rich SDK with functionality to invoke Selling Partner APIs built in. The templates are located in *resources/swagger-codegen*.
## Building
This library can be built using Maven by running this command in the package root:
```
mvn clean package
```
Dependencies are declared in the pom.xml file.
## License
Swagger Codegen templates are subject to the [Swagger Codegen License](https://github.com/swagger-api/swagger-codegen#license).
All other work licensed as follows:
Copyright 2019 Amazon.com, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this library except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.