scheb / two-factor-bundle

[ABANDONED] Two-factor authentication for Symfony 2 & 3 applications 🔐. Please use the newer versions from https://github.com/scheb/2fa.
https://github.com/scheb/2fa
MIT License
385 stars 111 forks source link

2fa Form Response type is plain text #265

Closed cjgordon closed 4 years ago

cjgordon commented 4 years ago

Bundle version: 4.12.0 Symfony version: 4.4.3 **Authenticator***: Google

Description When I login the two factor authentication form is shown - however it is rendered by the browser as plain text with no DOM element etc - just the markup displayed as a string. This happens with default form template and my own custom one.

I have been able to resolve by adding the following to DefaultTwoFactorFormRenderer.php:

    public function renderForm(Request $request, array $templateVars): Response
    {
        $content = $this->twigEnvironment->render($this->template, $templateVars);
        $response = new Response();
        $response->setContent($content);
        $response->headers->set('Content-Type', 'text/html');

        return $response;
    }

Note header added to explicitly set content type. This solution works for me but just flagging it here as this may mean I have miss configured something else in the bundle or there is a bug.

Additional Context
I have just upgrade from Symfony 3x and Two Factor 2x and have completely reinstalled two-factor-bundle following the guide.

cjgordon commented 4 years ago

I was just looking through my git history to commit and realised I added the 2fa routes to the wrong bundle configuration - I added it to my REST API bundle instead of main application bundles routes.

Moving them to correct routing config resolves issue.