feat: API-Zugang endet mit der Buchung, optionales Ablaufdatum für API-Tokens
Bisher blieb ein einmal erstellter Token gültig, auch wenn Abo bzw. Buchung längst beendet waren. EnsureApiAccessIsBooked prüft jetzt bei jeder Anfrage (v1 und /service/…-Altpfade), ob das Konto API-Zugang hat (ApiAccessEligibilityService::hasApiAccess), sonst 403. Die Tokens bleiben erhalten und funktionieren nach erneuter Buchung wieder. Kunden können beim Erstellen optional ein Ablaufdatum setzen (bis 5 Jahre); die Token-Liste zeigt „Gültig bis“ und einen Hinweis, wenn der Zugang pausiert ist. sanctum:prune-expired räumt abgelaufene Tokens nach 30 Tagen täglich ab. API-Doku (public/api/v1.yml) ergänzt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3def447f51
commit
e77d9e7d09
24 changed files with 319 additions and 66 deletions
38
app/Http/Middleware/EnsureApiAccessIsBooked.php
Normal file
38
app/Http/Middleware/EnsureApiAccessIsBooked.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Api\ApiAccessEligibilityService;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* API-Zugang nur mit laufender Buchung (08.10.2026): aktives Abo,
|
||||
* aktive Zahlungsoption oder Bestandsschutz — dieselbe Regel wie beim
|
||||
* Erzeugen eines Tokens (ApiAccessEligibilityService), jetzt bei jedem
|
||||
* Aufruf. Endet die Buchung, sperren die Tokens; sie bleiben erhalten und
|
||||
* funktionieren wieder, sobald erneut gebucht ist. Gilt für API v1 und die
|
||||
* Legacy-Aliasse unter /service.
|
||||
*/
|
||||
class EnsureApiAccessIsBooked
|
||||
{
|
||||
public function __construct(private readonly ApiAccessEligibilityService $eligibility) {}
|
||||
|
||||
/**
|
||||
* @param Closure(Request): (Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
if ($user instanceof User && ! $this->eligibility->hasApiAccess($user)) {
|
||||
return response()->json([
|
||||
'message' => 'API access requires an active subscription or booking.',
|
||||
], 403);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue