Skip to content

Commit

Permalink
fix: update start method
Browse files Browse the repository at this point in the history
Do not use a redirect response or else some informations are lost.
  • Loading branch information
drupol committed Mar 1, 2023
1 parent b7c5f89 commit f3ebf70
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/Security/CasAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
use EcPhp\CasLib\Utils\Uri;
use InvalidArgumentException;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\UserInterface;
Expand All @@ -36,22 +36,22 @@ final class CasAuthenticator extends AbstractAuthenticator implements Authentica
{
private CasInterface $cas;

private HttpMessageFactoryInterface $httpMessageFactory;
private HttpFoundationFactoryInterface $httpFoundationFactory;

private UrlGeneratorInterface $urlGenerator;
private HttpMessageFactoryInterface $httpMessageFactory;

private CasUserProviderInterface $userProvider;

public function __construct(
CasInterface $cas,
HttpMessageFactoryInterface $httpMessageFactory,
HttpFoundationFactoryInterface $httpFoundationFactory,
CasUserProviderInterface $userProvider,
UrlGeneratorInterface $urlGenerator
) {
$this->cas = $cas;
$this->httpFoundationFactory = $httpFoundationFactory;
$this->httpMessageFactory = $httpMessageFactory;
$this->userProvider = $userProvider;
$this->urlGenerator = $urlGenerator;
}

public function authenticate(Request $request): Passport
Expand Down Expand Up @@ -124,13 +124,13 @@ public function start(Request $request, ?AuthenticationException $authException
);
}

return new RedirectResponse(
$this
->urlGenerator
->generate(
'cas_bundle_login',
)
);
// Here we could also forward the request to `cas_bundle_login`.
// Maybe this is something we should do at some point.
$response = $this->cas->login($request->query->all());

return null === $response ?
new RedirectResponse('/') :
$this->httpFoundationFactory->createResponse($response);
}

public function supports(Request $request): bool
Expand Down

0 comments on commit f3ebf70

Please sign in to comment.