aporat/laravel-firebase-app-check
Laravel integration for Firebase App Check, helping protect your backend from abuse by verifying requests from legitimate app clients. Adds configuration and middleware for validating App Check tokens on incoming requests.
composer require the package, then publish its config: php artisan vendor:publish --tag=... (check vendor/ for the exact tag). The config file is your first stop — it holds the projects map that everything else keys off.firebase-app-check in bootstrap/app.php (Laravel 11+) or app/Http/Kernel.php (Laravel 10). Add it to your API group, before auth:sanctum, so unverified clients never reach your auth or DB layer.FirebaseAppCheck.getToken() and sends X-Firebase-AppCheck: <token> on every request; your routes are hard-enforced by default, GET reads fall back to soft enforcement automatically.AppCheck::fake() in a feature test to pin the behaviour down.firebase-app-check on the whole API group and relax individual routes with firebase-app-check:soft — useful for endpoints your web app also calls (read-heavy public catalogues, health pings).:soft routes still reject unknown/unconfigured projects, so soft mode only loosens token verdicts. Use it while instrumenting clients, then flip to hard.AppCheck::resolveProjectUsing(fn ($request) => ...) in a service provider rather than duplicating config lookups in middleware.AppCheck::skipWhen(fn ($request) => ...) handles webhooks, CORS preflight, health checks and internal service calls without sprinkling :soft across route files.AppCheck::rejectUsing(fn ($request, $reason) => response()->json([...], 401)) gives you one response shape for mobile clients instead of the default. Pair it with reportUsing() to route failures into your logging/alerting channel so you can see rejection rates per project before enforcing hard.AppCheck::verify($token, $project = null) when the token arrives somewhere middleware can't see it — queue jobs, websocket handshakes, an upload endpoint accepting a signed URL request.IdTokenVerifier in your login/registration controller: verify the Firebase ID token, get an Identity back, then either Auth::login() a local user or mint a Sanctum/Passport token. Keep the exchange in one action/controller so both mobile and web sign-in paths share it.AppCheck::fake() and IdTokenVerifier::fake() in setUp(); then assertVerified() / recorded-verification assertions in each test. This removes network calls from CI and lets you assert which project and token were checked — a real gap when you support several projects.:soft. If reads start failing after a config change, check project resolution first, not the token.X-Firebase-AppCheck is custom, so CDNs, load balancers, some proxies and serverless gateways may not forward it. Verify with a raw request before blaming the package.InvalidIdToken from IdTokenVerificationFailed. The first is the client's problem (401, "sign in again"); the second is infrastructure (503/retry, alert). Collapsing both into a 401 will mask outages as auth failures and confuse users.RefreshDatabase/container rebinding in unusual setups, and remember a fake that was never consulted passes silently — assert on recorded verifications rather than just the response status.0.1.0, treat facade signatures, config keys and exception hierarchies as unstable; pin the version and read the changelog before minor bumps.How can I help you explore Laravel packages today?