Skip to content

Authentication

Audible uses the same authentication flow as the official iOS app: OpenID Connect with PKCE (Proof Key for Code Exchange), followed by device registration on Amazon’s API.

This gives you long-lived credentials that can be refreshed without re-authentication.

  1. Generate a login URLlogin() creates a PKCE challenge, a device serial, and the Amazon login URL with the correct parameters for the chosen locale.

  2. User logs in — Redirect the user to the login URL in a browser. They sign in with their Amazon/Audible account.

  3. Extract the authorization code — After login, Amazon redirects to a callback URL. Extract the openid.oa2.authorization_code parameter from the redirect URL.

  4. Register the deviceregister() exchanges the authorization code for permanent credentials: access token, refresh token, ADP token, and device private key.

import { login } from 'audible-api-ts'
const { loginUrl, session, cookies } = await login('fr')

The function returns three things:

PropertyTypeDescription
loginUrlstringThe Amazon login URL to redirect the user to
sessionAuthSessionSession data needed for device registration
cookiesAudibleCookie[]Cookies to set in the browser before redirecting

The cookies must be set on the .amazon.{domain} domain before the user navigates to the login URL. There are 3 cookies:

  • frc — A random value identifying the session
  • map-md — Device metadata (app version, bundle ID)
  • amzn-app-id — App identifier string

Open loginUrl in the user’s browser. After successful login, Amazon redirects to:

https://www.amazon.{domain}/ap/maplanding?openid.oa2.authorization_code=XXXXX&...

Extract the openid.oa2.authorization_code query parameter from this URL.

import { register } from 'audible-api-ts'
const credentials = await register(authorizationCode, session)

register returns an AudibleCredentials object. You are responsible for storing it — the library is stateless by design.

// Example: save to a JSON file
import { writeFileSync } from 'node:fs'
writeFileSync(
'credentials.json',
JSON.stringify(credentials, null, 2)
)

The credentials contain:

FieldPurpose
accessTokenBearer token for API requests (expires)
refreshTokenLong-lived token for getting new access tokens
adpTokenMAC DMS token used for request signing
devicePrivateKeyRSA private key for signing requests
serialDevice serial number
localeThe marketplace locale
expiresAtWhen the access token expires
import { login, register, library } from 'audible-api-ts'
// 1. Generate login URL
const { loginUrl, session, cookies } = await login('com')
console.log('Open this URL:', loginUrl)
console.log('Set these cookies first:', cookies)
// 2. Wait for user to log in and get the code
// (your app extracts this from the callback URL)
const authorizationCode = '...'
// 3. Register device
const credentials = await register(authorizationCode, session)
console.log('Authenticated! Token expires at:', credentials.expiresAt)
// 4. Use the credentials
const { items } = await library(credentials)
console.log(`Library contains ${items.length} audiobooks`)