Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@sp-api-sdk/auth

Package Overview
Dependencies
Maintainers
1
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sp-api-sdk/auth

Amazon Selling Partner API authentication package

Source
npmnpm
Version
2.2.25
Version published
Weekly downloads
4.3K
-55.85%
Maintainers
1
Weekly downloads
 
Created
Source

@sp-api-sdk/auth

npm version XO code style

Amazon Selling Partner API authentication package

Bizon

Installing

npm install @sp-api-sdk/auth

Usage

The SellingPartnerApiAuth class handles OAuth token acquisition from Login with Amazon (LWA). You must provide exactly one of refreshToken or scopes.

import { SellingPartnerApiAuth } from "@sp-api-sdk/auth";

const auth = new SellingPartnerApiAuth({
  clientId: process.env.LWA_CLIENT_ID,
  clientSecret: process.env.LWA_CLIENT_SECRET,
  refreshToken: "Atzr|…",
});

const accessToken = await auth.getAccessToken();

Default values from the environment

These constructor options can be passed using environment variables:

Property NameEnvironment variable
clientIdLWA_CLIENT_ID
clientSecretLWA_CLIENT_SECRET
refreshTokenLWA_REFRESH_TOKEN

Grantless APIs support

Some APIs (e.g. Notifications API) 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 { NotificationsApiClient } from "@sp-api-sdk/notifications-api-v1";

const auth = new SellingPartnerApiAuth({
  clientId: process.env.LWA_CLIENT_ID,
  clientSecret: process.env.LWA_CLIENT_SECRET,
  scopes: [AuthorizationScope.NOTIFICATIONS],
});

const client = new NotificationsApiClient({
  auth,
  region: "eu",
});

Available scopes:

  • AuthorizationScope.NOTIFICATIONS - For the Notifications API
  • AuthorizationScope.CLIENT_CREDENTIAL_ROTATION - For client credential rotation

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 an external store.

The protected accessTokenExpiration getter provides the current token's expiration date, which is useful for setting TTLs in your cache.

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;
  }
}

Error handling

Authentication errors are thrown as SellingPartnerApiAuthError instances, which extend AxiosError.

import { SellingPartnerApiAuth, SellingPartnerApiAuthError } from "@sp-api-sdk/auth";

try {
  const accessToken = await auth.getAccessToken();
} catch (error) {
  if (error instanceof SellingPartnerApiAuthError) {
    console.error(error.message); // e.g. "access-token error: Response code 401"
  }
}

License

MIT

Miscellaneous

    ╚⊙ ⊙╝
  ╚═(███)═╝
 ╚═(███)═╝
╚═(███)═╝
 ╚═(███)═╝
  ╚═(███)═╝
   ╚═(███)═╝

Keywords

bizon

FAQs

Package last updated on 30 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts