2FA Middleware
I use Filament as the admin panel for my app. Whenever I login to my app, I get a 2FA screen after clicking login and the rest of the apps routes are not working before 2FA is completed.
Now when I don't enter my 2FA, and try to open my Filament route instead I get the actual dashboard and everything is working. I can delete users etc.
IE: Security hole.
How can I apply my 2FA Middleware? Whenever I add
\App\Http\Middleware\Google2FAMiddleware::class
to the middleware()
or authMiddleware()
methods on my public function panel(Panel $panel): Panel
in AdminPanelProvider.php it doesn't change anything.14 Replies
Anyone? 🙂
Which starter kit are you using? Jetstream or Breeze?
Ensure the middleware for your frontend routes are applied to your backend routes;
https://filamentphp.com/docs/3.x/panels/configuration#applying-middleware
No starter kit. Older project
I have a 2FA middleware alias which is applied to my app routes. Any way to apply the same to Filament routes? When I add the FQDN to the middleware() function in my panel provider it doesnt do anything.
Another thought: Is it possible to disable and bypass Filaments entire auth system and just rely on being logged on to the main app? That last part already works actually, just need to make FIlament inaccessable when the 2FA code hasnt been entered yet.
Just add a redirect. Or register the standard login class you use .
Any pointers? No clue where to look.
Part of my AdminPanelProvider. Do I remove the login method there?
My login controller just uses the
AuthenticatesUsers
trait.->login()
->login(MyLoginClass::class)
Ok. Meeting now, will try after and come back. Thanks!
Hmm. Dont think I could make that work.
It's expecting an invokable class. Yet my LoginController uses an index() and login() method.
It expects a livewire class basically, so just add a redirect in the web routes to that url.
Sorry for being a noob lol but add a redirect where to my /login url? AFAIK filament registers its own routes (/dashboard in my case) and idk if I can edit those.
in your routes/web.php
with /login being your primary login route you want to use, /{any}/ will find any route which ends in /login and redirect to /login.
Ok cool, will try asap. Cheers! 😄
Ok that works perfectly. So simple, nice.
Ah damn. Whenever I login with user/pass, I get shown the 2FA screen (diff URL). If I dont enter 2FA and instead open the dashboard (Filament) URL I am logged into Filament and can do anything. So need to make Filament aware of 2FA being logged in or not somehow
You need the 2fa middlewhere added to filament middleware 😉 For example my middleware for filament is:
Notice the last one? That middleware is:
I added it to both middleware and authmiddleware now and it seems to finally work in prod now too. Cheers!