@@ -109,11 +109,11 @@ class OneLogin_Saml2_Auth
109109 private $ _errors = array ();
110110
111111 /**
112- * Reason of the last error .
112+ * Last error exception object .
113113 *
114- * @var string |null
114+ * @var Exception |null
115115 */
116- private $ _errorReason ;
116+ private $ _lastError ;
117117
118118 /**
119119 * Last AuthNRequest ID or LogoutRequest ID generated by this Service Provider
@@ -188,7 +188,7 @@ public function setStrict($value)
188188 public function processResponse ($ requestId = null )
189189 {
190190 $ this ->_errors = array ();
191- $ this ->_errorReason = null ;
191+ $ this ->_lastError = null ;
192192 if (isset ($ _POST ) && isset ($ _POST ['SAMLResponse ' ])) {
193193 // AuthnResponse -- HTTP_POST Binding
194194 $ response = new OneLogin_Saml2_Response ($ this ->_settings , $ _POST ['SAMLResponse ' ]);
@@ -207,7 +207,7 @@ public function processResponse($requestId = null)
207207 $ this ->_lastAssertionNotOnOrAfter = $ response ->getAssertionNotOnOrAfter ();
208208 } else {
209209 $ this ->_errors [] = 'invalid_response ' ;
210- $ this ->_errorReason = $ response ->getError ();
210+ $ this ->_lastError = $ response ->getError ();
211211 }
212212 } else {
213213 $ this ->_errors [] = 'invalid_binding ' ;
@@ -234,13 +234,13 @@ public function processResponse($requestId = null)
234234 public function processSLO ($ keepLocalSession = false , $ requestId = null , $ retrieveParametersFromServer = false , $ cbDeleteSession = null , $ stay = false )
235235 {
236236 $ this ->_errors = array ();
237- $ this ->_errorReason = null ;
237+ $ this ->_lastError = null ;
238238 if (isset ($ _GET ) && isset ($ _GET ['SAMLResponse ' ])) {
239239 $ logoutResponse = new OneLogin_Saml2_LogoutResponse ($ this ->_settings , $ _GET ['SAMLResponse ' ]);
240240 $ this ->_lastResponse = $ logoutResponse ->getXML ();
241241 if (!$ logoutResponse ->isValid ($ requestId , $ retrieveParametersFromServer )) {
242242 $ this ->_errors [] = 'invalid_logout_response ' ;
243- $ this ->_errorReason = $ logoutResponse ->getError ();
243+ $ this ->_lastError = $ logoutResponse ->getError ();
244244 } else if ($ logoutResponse ->getStatus () !== OneLogin_Saml2_Constants::STATUS_SUCCESS ) {
245245 $ this ->_errors [] = 'logout_not_success ' ;
246246 } else {
@@ -258,7 +258,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
258258 $ this ->_lastRequest = $ logoutRequest ->getXML ();
259259 if (!$ logoutRequest ->isValid ($ retrieveParametersFromServer )) {
260260 $ this ->_errors [] = 'invalid_logout_request ' ;
261- $ this ->_errorReason = $ logoutRequest ->getError ();
261+ $ this ->_lastError = $ logoutRequest ->getError ();
262262 } else {
263263 if (!$ keepLocalSession ) {
264264 if ($ cbDeleteSession === null ) {
@@ -406,6 +406,17 @@ public function getErrors()
406406 * @return string|null Error reason
407407 */
408408 public function getLastErrorReason ()
409+ {
410+ return htmlentities ($ this ->_lastError ->getMessage ());
411+ }
412+
413+
414+ /**
415+ * Returns the last error
416+ *
417+ * @return Exception Error
418+ */
419+ public function getLastError ()
409420 {
410421 return $ this ->_errorReason ;
411422 }
0 commit comments