dflydev/hawk
PHP implementation of the Hawk HTTP authentication scheme. Build a client via ClientBuilder, sign requests with MAC-based Authorization headers using credentials, URL and method, with optional payload/content-type, nonce and ext (plus Oz app/dlg support).
dflydev/hawk is a message authentication code (MAC)-based HTTP authentication scheme, ideal for securing API endpoints where lightweight, stateless, and cryptographically verified authentication is required. It fits well in Laravel applications needing client-server authentication (e.g., mobile apps, IoT devices, or third-party integrations) without relying on OAuth2’s complexity.Authorization: Hawk headers and validating requests before routing.Illuminate\Http\Request/Response via custom wrappers.hash_algorithm in config/app.php).app['hash']) may need extension.Request object may need custom parsing for Hawk headers (e.g., Authorization: Hawk id="...", mac="...").Key Management:
config, environment variables, or a dedicated secrets manager like Hashicorp Vault?)Nonce Handling:
Error Handling:
401 Unauthorized responses with Hawk-specific details.)UnauthorizedException map to Laravel’s HttpException?Bewit Usage:
Logging:
id in Hawk headers) be handled?Testing:
spatie/laravel-hmac) that could complement Hawk?HawkAuthenticate) applied to API routes.Client/Server builders can be registered as Laravel bindings for dependency injection.HawkAuthenticated) for analytics or logging.throttle) to pair Hawk auth with DDoS protection.dflydev/hawk’s Client.sha256 hashing to Hawk’s createRequest() for API calls.// app/Http/Middleware/HawkAuthenticate.php
public function handle(Request $request, Closure $next) {
$server = app(Dflydev\Hawk\Server\Server::class);
try {
$response = $server->authenticate(
$request->method(),
parse_url($request->url(), PHP_URL_HOST),
$request->server('server_port'),
parse_url($request->url(), PHP_URL_PATH),
$request->header('content-type'),
$request->getContent(),
$request->header('Authorization')
);
$request->merge(['hawk_credentials' => $response->credentials()]);
return $next($request);
} catch (UnauthorizedException $e) {
abort(401, 'Hawk authentication failed');
}
}
Server-Authorization headers for critical responses (e.g., payment confirmations)./downloads/:id).parse_url or Request methods.Request/Response to Hawk’s interfaces.api_token for higher security.| Step | Task | Dependencies | Owner |
|---|---|---|---|
| 1 | Define Hawk key management strategy | Security team | PM/Dev |
| 2 | Implement HawkServer service provider |
dflydev/hawk |
Backend |
| 3 | Create Hawk middleware | Laravel middleware | Backend |
| 4 | Update client SDKs to use Hawk | dflydev/hawk |
Mobile/Web |
| 5 | Test nonce storage backend | Redis/DB | QA |
| 6 | Roll out middleware to API routes | Route definitions | Backend |
| 7 | Add response signing for sensitive endpoints | Server-Authorization |
Backend |
| 8 | Implement bewit for public endpoints | Query param parsing | Backend |
| 9 | Monitor auth logs for anomalies | ELK/StatsD | Ops |
config caching to avoid restarting the app during key updates.dflydev/hawk for CVE patches (MIT license implies community-driven security).composer.json to avoid breaking changes.ts, nonce) for failed authentications without exposing keys./debug/hawk) to validate Hawk headers manually.How can I help you explore Laravel packages today?