Security & Architecture
Cryptographic JWT Validation (EdDSA / Ed25519)
All incoming requests from Torob to your shop carry an asymmetric JWT in the request headers:
X-Torob-Token: The base64-encoded JWT token string.X-Torob-Token-Version: Must be1.
Native PHP Sodium Implementation
Rather than introducing heavy third-party JWT libraries that require frequent maintenance, torob-laravel uses PHP's native ext-sodium extension (sodium_crypto_sign_verify_detached).
The package validates:
- Algorithm Check: Strictly verifies that the header
algequalsEdDSA. - Signature: Verifies the signature against Torob's 32-byte Ed25519 public key.
- Expiration (
exp): Rejects requests wheretime() > exp. - Not-Before (
nbf): Rejects requests wheretime() < nbf. - Audience (
aud): Comparesaudagainst your server'sHostheader (including custom port if specified), preventing tokens issued for other shops from being replayed against your shop.
Middleware Execution
The VerifyTorobToken middleware (torob.auth) guards all inbound routes:
php
// Decoded JWT payload is accessible inside controllers:
$payload = $request->attributes->get('torob_token');If validation fails, the middleware returns HTTP 401 Unauthorized with:
json
{
"error": "Unauthorized: Audience mismatch"
}