From d8ece093d5440ccec1d4145ae7a1faad95e8d84f Mon Sep 17 00:00:00 2001 From: Ian Littman Date: Sat, 4 Feb 2017 14:48:40 -0500 Subject: [PATCH] Add hasRedirect() method for OAuthServerException Resolves #694. --- src/Exception/OAuthServerException.php | 13 +++++++++++++ tests/ExceptionTest.php | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/ExceptionTest.php diff --git a/src/Exception/OAuthServerException.php b/src/Exception/OAuthServerException.php index 6ffa0fb1..30007be7 100644 --- a/src/Exception/OAuthServerException.php +++ b/src/Exception/OAuthServerException.php @@ -273,6 +273,19 @@ class OAuthServerException extends \Exception return $headers; } + /** + * Returns whether the exception includes a redirect, since + * getHttpStatusCode() doesn't return a 302 when there's a + * redirect enabled. This helps when you want to override local + * error pages but want to let redirects through. + * + * @return bool + */ + public function hasRedirect() + { + return $this->redirectUri !== null; + } + /** * Returns the HTTP status code to send when the exceptions is output. * diff --git a/tests/ExceptionTest.php b/tests/ExceptionTest.php new file mode 100644 index 00000000..2d77118e --- /dev/null +++ b/tests/ExceptionTest.php @@ -0,0 +1,17 @@ +assertFalse($exceptionWithoutRedirect->hasRedirect()); + + $exceptionWithRedirect = OAuthServerException::accessDenied('some hint', 'https://example.com/error'); + $this->assertTrue($exceptionWithRedirect->hasRedirect()); + } +} \ No newline at end of file