MATIH Platform is in active MVP development. Documentation reflects current implementation status.
2. Architecture
API Design
Authentication in APIs

Authentication in APIs

Every API request to the MATIH Platform (except public endpoints like login) must be authenticated. The platform supports three authentication mechanisms: JWT access tokens for user requests, API keys for programmatic access, and service tokens for inter-service communication.


Authentication Methods

MethodUse CaseToken LifetimeHeader
JWT access tokenBrowser/UI requests15 minutesAuthorization: Bearer <token>
JWT refresh tokenToken renewal7 daysPOST body to /api/v1/auth/refresh
API keyProgrammatic/CI accessConfigurableAuthorization: Bearer <api_key_token>
Service tokenService-to-service calls5 minutesAuthorization: Bearer <service_token>

JWT Token Flow

Login

POST /api/v1/auth/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "..."
}

Response:

{
  "success": true,
  "data": {
    "accessToken": "eyJ...",
    "refreshToken": "eyJ...",
    "expiresIn": 900,
    "tokenType": "Bearer"
  }
}

Token Refresh

POST /api/v1/auth/refresh
Content-Type: application/json

{
  "refreshToken": "eyJ..."
}

JWT Claims

The access token carries the following claims:

ClaimTypeDescription
subStringUser identifier
tenant_idStringTenant scope
rolesArrayAssigned RBAC roles
issStringIssuer (matih-platform)
iatNumberIssued-at timestamp
expNumberExpiration timestamp
jtiStringUnique token identifier
typeStringToken type (access, refresh, service, api_key)

API Key Authentication

API keys provide long-lived programmatic access:

GET /api/v1/query/execute
Authorization: Bearer <api_key_token>

API keys are managed through the IAM Service:

EndpointMethodDescription
/api/v1/api-keysPOSTCreate a new API key
/api/v1/api-keysGETList API keys for current user
/api/v1/api-keys/:idDELETERevoke an API key

API key tokens carry restricted permissions (scopes) and are bound to a specific tenant.


Service-to-Service Authentication

When one service calls another, it uses a short-lived service token:

// Generated by JwtTokenProvider
generateServiceToken(serviceName, scopes)
// Lifetime: 5 minutes
// Scopes: limited to the specific operation needed

The service token is included in the Authorization header and carries the originating tenant context.


Authentication Filter Chain

Every request passes through this filter chain in order:

1. SecurityFilter
   - Input validation
   - Attack pattern detection
   - Header sanitization

2. JwtAuthenticationFilter
   - Extract token from Authorization header
   - Validate JWT signature
   - Check token expiration
   - Extract claims (sub, tenant_id, roles)

3. TenantContextFilter
   - Set TenantContextHolder from JWT tenant_id claim
   - Verify X-Tenant-ID header matches JWT claim

4. RbacFilter
   - Check user roles against endpoint permissions
   - Return 403 if insufficient permissions

Public Endpoints

The following endpoints do not require authentication:

EndpointMethodPurpose
/api/v1/auth/loginPOSTUser authentication
/api/v1/auth/refreshPOSTToken refresh
/healthGETHealth check
/api/v1/actuator/healthGETSpring Boot health endpoint

Related Pages