artapamudaid/secure-api-server

Laravel package for secure API HMAC authentication

1.0.0 2025-07-16 03:07 UTC

This package is auto-updated.

Last update: 2025-07-16 03:09:56 UTC


README

License Latest Version on Packagist CI Tested Laravel Versions

A secure API authentication package for Laravel using API Key + Secret + HMAC signature with nonce & timestamp validation.
Built for protecting internal or third-party API calls with full management support.

โœจ Features

  • ๐Ÿ”‘ Generate secure API Key & Secret
  • ๐Ÿ” Validate signature using HMAC
  • ๐Ÿ•’ Protects with X-TIMESTAMP and X-NONCE
  • ๐Ÿšซ Revoke or delete API Keys
  • ๐Ÿ‘ค Enforce one key per user
  • ๐Ÿ“ฆ Fully tested with PHPUnit 12

๐Ÿ“ฆ Installation (via Packagist)

composer require artapamudaid/secure-api-server

Lalu:

php artisan vendor:publish --tag=config
php artisan migrate

โš™๏ธ Configuration

Konfigurasi berada di config/apikey.php:

return [
    'enabled' => true,
    'timestamp_tolerance' => 300, // in seconds (default 5 minutes)
];

๐Ÿš€ API Endpoints

Method Endpoint Description
POST /secure-api/key Generate API key + secret
GET /secure-api/keys List all API keys
DELETE /secure-api/key/{id} Delete API key
PATCH /secure-api/key/{id}/revoke Revoke API key
POST /secure-api/ping Test secure endpoint

๐Ÿงพ Required Headers for Secured Endpoints

X-API-KEY: {api_key}
X-API-SIGNATURE: {hmac_signature}
X-TIMESTAMP: {unix_timestamp}
X-NONCE: {random_string}

HMAC Signature format:

HMAC_SHA256(api_key . nonce . timestamp, secret)

๐Ÿงช Running Tests

composer install
vendor/bin/phpunit

Dibangun menggunakan:

  • PHPUnit ^12.0

  • Orchestra Testbench (Laravel testing framework)

๐Ÿ›ก Laravel Compatibility

Laravel Version Support
8.x โœ…
9.x โœ…
10.x โœ…
11.x โœ