Tenant Management

Create tenants and manage Data Border access tokens

Tenant Management

These endpoints manage WMS tenant registration and access token lifecycle.

Create Tenant

Creates a new tenant (WMS system) in Data Border.

POST /api/create-tenant

Authentication

Requires Authorization: Bearer <JWT> header with a JWT containing the "create-tenant": true claim.

Request Body

{
  "name": "string",
  "redirectOrigin": "string"
}
FieldTypeRequiredDescription
namestringYesDisplay name for the WMS system
redirectOriginstringYesBase URL for OAuth redirects (must start with https://)

Response

{
  "success": true,
  "data": {
    "tenant_id": "clx1y2z3a4b5c6d7e8f9g0h1",
    "refresh_token": "rt_abc123def456..."
  }
}
FieldDescription
tenant_idUnique identifier for the tenant
refresh_tokenLong-lived token for obtaining access tokens

Example

# Generate JWT (on Data Border server with JWT_SECRET set)
JWT=$(npx tsx scripts/generate-jwt.ts --expiry 1h)

curl -X POST https://adb.example.com/api/create-tenant \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $JWT" \
  -d '{
    "name": "My WMS System",
    "redirectOrigin": "https://my-wms.com/oauth"
  }'

Errors

StatusMessageCause
400Name is requiredMissing or empty name
400redirectOrigin must start with https://Invalid redirect origin
401Invalid tokenJWT is invalid or expired
401Token missing create-tenant claimJWT lacks required permission

Store the refresh token securely. It cannot be retrieved again and is required for all future operations.


Get Data Border Access Token

Exchanges a tenant refresh token for a Data Border access token.

POST /api/get-adb-access-token

Authentication

Requires Authorization: Bearer <JWT> header with the "create-tenant": true claim.

Request Body

{
  "tenant_id": "string",
  "refresh_token": "string"
}
FieldTypeRequiredDescription
tenant_idstringYesThe tenant's unique identifier
refresh_tokenstringYesThe tenant's refresh token

Response

{
  "success": true,
  "data": {
    "access_token": "eyJhbGciOiJIUzI1NiIs..."
  }
}
FieldDescription
access_tokenJWT access token valid for 30 days

Token Claims

The access token contains:

{
  "tenant_id": "clx1y2z3a4b5c6d7e8f9g0h1",
  "iat": 1640995200,
  "exp": 1643587200
}

Example

curl -X POST https://adb.example.com/api/get-adb-access-token \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $JWT" \
  -d '{
    "tenant_id": "clx1y2z3a4b5c6d7e8f9g0h1",
    "refresh_token": "rt_abc123def456..."
  }'

Errors

StatusMessageCause
400tenant_id is requiredMissing tenant ID
400refresh_token is requiredMissing refresh token
401Invalid tokenJWT is invalid or expired
404Tenant not foundTenant ID doesn't exist
401Invalid refresh tokenRefresh token doesn't match

Token Lifecycle

flowchart TD
    A[Application Start] --> B{Token Cached?}
    B -->|No| C[Exchange Refresh Token]
    B -->|Yes| D{Expires in < 7 days?}
    D -->|Yes| C
    D -->|No| E[Use Cached Token]
    C --> F[Cache Token + Expiry]
    F --> E
    E --> G[Make API Calls]

Token Storage

TokenStorageEncryptionAccess
Tenant Refresh TokenDatabaseYes (at rest)Limited to token refresh
Data Border Access TokenMemory/CacheOptionalAPI calls

Security Considerations

  • Refresh tokens never expire but can be revoked
  • Access tokens are JWTs signed with HS256
  • Always transmit tokens over HTTPS
  • Never log tokens in plain text
  • Implement token refresh before expiry

Next Steps

Seller Management

Connect Amazon sellers to your tenant.

OAuth Flow

Implement the Amazon authorization flow.