Skip to main content

Overview

The Terminal Gateway uses API key-based authentication for both HTTP and WebSocket protocols. Each protocol has a different authentication mechanism:

API Key Provisioning

API keys are provisioned manually by Modulus Labs. To request API credentials:
1

Contact support

Email support@moduluslabs.io with your integration details.
2

Provide information

Include your organization name and intended use case (desktop POS, terminal integration, etc.).
3

Receive credentials

You’ll receive an API key and API secret pair. Store these securely.
Never expose your API key or secret in client-side code, version control, or logs. Store them in environment variables or a secure secrets manager.

HTTP API Authentication

HTTP requests require HMAC-SHA256 signature authentication. Each request must include three authentication headers.

Required Headers

String-to-Sign Format

Construct the string to sign using this format:
Where:
  • METHOD - HTTP method in uppercase (GET, POST)
  • PATH - Request path (e.g., /v1/terminals)
  • TIMESTAMP - Value of x-timestamp header
  • SHA256(BODY) - Hex-encoded SHA256 hash of request body (empty string hash for GET requests)

Signature Computation

Example

For a GET request to /v1/terminals at 2024-01-15T10:30:00.000Z:
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 is the SHA256 hash of an empty string.

Code Examples

Common Authentication Errors


WebSocket API Authentication

WebSocket connections authenticate during the connection handshake. Provide your API key via headers or query parameters.

Authentication via Headers

Include the x-api-key header in your WebSocket connection request:

Authentication via Query Parameter

Alternatively, pass your API key as a query parameter:
When using query parameters, your API key may appear in server logs. Use header-based authentication in production when possible.

Code Examples


Security Best Practices

Protect Credentials

Store API keys and secrets in environment variables or a secure secrets manager. Never hardcode them in source code.

Use Headers for WebSocket

Prefer header-based authentication over query parameters to avoid keys appearing in logs and browser history.

Synchronize Time

For HTTP API, ensure your system clock is synchronized with NTP. Timestamps must be within 5 minutes of server time.

Rotate Keys

Rotate API keys periodically and immediately if you suspect compromise. Contact support for key rotation.

Next Steps

HTTP Quickstart

Start integrating with the HTTP API

WebSocket Quickstart

Start integrating with the WebSocket API

Core Concepts

Learn about device enforcement and reconnection resilience

Data Types

Review shared data types and error codes