jeffgreco13 / filament-breezy

MIT License
694 stars 128 forks source link

Impersonation (2FA Codes) #277

Open rmclain opened 9 months ago

rmclain commented 9 months ago

When using joseph-szobody-impersonate plugin, we are able to login as the user but then get prompted for the 2-Factor code if one is set.

Bogardo commented 9 months ago

@rmclain, if you're still experiencing this issue. Your user model likely already includes the TwoFactorAuthenticatable trait, which contains the following method:

public function hasValidTwoFactorSession(): bool
{
    return $this->breezySession?->is_valid ?? false;
}

I solved this for now by overriding this method in my User model with the following:

public function hasValidTwoFactorSession(): bool
{
    /** @var \Lab404\Impersonate\Services\ImpersonateManager $impersonateManager */
    $impersonateManager = app('impersonate');

    if ($impersonateManager->isImpersonating()) {
        return true;
    }

    return $this->breezySession?->is_valid ?? false;
}

However, be aware that the isImpersonating() method only checks for the existence of the session key. This approach suits my specific use case, but ensure it aligns with your (security) requirements as well.