Package Exports
- @sp-api-sdk/auth
- @sp-api-sdk/auth/dist/cjs/index.js
- @sp-api-sdk/auth/dist/es/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@sp-api-sdk/auth) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@sp-api-sdk/auth
Amazon Selling Partner API authentication package
Installing
npm install @sp-api-sdk/authDefault values from the environment
These constructor options can be passed using environment variables:
| Property Name | Environement variable |
|---|---|
clientId |
LWA_CLIENT_ID |
clientSecret |
LWA_CLIENT_SECRET |
refreshToken |
LWA_REFRESH_TOKEN |
Grantless APIs support
Some APIs require grantless authentication, which is done by passing scopes, instead of a refresh token.
The available scopes are exposed in the AuthorizationScope enum from this library.
import { SellingPartnerApiAuth, AuthorizationScope } from "@sp-api-sdk/auth";
import { AuthorizationApiClient } from "@sp-api-sdk/authorization-api-v1";
const auth = new SellingPartnerApiAuth({
clientId: "",
clientSecret: "",
scopes: [AuthorizationScope.NOTIFICATIONS, AuthorizationScope.CLIENT_CREDENTIAL_ROTATION], // Or choose the only ones you need
});
const accessToken = await auth.getAccessToken();Credentials caching
getAccessToken() caches the access token in memory for its whole duration, it will only request a new token if the current one has expired.
Subclassing
You can subclass SellingPartnerApiAuth to add custom logic, for example, caching the access token in a store.
import { SellingPartnerApiAuth } from "@sp-api-sdk/auth";
import { storeToken, getToken } from "./token-store";
class StoredSellingPartnerApiAuth extends SellingPartnerApiAuth {
async getAccessToken() {
let token = await getToken();
if (token) {
return token;
}
token = await super.getAccessToken();
await storeToken(token, { ttl: this.accessTokenExpiration });
return token;
}
}License
MIT
Miscellaneous
╚⊙ ⊙╝
╚═(███)═╝
╚═(███)═╝
╚═(███)═╝
╚═(███)═╝
╚═(███)═╝
╚═(███)═╝