OneLogin_Saml2_Auth::processSLO PHP Метод

processSLO() публичный Метод

Process the SAML Logout Response / Logout Request sent by the IdP.
public processSLO ( boolean $keepLocalSession = false, string | null $requestId = null, boolean $retrieveParametersFromServer = false, callable $cbDeleteSession = null, boolean $stay = false ) : string | void
$keepLocalSession boolean When false will destroy the local session, otherwise will keep it
$requestId string | null The ID of the LogoutRequest sent by this SP to the IdP
$retrieveParametersFromServer boolean
$cbDeleteSession callable
$stay boolean True if we want to stay (returns the url string) False to redirect
Результат string | void
    public function processSLO($keepLocalSession = false, $requestId = null, $retrieveParametersFromServer = false, $cbDeleteSession = null, $stay = false)
    {
        $this->_errors = array();
        if (isset($_GET) && isset($_GET['SAMLResponse'])) {
            $logoutResponse = new OneLogin_Saml2_LogoutResponse($this->_settings, $_GET['SAMLResponse']);
            if (!$logoutResponse->isValid($requestId, $retrieveParametersFromServer)) {
                $this->_errors[] = 'invalid_logout_response';
                $this->_errorReason = $logoutResponse->getError();
            } else {
                if ($logoutResponse->getStatus() !== OneLogin_Saml2_Constants::STATUS_SUCCESS) {
                    $this->_errors[] = 'logout_not_success';
                } else {
                    if (!$keepLocalSession) {
                        if ($cbDeleteSession === null) {
                            OneLogin_Saml2_Utils::deleteLocalSession();
                        } else {
                            call_user_func($cbDeleteSession);
                        }
                    }
                }
            }
        } else {
            if (isset($_GET) && isset($_GET['SAMLRequest'])) {
                $logoutRequest = new OneLogin_Saml2_LogoutRequest($this->_settings, $_GET['SAMLRequest']);
                if (!$logoutRequest->isValid($retrieveParametersFromServer)) {
                    $this->_errors[] = 'invalid_logout_request';
                    $this->_errorReason = $logoutRequest->getError();
                } else {
                    if (!$keepLocalSession) {
                        if ($cbDeleteSession === null) {
                            OneLogin_Saml2_Utils::deleteLocalSession();
                        } else {
                            call_user_func($cbDeleteSession);
                        }
                    }
                    $inResponseTo = $logoutRequest->id;
                    $responseBuilder = new OneLogin_Saml2_LogoutResponse($this->_settings);
                    $responseBuilder->build($inResponseTo);
                    $logoutResponse = $responseBuilder->getResponse();
                    $parameters = array('SAMLResponse' => $logoutResponse);
                    if (isset($_GET['RelayState'])) {
                        $parameters['RelayState'] = $_GET['RelayState'];
                    }
                    $security = $this->_settings->getSecurityData();
                    if (isset($security['logoutResponseSigned']) && $security['logoutResponseSigned']) {
                        $signature = $this->buildResponseSignature($logoutResponse, isset($parameters['RelayState']) ? $parameters['RelayState'] : null, $security['signatureAlgorithm']);
                        $parameters['SigAlg'] = $security['signatureAlgorithm'];
                        $parameters['Signature'] = $signature;
                    }
                    return $this->redirectTo($this->getSLOurl(), $parameters, $stay);
                }
            } else {
                $this->_errors[] = 'invalid_binding';
                throw new OneLogin_Saml2_Error('SAML LogoutRequest/LogoutResponse not found. Only supported HTTP_REDIRECT Binding', OneLogin_Saml2_Error::SAML_LOGOUTMESSAGE_NOT_FOUND);
            }
        }
    }

Usage Example

Пример #1
0
                }
                $_SESSION['samlUserdata'] = $auth->getAttributes();
                $_SESSION['samlNameId'] = $auth->getNameId();
                $_SESSION['samlSessionIndex'] = $auth->getSessionIndex();
                unset($_SESSION['AuthNRequestID']);
                if (isset($_POST['RelayState']) && OneLogin_Saml2_Utils::getSelfURL() != $_POST['RelayState']) {
                    $auth->redirectTo($_POST['RelayState']);
                }
            } else {
                if (isset($_GET['sls'])) {
                    if (isset($_SESSION) && isset($_SESSION['LogoutRequestID'])) {
                        $requestID = $_SESSION['LogoutRequestID'];
                    } else {
                        $requestID = null;
                    }
                    $auth->processSLO(false, $requestID);
                    $errors = $auth->getErrors();
                    if (empty($errors)) {
                        print_r('<p>Sucessfully logged out</p>');
                    } else {
                        print_r('<p>' . implode(', ', $errors) . '</p>');
                    }
                }
            }
        }
    }
}
if (isset($_SESSION['samlUserdata'])) {
    if (!empty($_SESSION['samlUserdata'])) {
        $attributes = $_SESSION['samlUserdata'];
        echo 'You have the following attributes:<br>';
All Usage Examples Of OneLogin_Saml2_Auth::processSLO