Skip to content

Commit e15e32e

Browse files
committed
Move the creation of the LogoutRequest and the LogoutResponse object to separate functions
1 parent 6d023e0 commit e15e32e

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ Installation
8484

8585
git clone [email protected]:SAML-Toolkits/php-saml.git
8686

87-
Then pull the 3.X.X branch/tag
87+
Then pull the 4.X.X branch/tag
8888

8989
#### Option 2. Download from github ####
9090

9191
The toolkit is hosted on github. You can download it from:
9292

9393
* https://github.com/SAML-Toolkits/php-saml/releases
9494

95-
Search for 3.X.X releases
95+
Search for 4.X.X releases
9696

9797
Copy the core of the library inside the php application. (each application has its
9898
structure so take your time to locate the PHP SAML toolkit in the best place).
@@ -124,7 +124,7 @@ Compatibility
124124

125125
This 4.X.X supports PHP >=7.3 .
126126

127-
It is not compatible with PHP5.6 or PHP7.0.
127+
It is not compatible with PHP5.6 or PHP7.0, PHP7.1 or PHP7.2
128128

129129
Namespaces
130130
----------
@@ -1257,6 +1257,9 @@ Main class of SAML PHP Toolkit
12571257
* `getLastRequestID` - Gets the ID of the last AuthNRequest or LogoutRequest generated by the Service Provider.
12581258
* `getLastRequestXML` - Returns the most recently-constructed/processed XML SAML request (AuthNRequest, LogoutRequest)
12591259
* `getLastResponseXML` - Returns the most recently-constructed/processed XML SAML response (SAMLResponse, LogoutResponse). If the SAMLResponse had an encrypted assertion, decrypts it.
1260+
* `buildAuthnRequest` - Creates an AuthnRequest
1261+
* `buildLogoutRequest` - Creates an LogoutRequest
1262+
* `buildLogoutResponse` - Constructs a Logout Response object (Initialize params from settings and if provided load the Logout Response).
12601263

12611264

12621265
##### OneLogin\Saml2\AuthnRequest - `AuthnRequest.php` #####

src/Saml2/Auth.php

+36-5
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
280280
$this->_errors = array();
281281
$this->_lastError = $this->_lastErrorException = null;
282282
if (isset($_GET['SAMLResponse'])) {
283-
$logoutResponse = new LogoutResponse($this->_settings, $_GET['SAMLResponse']);
283+
$logoutResponse = $this->buildLogoutResponse($this->_settings, $_GET['SAMLResponse']);
284284
$this->_lastResponse = $logoutResponse->getXML();
285285
if (!$logoutResponse->isValid($requestId, $retrieveParametersFromServer)) {
286286
$this->_errors[] = 'invalid_logout_response';
@@ -300,7 +300,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
300300
}
301301
}
302302
} else if (isset($_GET['SAMLRequest'])) {
303-
$logoutRequest = new LogoutRequest($this->_settings, $_GET['SAMLRequest']);
303+
$logoutRequest = $this->buildLogoutRequest($this->_settings, $_GET['SAMLRequest']);
304304
$this->_lastRequest = $logoutRequest->getXML();
305305
if (!$logoutRequest->isValid($retrieveParametersFromServer)) {
306306
$this->_errors[] = 'invalid_logout_request';
@@ -316,7 +316,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
316316
}
317317
$inResponseTo = $logoutRequest->id;
318318
$this->_lastMessageId = $logoutRequest->id;
319-
$responseBuilder = new LogoutResponse($this->_settings);
319+
$responseBuilder = $this->buildLogoutResponse($this->_settings);
320320
$responseBuilder->build($inResponseTo);
321321
$this->_lastResponse = $responseBuilder->getXML();
322322

@@ -598,7 +598,7 @@ public function logout($returnTo = null, array $parameters = array(), $nameId =
598598
$nameIdFormat = $this->_nameidFormat;
599599
}
600600

601-
$logoutRequest = new LogoutRequest($this->_settings, null, $nameId, $sessionIndex, $nameIdFormat, $nameIdNameQualifier, $nameIdSPNameQualifier);
601+
$logoutRequest = $this->buildLogoutRequest($this->_settings, null, $nameId, $sessionIndex, $nameIdFormat, $nameIdNameQualifier, $nameIdSPNameQualifier);
602602

603603
$this->_lastRequest = $logoutRequest->getXML();
604604
$this->_lastRequestID = $logoutRequest->id;
@@ -674,11 +674,42 @@ public function getLastRequestID()
674674
*
675675
* @return AuthnRequest The AuthnRequest object
676676
*/
677-
public function buildAuthnRequest($settings, $forceAuthn, $isPassive, $setNameIdPolicy, $nameIdValueReq = null)
677+
public function buildAuthnRequest(Settings $settings, $forceAuthn, $isPassive, $setNameIdPolicy, $nameIdValueReq = null)
678678
{
679679
return new AuthnRequest($settings, $forceAuthn, $isPassive, $setNameIdPolicy, $nameIdValueReq);
680680
}
681681

682+
/**
683+
* Creates an LogoutRequest
684+
*
685+
* @param Settings $settings Settings
686+
* @param string|null $request A UUEncoded Logout Request.
687+
* @param string|null $nameId The NameID that will be set in the LogoutRequest.
688+
* @param string|null $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process).
689+
* @param string|null $nameIdFormat The NameID Format will be set in the LogoutRequest.
690+
* @param string|null $nameIdNameQualifier The NameID NameQualifier will be set in the LogoutRequest.
691+
* @param string|null $nameIdSPNameQualifier The NameID SP NameQualifier will be set in the LogoutRequest.
692+
*/
693+
public function buildLogoutRequest(Settings $settings, $request = null, $nameId = null, $sessionIndex = null, $nameIdFormat = null, $nameIdNameQualifier = null, $nameIdSPNameQualifier = null)
694+
{
695+
return new LogoutRequest($settings, $request, $nameId, $sessionIndex, $nameIdFormat, $nameIdNameQualifier, $nameIdSPNameQualifier);
696+
}
697+
698+
/**
699+
* Constructs a Logout Response object (Initialize params from settings and if provided
700+
* load the Logout Response.
701+
*
702+
* @param Settings $settings Settings.
703+
* @param string|null $response An UUEncoded SAML Logout response from the IdP.
704+
*
705+
* @throws Error
706+
* @throws Exception
707+
*/
708+
public function buildLogoutResponse(Settings $settings, $response = null)
709+
{
710+
return new LogoutResponse($settings, $response);
711+
}
712+
682713
/**
683714
* Generates the Signature for a SAML Request
684715
*

0 commit comments

Comments
 (0)