Skip to content

Commit

Permalink
Add logger to auzure login
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjorn Van Acker committed Apr 30, 2024
1 parent 301fd0c commit d2fe1bd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Security/AzureAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SumoCoders\OAuthBundle\Security;

use Psr\Log\LoggerInterface;
use SumoCoders\OAuthBundle\Entity\User;
use SumoCoders\OAuthBundle\Event\LoginEvent;
use SumoCoders\OAuthBundle\Repository\UserRepository;
Expand All @@ -27,6 +28,7 @@ class AzureAuthenticator extends OAuth2Authenticator implements AuthenticationEn
const ORIGIN = 'azure';

public function __construct(
private readonly LoggerInterface $logger,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly RequestStack $requestStack,
private readonly TranslatorInterface $translator,
Expand Down Expand Up @@ -95,13 +97,17 @@ public function authenticate(Request $request): Passport

public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
{
$this->logger->info('User successfully authenticated', ['user' => $token->getUser()]);

return new RedirectResponse(
$this->router->generate($this->successRoute)
);
}

public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
{
$this->logger->error($exception->getMessage(), ['exception' => $exception]);

$this->requestStack->getSession()->getFlashBag()->add(
'error',
$this->translator->trans('login.error', [], 'azure')
Expand Down

0 comments on commit d2fe1bd

Please sign in to comment.