diff --git a/src/Spid/Saml.php b/src/Spid/Saml.php index 1fb7d62..5b0ac15 100644 --- a/src/Spid/Saml.php +++ b/src/Spid/Saml.php @@ -14,6 +14,7 @@ class Saml implements SAMLInterface public $settings; private $idps = []; // contains filename -> Idp object array private $session; // Session object + private $response; public function __construct(array $settings, $autoconfigure = true) { @@ -207,8 +208,8 @@ public function isAuthenticated() : bool return false; } $idp = $this->loadIdpFromFile($selectedIdp); - $response = new BaseResponse($this); - if (!empty($idp) && !$response->validate($idp->metadata['idpCertValue'])) { + $this->response = new BaseResponse($this); + if (!empty($idp) && !$this->response->validate($idp->metadata['idpCertValue'])) { return false; } if (isset($_SESSION) && isset($_SESSION['inResponseTo'])) { @@ -225,6 +226,11 @@ public function isAuthenticated() : bool return false; } + public function getResponse() + { + return $this->response; + } + public function logout(int $slo, string $redirectTo = null, $shouldRedirect = true) { $args = func_get_args(); diff --git a/src/Spid/Saml/Idp.php b/src/Spid/Saml/Idp.php index a4b0327..80fc919 100644 --- a/src/Spid/Saml/Idp.php +++ b/src/Spid/Saml/Idp.php @@ -17,6 +17,7 @@ class Idp implements IdpInterface public $attrID; public $level = 1; public $session; + private $authn; public function __construct($sp) { @@ -87,11 +88,11 @@ public function authnRequest($ass, $attr, $binding, $level = 1, $redirectTo = nu $this->attrID = $attr; $this->level = $level; - $authn = new AuthnRequest($this); + $this->authn = new AuthnRequest($this); $url = $binding == Settings::BINDING_REDIRECT ? - $authn->redirectUrl($redirectTo) : - $authn->httpPost($redirectTo); - $_SESSION['RequestID'] = $authn->id; + $this->authn->redirectUrl($redirectTo) : + $this->authn->httpPost($redirectTo); + $_SESSION['RequestID'] = $this->authn->id; $_SESSION['idpName'] = $this->idpFileName; $_SESSION['idpEntityId'] = $this->metadata['idpEntityId']; $_SESSION['acsUrl'] = $this->sp->settings['sp_assertionconsumerservice'][$ass]; @@ -106,6 +107,11 @@ public function authnRequest($ass, $attr, $binding, $level = 1, $redirectTo = nu exit(""); } + public function getAuthn() + { + return $this->authn; + } + public function logoutRequest(Session $session, $slo, $binding, $redirectTo = null, $shouldRedirect = true) : string { $this->session = $session; diff --git a/src/Spid/Saml/In/BaseResponse.php b/src/Spid/Saml/In/BaseResponse.php index e8fb0ff..d8b144b 100644 --- a/src/Spid/Saml/In/BaseResponse.php +++ b/src/Spid/Saml/In/BaseResponse.php @@ -102,4 +102,13 @@ public function validate($cert) : bool } return $this->response->validate($this->xml, $hasAssertion); } + + public function getXml() + { + if ($this->xml) { + return $this->xml->getElementsByTagName('Response')->item(0); + } else { + return ''; + } + } }