diff --git a/CHANGELOG.md b/CHANGELOG.md index d657b746..3d36285c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added +- Function `hasRedirect()` added to `OAuthServerException` (PR #703) + ### Fixed - Catch and handle `BadMethodCallException` from the `verify()` method of the JWT token in the `validateAuthorization` method (PR #904) diff --git a/src/Exception/OAuthServerException.php b/src/Exception/OAuthServerException.php index a62d961d..2c7bc28b 100644 --- a/src/Exception/OAuthServerException.php +++ b/src/Exception/OAuthServerException.php @@ -303,6 +303,21 @@ class OAuthServerException extends \Exception return $headers; } + /** + * Check if the exception has an associated redirect URI. + * + * 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/Exception/OAuthServerExceptionTest.php b/tests/Exception/OAuthServerExceptionTest.php new file mode 100644 index 00000000..976362e3 --- /dev/null +++ b/tests/Exception/OAuthServerExceptionTest.php @@ -0,0 +1,23 @@ +assertTrue($exceptionWithRedirect->hasRedirect()); + } + + public function testDoesNotHaveRedirect() + { + $exceptionWithoutRedirect = OAuthServerException::accessDenied('Some hint'); + + $this->assertFalse($exceptionWithoutRedirect->hasRedirect()); + } +}