4
4
5
5
namespace App \Authenticator ;
6
6
7
- use App \Exception \SsoConsumerAuthNException ;
8
7
use App \Exception \SsoConsumerException ;
9
8
use OneLogin \Saml2 \Auth ;
10
9
use Symfony \Component \HttpFoundation \JsonResponse ;
@@ -27,6 +26,8 @@ public function __construct(
27
26
private readonly HttpUtils $ httpUtils ,
28
27
private readonly string $ checkPath ,
29
28
private readonly Auth $ auth ,
29
+ private readonly string $ returnTo ,
30
+ private readonly \Psr \Log \LoggerInterface $ logger ,
30
31
) {
31
32
}
32
33
@@ -44,10 +45,6 @@ public function authenticate(Request $request): Passport
44
45
{
45
46
$ session = $ request ->getSession ();
46
47
$ authNRequestId = $ session ->get ('AuthNRequestID ' , null );
47
- if (! \is_string ($ authNRequestId )) {
48
- throw new SsoConsumerAuthNException ();
49
- }
50
-
51
48
$ auth = $ this ->auth ;
52
49
$ auth ->setStrict (false );
53
50
$ auth ->processResponse ($ authNRequestId );
@@ -99,10 +96,12 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
99
96
public function start (Request $ request , AuthenticationException |null $ authException = null )
100
97
{
101
98
$ session = $ request ->getSession ();
99
+ $ this ->logger ->error ('Starting auth ' );
102
100
$ auth = $ this ->auth ;
103
- $ url = $ auth ->login (null , [], false , false , true );
101
+ $ url = $ auth ->login ($ this -> returnTo , [], false , false , true );
104
102
$ authNRequestId = $ auth ->getLastRequestID ();
105
103
$ session ->set ('AuthNRequestID ' , $ authNRequestId );
104
+ $ this ->logger ->error ("Need redirect to $ url " );
106
105
107
106
return new JsonResponse (['url ' => $ url ], Response::HTTP_UNAUTHORIZED );
108
107
}
0 commit comments