-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add forced()
method and middleware
#28
Conversation
I believe I already built this in a project of us previous of building this package. I can take a look at it if you want @CodeWithDennis |
Yeah, go for it! Just a heads-up, there are a few PHPSTAN issues. =( |
In the project I have this code: class RedirectWhen2faNotEnabled
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (!$request->user()?->hasTwoFactorEnabled() && !$request->routeIs('filament.admin.pages.two-factor')) {
return redirect()->route('filament.admin.pages.two-factor');
}
return $next($request);
}
} And in my ->withMiddleware(function (Middleware $middleware) {
$middleware->group('panel:admin', [
\Illuminate\Session\Middleware\StartSession::class,
RedirectWhen2faNotEnabled::class
]);
}) I needed the Will take a further look tonight. @CodeWithDennis |
You should be able to edit this PR, so feel free to make any changes! Unless you prefer to rewrite it. =) |
Already fixed redirecting in my lunch break :) @CodeWithDennis |
Dedication 🔥 |
@Baspa Does PHPStan command work for you in my branch? Seems to crash on me. |
Seem to work for me but it was very slow, I also gave it full memory so that might be the reason why it worked for me.. |
One issue with this when using multi-tenancy: Missing required parameter for [Route: filament.customer.pages.two-factor] [URI: customer/{tenant}/two-factor] [Missing parameter: tenant]. |
Can you try again maybe? :) |
Must be something on my side. |
Same problem, i think this is where i got stuck because Shorter: $tenant = filament()->getTenant(); // Still same issue
TwoFactor::getUrl($tenant); But we also need to check if the panel is multi tenancy. |
Hmmm good one.. I have to think about that |
Is it not available in any middleware at all? Or just after a specific middleware? Then we could maybe load that middleware before our middleware? @CodeWithDennis |
I mean it returns |
Won't this be the same problem where we can't access the tenant parameter? I think this PR kinda done if we can figure out how we can access it. (Besides the PHPStan issues) @Baspa Edit: Perhaps session parameter? |
@Baspa I haven't had time to check it again yet. Did you come up with any ideas that might solve the problem? |
@CodeWithDennis unfortunately I haven't been able to take a look at this as well.. hopefully later this week |
It should be fixed right now, can you test it to be sure? @CodeWithDennis |
Yes it works! Couple of questions:
|
Hmm, when you're not using tenancy the |
I can imagine that if users are constantly being redirected to this page, it could be confusing, and they might not understand what's happening. It would be good to inform them that the app requires 2FA before they can use it. I don't have time right now, but if I get a chance and you haven't added it yet, I'll take a look. |
I can make a difference in which middleware to use now by also adding |
I think you can check if the |
Unfortunately |
@@ -22,10 +22,10 @@ public function handle(Request $request, Closure $next): mixed | |||
if ($currentPanel) { | |||
return redirect()->to(route('filament.' . $currentPanel->getId() . '.pages.two-factor', [ | |||
'tenant' => Filament::getTenant(), | |||
])); | |||
]))->with('two_factor_redirect_message', __('Your administrator requires you to enable two-factor authentication.')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this customizable?
Example:
->forced(message: __('Some message')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes maybe it's better to let the developer choose which message to show to the user. I'm also not really satisfied with showing the message yet. Weird enough I couldn't show the message in the blade view itself using the session
helper..
This PR is a draft. I'm still trying to figure out how to redirect to the 2FA page.