44
55namespace App \Authenticator ;
66
7- use App \Exception \SsoConsumerAuthNException ;
87use App \Exception \SsoConsumerException ;
98use OneLogin \Saml2 \Auth ;
109use Symfony \Component \HttpFoundation \JsonResponse ;
@@ -27,6 +26,8 @@ public function __construct(
2726 private readonly HttpUtils $ httpUtils ,
2827 private readonly string $ checkPath ,
2928 private readonly Auth $ auth ,
29+ private readonly string $ returnTo ,
30+ private readonly \Psr \Log \LoggerInterface $ logger ,
3031 ) {
3132 }
3233
@@ -43,12 +44,8 @@ public function supports(Request $request): bool|null
4344 public function authenticate (Request $ request ): Passport
4445 {
4546 $ session = $ request ->getSession ();
46- $ authNRequestId = $ session ->get ('AuthNRequestID ' );
47- if (! \is_string ($ authNRequestId )) {
48- throw new SsoConsumerAuthNException ();
49- }
50-
51- $ auth = $ this ->auth ;
47+ $ authNRequestId = $ session ->get ('AuthNRequestID ' , null );
48+ $ auth = $ this ->auth ;
5249 $ auth ->setStrict (false );
5350 $ auth ->processResponse ($ authNRequestId );
5451 $ errors = $ auth ->getErrors ();
@@ -97,11 +94,13 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
9794 /** @inheritDoc */
9895 public function start (Request $ request , AuthenticationException |null $ authException = null )
9996 {
100- $ session = $ request ->getSession ();
101- $ auth = $ this ->auth ;
102- $ url = $ auth ->login (null , [], false , false , true );
97+ $ session = $ request ->getSession ();
98+ $ this ->logger ->debug ('Starting auth ' );
99+ $ auth = $ this ->auth ;
100+ $ url = $ auth ->login ($ this ->returnTo , [], false , false , true );
103101 $ authNRequestId = $ auth ->getLastRequestID ();
104102 $ session ->set ('AuthNRequestID ' , $ authNRequestId );
103+ $ this ->logger ->debug ("Need redirect to $ url " );
105104
106105 return new JsonResponse (['url ' => $ url ], Response::HTTP_UNAUTHORIZED );
107106 }
0 commit comments