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

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

AWSSigV4Signer

Signs a request with AWS Signature Version 4 using the provided AWS developer account credentials.

Example

com.squareup.okhttp.Request request = new Request.Builder()
    .url(...)
    ...
    .build();

AWSAuthenticationCredentials awsAuthenticationCredentials = AWSAuthenticationCredentials.builder()
                .accessKeyId("...")
                .secretKey("...")
                .region("...")
                .build();

com.squareup.okhttp.Request signedRequest = new AWSSigV4Signer(awsAuthenticationCredentials)
    .sign(request);

/*Signs request using IAM role credentials.

AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider = AWSAuthenticationCredentialsProvider.builder()
               .roleArn("...")
               .roleSessionName("...")
               .build();
               
com.squareup.okhttp.Request signedRequest = new 
     AWSSigV4Signer(awsAuthenticationCredentialsProvider.getCredentials())
    .sign(request);

LWAAccessTokenCache

Interface to implement cache for access token that is returned in LWAClient and reuse the access token until time to live.

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.