22/**
33 * This file is part of php-saml.
44 *
5- * (c) OneLogin Inc
6- *
75 * For the full copyright and license information, please view the LICENSE
86 * file that was distributed with this source code.
97 *
108 * @package OneLogin
11- * @author OneLogin Inc <saml-info@onelogin .com>
12- * @license MIT https://github.com/onelogin /php-saml/blob/master/LICENSE
13- * @link https://github.com/onelogin /php-saml
9+ * @author Sixto Martin <sixto.martin.garcia@gmail .com>
10+ * @license MIT https://github.com/SAML-Toolkits /php-saml/blob/master/LICENSE
11+ * @link https://github.com/SAML-Toolkits /php-saml
1412 */
1513
1614namespace OneLogin \Saml2 ;
2018use Exception ;
2119
2220/**
23- * Main class of OneLogin's PHP Toolkit
21+ * Main class of SAML PHP Toolkit
2422 */
2523class Auth
2624{
@@ -167,14 +165,15 @@ class Auth
167165 /**
168166 * Initializes the SP SAML instance.
169167 *
170- * @param array|null $settings Setting data
168+ * @param array|null $settings Setting data
169+ * @param bool $spValidationOnly Validate or not the IdP data
171170 *
172171 * @throws Exception
173172 * @throws Error
174173 */
175- public function __construct (array $ settings = null )
174+ public function __construct (array $ settings = null , $ spValidationOnly = false )
176175 {
177- $ this ->_settings = new Settings ($ settings );
176+ $ this ->_settings = new Settings ($ settings, $ spValidationOnly );
178177 }
179178
180179 /**
@@ -271,6 +270,7 @@ public function processResponse($requestId = null)
271270 * @param bool $stay True if we want to stay (returns the url string) False to redirect
272271 *
273272 * @return string|null
273+ * @phpstan-return ($stay is true ? string : never)
274274 *
275275 * @throws Error
276276 */
@@ -279,7 +279,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
279279 $ this ->_errors = array ();
280280 $ this ->_lastError = $ this ->_lastErrorException = null ;
281281 if (isset ($ _GET ['SAMLResponse ' ])) {
282- $ logoutResponse = new LogoutResponse ($ this ->_settings , $ _GET ['SAMLResponse ' ]);
282+ $ logoutResponse = $ this -> buildLogoutResponse ($ this ->_settings , $ _GET ['SAMLResponse ' ]);
283283 $ this ->_lastResponse = $ logoutResponse ->getXML ();
284284 if (!$ logoutResponse ->isValid ($ requestId , $ retrieveParametersFromServer )) {
285285 $ this ->_errors [] = 'invalid_logout_response ' ;
@@ -299,7 +299,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
299299 }
300300 }
301301 } else if (isset ($ _GET ['SAMLRequest ' ])) {
302- $ logoutRequest = new LogoutRequest ($ this ->_settings , $ _GET ['SAMLRequest ' ]);
302+ $ logoutRequest = $ this -> buildLogoutRequest ($ this ->_settings , $ _GET ['SAMLRequest ' ]);
303303 $ this ->_lastRequest = $ logoutRequest ->getXML ();
304304 if (!$ logoutRequest ->isValid ($ retrieveParametersFromServer )) {
305305 $ this ->_errors [] = 'invalid_logout_request ' ;
@@ -315,7 +315,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
315315 }
316316 $ inResponseTo = $ logoutRequest ->id ;
317317 $ this ->_lastMessageId = $ logoutRequest ->id ;
318- $ responseBuilder = new LogoutResponse ($ this ->_settings );
318+ $ responseBuilder = $ this -> buildLogoutResponse ($ this ->_settings );
319319 $ responseBuilder ->build ($ inResponseTo );
320320 $ this ->_lastResponse = $ responseBuilder ->getXML ();
321321
@@ -353,6 +353,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
353353 * @param bool $stay True if we want to stay (returns the url string) False to redirect
354354 *
355355 * @return string|null
356+ * @phpstan-return ($stay is true ? string : never)
356357 */
357358 public function redirectTo ($ url = '' , array $ parameters = array (), $ stay = false )
358359 {
@@ -534,6 +535,7 @@ public function getAttributeWithFriendlyName($friendlyName)
534535 * @param string $nameIdValueReq Indicates to the IdP the subject that should be authenticated
535536 *
536537 * @return string|null If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters
538+ * @phpstan-return ($stay is true ? string : never)
537539 *
538540 * @throws Error
539541 */
@@ -574,6 +576,7 @@ public function login($returnTo = null, array $parameters = array(), $forceAuthn
574576 * @param string|null $nameIdNameQualifier The NameID NameQualifier will be set in the LogoutRequest.
575577 *
576578 * @return string|null If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters
579+ * @phpstan-return ($stay is true ? string : never)
577580 *
578581 * @throws Error
579582 */
@@ -594,7 +597,7 @@ public function logout($returnTo = null, array $parameters = array(), $nameId =
594597 $ nameIdFormat = $ this ->_nameidFormat ;
595598 }
596599
597- $ logoutRequest = new LogoutRequest ($ this ->_settings , null , $ nameId , $ sessionIndex , $ nameIdFormat , $ nameIdNameQualifier , $ nameIdSPNameQualifier );
600+ $ logoutRequest = $ this -> buildLogoutRequest ($ this ->_settings , null , $ nameId , $ sessionIndex , $ nameIdFormat , $ nameIdNameQualifier , $ nameIdSPNameQualifier );
598601
599602 $ this ->_lastRequest = $ logoutRequest ->getXML ();
600603 $ this ->_lastRequestID = $ logoutRequest ->id ;
@@ -670,11 +673,42 @@ public function getLastRequestID()
670673 *
671674 * @return AuthnRequest The AuthnRequest object
672675 */
673- public function buildAuthnRequest ($ settings , $ forceAuthn , $ isPassive , $ setNameIdPolicy , $ nameIdValueReq = null )
676+ public function buildAuthnRequest (Settings $ settings , $ forceAuthn , $ isPassive , $ setNameIdPolicy , $ nameIdValueReq = null )
674677 {
675678 return new AuthnRequest ($ settings , $ forceAuthn , $ isPassive , $ setNameIdPolicy , $ nameIdValueReq );
676679 }
677680
681+ /**
682+ * Creates an LogoutRequest
683+ *
684+ * @param Settings $settings Settings
685+ * @param string|null $request A UUEncoded Logout Request.
686+ * @param string|null $nameId The NameID that will be set in the LogoutRequest.
687+ * @param string|null $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process).
688+ * @param string|null $nameIdFormat The NameID Format will be set in the LogoutRequest.
689+ * @param string|null $nameIdNameQualifier The NameID NameQualifier will be set in the LogoutRequest.
690+ * @param string|null $nameIdSPNameQualifier The NameID SP NameQualifier will be set in the LogoutRequest.
691+ */
692+ public function buildLogoutRequest (Settings $ settings , $ request = null , $ nameId = null , $ sessionIndex = null , $ nameIdFormat = null , $ nameIdNameQualifier = null , $ nameIdSPNameQualifier = null )
693+ {
694+ return new LogoutRequest ($ settings , $ request , $ nameId , $ sessionIndex , $ nameIdFormat , $ nameIdNameQualifier , $ nameIdSPNameQualifier );
695+ }
696+
697+ /**
698+ * Constructs a Logout Response object (Initialize params from settings and if provided
699+ * load the Logout Response.
700+ *
701+ * @param Settings $settings Settings.
702+ * @param string|null $response An UUEncoded SAML Logout response from the IdP.
703+ *
704+ * @throws Error
705+ * @throws Exception
706+ */
707+ public function buildLogoutResponse (Settings $ settings , $ response = null )
708+ {
709+ return new LogoutResponse ($ settings , $ response );
710+ }
711+
678712 /**
679713 * Generates the Signature for a SAML Request
680714 *
0 commit comments