B2ALABS® - Smart API Gateway Platform
®
Documentation/Authentication

Authentication Guide

Learn how to authenticate with B2ALABS API using JWT tokens, API keys, and refresh tokens.

Secure by Default

B2ALABS uses industry-standard authentication mechanisms to protect your data. All API requests require valid authentication credentials.

JWT (RFC 7519)
HTTPS Only
Rate Limited

Authentication Methods

JWT Tokens

Short-lived tokens for user sessions and web applications

USE CASES

  • Web dashboard access
  • User sessions
  • Single-page applications

EXPIRY

1 hour (default)

API Keys

Long-lived keys for programmatic access and automation

USE CASES

  • ServerIcon-to-server communication
  • CI/CD pipelines
  • Automated scripts

EXPIRY

No expiration (revocable)

Refresh Tokens

Long-lived tokens to obtain new access tokens

USE CASES

  • Mobile apps
  • Desktop applications
  • Long-running services

EXPIRY

30 days (default)

JWT Token Authentication

Short-lived tokens for user sessions. Ideal for web applications and SPAs.

1Register a New User

curl -X POST http://localhost:8080/api/v1/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "SecurePass123!",
    "name": "John Doe"
  }'

Response:

{
  "data": {
    "id": "uuid-here",
    "email": "user@example.com",
    "name": "John Doe",
    "role": "user"
  }
}

2Login and Get Token

curl -X POST http://localhost:8080/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "SecurePass123!"
  }'

Response:

{
  "data": {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "expires_at": "2025-10-14T15:00:00Z",
    "user": {
      "id": "uuid-here",
      "email": "user@example.com",
      "name": "John Doe",
      "role": "user"
    }
  }
}

3Use Token in Requests

curl -X GET http://localhost:8080/api/v1/auth/me \
  -H "Authorization: Bearer YOUR_JWT_TOKEN_HERE"

Token Structure

JWT tokens have three parts: header.payload.signature

  • Header: Algorithm and token type
  • Payload: User data and claims
  • Signature: Cryptographic signature

Security Best Practices

Never Commit Secrets

CRITICAL

Never commit API keys, tokens, or passwords to version control

Rotate Keys Regularly

HIGH

Rotate API keys every 90 days or immediately if compromised

Use HTTPS Only

CRITICAL

Always use HTTPS in production to protect tokens in transit

Implement Rate Limiting

MEDIUM

Rate limit authentication endpoints to prevent brute force attacks

Scope Permissions

HIGH

Grant minimum required permissions (principle of least privilege)

SDK Examples

Use our official SDKs for easier authentication handling

import { B2ALabsClient } from '@b2alabs/sdk';

// Using API Key
const client = new B2ALabsClient({
  apiKey: 'b2a_xxxxxxxxxxxxxxxxxxxxx',
  baseURL: 'https://api.b2alabs.com'
});

// Make authenticated request
const response = await client.ai.chat.completions({
  model: 'gpt-5',
  messages: [{ role: 'user', content: 'Hello!' }]
});

What's Next?

Questions About Authentication?

Need help implementing authentication? CheckIcon our guides or contact support.

Was this page helpful?