gitlabEdit

๐Ÿ”Authentication

Learn how to authenticate with Dispatcher API using Basic Authentication.

Overview

Docs-Dispatcher uses HTTP Basic Authentication for all API requests. This is a simple and secure method where you send your credentials with each request.

Authentication Flow:

1. Encode your email:password as base64
2. Add Authorization: Basic <base64> header to each request
3. Make Dispatcher API requests
graph LR
    A[Your App] -->|Basic Auth Header| B[Dispatcher API]
    B -->|Service Response| A

Basic Authentication Header

Header Format

All API requests must include the Authorization header with Basic authentication:

Authorization: Basic <base64(email:password)>

How to Create the Header

  1. Concatenate your email and password with a colon: email:password

  2. Encode the string as base64

  3. Prefix with Basic

Example:

Response (Success)

When credentials are valid, the API responds with the requested data (200 OK).

Response (Error)

Invalid Credentials (401):

Missing Authorization Header (401):

Code Examples

curl

Node.js (fetch)

PHP (Guzzle)

Java (HttpClient)

Encoding Base64

Command Line (bash)

Node.js

PHP

Java

circle-info

No Token Expiration: Unlike JWT tokens, Basic Auth credentials don't expire. You send them with every request. This simplifies authentication but requires secure credential storage.

Security Best Practices

1. Never Hardcode Credentials

โŒ Bad:

โœ… Good:

2. Store Credentials Securely

Backend (Node.js/Java/PHP):

  • Environment variables

  • Encrypted configuration files

  • Secret management services (AWS Secrets Manager, HashiCorp Vault, Azure Key Vault)

Browser:

  • โŒ Never store credentials in localStorage/sessionStorage

  • โŒ Never expose credentials to browser JavaScript

  • โœ… Use backend proxy for all Dispatcher calls

Example secure pattern:

3. Use HTTPS Only

All API requests must use HTTPS. HTTP requests will be rejected.

4. Rotate Credentials Regularly

  • Change passwords every 90 days

  • Revoke unused API access

  • Audit user access periodically

  • Use strong, unique passwords (min 12 characters)

5. Handle Authentication Errors

Always check for 401 responses:

Common Authentication Errors

401 Unauthorized

Causes:

  • Wrong email or password

  • Missing Authorization header

  • Incorrectly formatted Basic Auth header

Solutions:

  • Verify credentials are correct

  • Check header format: Authorization: Basic <base64>

  • Ensure credentials are properly base64 encoded

  • Test credentials with -u flag in curl

Debug example:

403 Forbidden

Causes:

  • User lacks permissions for the requested service

  • IP whitelist restriction

Solutions:

  • Contact admin to grant necessary permissions

  • Verify IP is whitelisted (if IP restrictions enabled)

429 Rate Limit

Causes:

  • Too many requests (>100/minute per user)

Solutions:

  • Add rate limiting to your application

  • Implement exponential backoff for retries

  • Cache results when possible

Next Steps

Now that you understand Basic Authentication:

  1. Use Basic Auth with Dispatcher - Complete authentication guide

  2. Quickstart Guide - Send an invoice using validation endpoint

  3. Invoice Recipe - Generate and dispatch a real invoice

Support

Last updated