Skip to content

Commit

Permalink
Move the creation of the LogoutRequest and the LogoutResponse object …
Browse files Browse the repository at this point in the history
…to separate functions
  • Loading branch information
pitbulk committed May 30, 2024
1 parent 6d023e0 commit e15e32e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ Installation

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

Then pull the 3.X.X branch/tag
Then pull the 4.X.X branch/tag

#### Option 2. Download from github ####

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

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

Search for 3.X.X releases
Search for 4.X.X releases

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

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

It is not compatible with PHP5.6 or PHP7.0.
It is not compatible with PHP5.6 or PHP7.0, PHP7.1 or PHP7.2

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


##### OneLogin\Saml2\AuthnRequest - `AuthnRequest.php` #####
Expand Down
41 changes: 36 additions & 5 deletions src/Saml2/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
$this->_errors = array();
$this->_lastError = $this->_lastErrorException = null;
if (isset($_GET['SAMLResponse'])) {
$logoutResponse = new LogoutResponse($this->_settings, $_GET['SAMLResponse']);
$logoutResponse = $this->buildLogoutResponse($this->_settings, $_GET['SAMLResponse']);
$this->_lastResponse = $logoutResponse->getXML();
if (!$logoutResponse->isValid($requestId, $retrieveParametersFromServer)) {
$this->_errors[] = 'invalid_logout_response';
Expand All @@ -300,7 +300,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
}
}
} else if (isset($_GET['SAMLRequest'])) {
$logoutRequest = new LogoutRequest($this->_settings, $_GET['SAMLRequest']);
$logoutRequest = $this->buildLogoutRequest($this->_settings, $_GET['SAMLRequest']);
$this->_lastRequest = $logoutRequest->getXML();
if (!$logoutRequest->isValid($retrieveParametersFromServer)) {
$this->_errors[] = 'invalid_logout_request';
Expand All @@ -316,7 +316,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
}
$inResponseTo = $logoutRequest->id;
$this->_lastMessageId = $logoutRequest->id;
$responseBuilder = new LogoutResponse($this->_settings);
$responseBuilder = $this->buildLogoutResponse($this->_settings);
$responseBuilder->build($inResponseTo);
$this->_lastResponse = $responseBuilder->getXML();

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

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

$this->_lastRequest = $logoutRequest->getXML();
$this->_lastRequestID = $logoutRequest->id;
Expand Down Expand Up @@ -674,11 +674,42 @@ public function getLastRequestID()
*
* @return AuthnRequest The AuthnRequest object
*/
public function buildAuthnRequest($settings, $forceAuthn, $isPassive, $setNameIdPolicy, $nameIdValueReq = null)
public function buildAuthnRequest(Settings $settings, $forceAuthn, $isPassive, $setNameIdPolicy, $nameIdValueReq = null)
{
return new AuthnRequest($settings, $forceAuthn, $isPassive, $setNameIdPolicy, $nameIdValueReq);
}

/**
* Creates an LogoutRequest
*
* @param Settings $settings Settings
* @param string|null $request A UUEncoded Logout Request.
* @param string|null $nameId The NameID that will be set in the LogoutRequest.
* @param string|null $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process).
* @param string|null $nameIdFormat The NameID Format will be set in the LogoutRequest.
* @param string|null $nameIdNameQualifier The NameID NameQualifier will be set in the LogoutRequest.
* @param string|null $nameIdSPNameQualifier The NameID SP NameQualifier will be set in the LogoutRequest.
*/
public function buildLogoutRequest(Settings $settings, $request = null, $nameId = null, $sessionIndex = null, $nameIdFormat = null, $nameIdNameQualifier = null, $nameIdSPNameQualifier = null)
{
return new LogoutRequest($settings, $request, $nameId, $sessionIndex, $nameIdFormat, $nameIdNameQualifier, $nameIdSPNameQualifier);
}

/**
* Constructs a Logout Response object (Initialize params from settings and if provided
* load the Logout Response.
*
* @param Settings $settings Settings.
* @param string|null $response An UUEncoded SAML Logout response from the IdP.
*
* @throws Error
* @throws Exception
*/
public function buildLogoutResponse(Settings $settings, $response = null)
{
return new LogoutResponse($settings, $response);
}

/**
* Generates the Signature for a SAML Request
*
Expand Down

0 comments on commit e15e32e

Please sign in to comment.