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

4.0 KiB

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 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.

RateLimitConfiguration

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();

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.

Resources

This package features Mustache templates designed for use with 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.

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.