@@ -165,24 +165,18 @@ public function login(
165165 $ returnToUrl = $ this ->getReturnUrl ($ request , $ sessionTicket );
166166
167167 // renew=true and gateway=true are incompatible → prefer interactive login (disable passive)
168- // Protocol: gateway and renew are incompatible; behavior is undefined if both are set.
169- // OPTIONAL (implementation policy): Prefer renew (interactive, non-passive) by disabling gateway.
170- // OPTIONAL alternative: Reject with 400 to signal incompatible parameters.
171168 if ($ gateway && $ forceAuthn ) {
172169 $ gateway = false ;
173170 }
174171
175- // Handle passive authentication
172+ // Handle passive authentication if service url defined
176173 // Protocol (gateway set): CAS MUST NOT prompt for credentials during this branch.
177- if ($ gateway && !$ this ->authSource ->isAuthenticated () && !$ requestForceAuthenticate ) {
178- $ response = $ this ->handleUnauthenticatedGateway (
174+ if ($ serviceUrl && $ gateway && !$ this ->authSource ->isAuthenticated () && !$ requestForceAuthenticate ) {
175+ return $ this ->handleUnauthenticatedGateway (
179176 $ serviceUrl ,
180177 $ entityId ,
181178 $ returnToUrl ,
182179 );
183- if ($ response !== null ) {
184- return $ response ;
185- }
186180 }
187181
188182 // Handle interactive authentication
@@ -254,9 +248,6 @@ public function login(
254248 }
255249
256250 // User has SSO or non-interactive auth succeeded → redirect/POST to service WITH a ticket
257- // Protocol: With gateway and a successful non-interactive auth (or existing SSO), CAS MAY redirect to the
258- // service and append a ticket.
259- // Protocol: CAS MAY interpose an advisory page indicating that authentication took place.
260251 $ ticketName = $ this ->calculateTicketName ($ service );
261252 $ this ->postAuthUrlParameters [$ ticketName ] = $ serviceTicket ['id ' ];
262253
@@ -502,20 +493,19 @@ private function handleInteractiveAuthenticate(
502493 * - null to indicate: proceed with interactive login (non-passive).
503494 */
504495 private function handleUnauthenticatedGateway (
505- ? string $ serviceUrl ,
496+ string $ serviceUrl ,
506497 ?string $ entityId ,
507498 string $ returnToUrl ,
508- ): ? RunnableResponse {
499+ ): RunnableResponse {
509500 $ passiveAllowed = $ this ->casConfig ->getOptionalBoolean ('enable_passive_mode ' , false );
510501
511- // Passive mode is not enabled by configuration.
512- // Protocol: If non-interactive auth cannot be established:
513- // - If service is present, CAS MUST redirect to the service URL WITHOUT a ticket parameter.
514- // - If service is absent, behavior is undefined; it is RECOMMENDED
515- // to request credentials as if neither parameter was specified.
502+ // Passive mode is not enabled by configuration
503+ // CAS MUST redirect to the service URL WITHOUT a ticket parameter.
516504 if (!$ passiveAllowed ) {
517- // Passive attempt already performed and still not authenticated.
518- return $ this ->gatewayFallback ($ serviceUrl );
505+ return new RunnableResponse (
506+ [$ this ->httpUtils , 'redirectTrustedURL ' ],
507+ [$ serviceUrl , []],
508+ );
519509 }
520510
521511 // Passive mode enabled: attempt a passive (non-interactive) authentication.
@@ -566,26 +556,4 @@ private function handleAuthenticate(
566556 [$ params ],
567557 );
568558 }
569-
570- /**
571- * Gateway fallback per CAS gateway semantics:
572- * - Protocol (MUST): If a service is provided and non-interactive auth cannot be established,
573- * redirect to the service WITHOUT any CAS parameters (no "ticket").
574- * - Protocol (Undefined, RECOMMENDED): If no service is provided, proceed with interactive login
575- * (request credentials).
576- * @param string|null $serviceUrl
577- * @return RunnableResponse|null
578- */
579- private function gatewayFallback (?string $ serviceUrl ): ?RunnableResponse
580- {
581- if ($ serviceUrl !== null ) {
582- // MUST: Redirect to service WITHOUT a "ticket" parameter (and without other CAS params).
583- return new RunnableResponse (
584- [$ this ->httpUtils , 'redirectTrustedURL ' ],
585- [$ serviceUrl , []],
586- );
587- }
588- // RECOMMENDED: No service specified; proceed with interactive login as if neither parameter was specified.
589- return null ;
590- }
591559}
0 commit comments