From d8ece093d5440ccec1d4145ae7a1faad95e8d84f Mon Sep 17 00:00:00 2001 From: Ian Littman Date: Sat, 4 Feb 2017 14:48:40 -0500 Subject: [PATCH 1/4] 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 From 68c9fbd83c2fa85f37ef98fcfe30d1c23edaf228 Mon Sep 17 00:00:00 2001 From: Andrew Millington Date: Fri, 25 May 2018 09:53:59 +0100 Subject: [PATCH 2/4] Add a summary for hasRedirect function --- src/Exception/OAuthServerException.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Exception/OAuthServerException.php b/src/Exception/OAuthServerException.php index 4bf3cb33..2c7bc28b 100644 --- a/src/Exception/OAuthServerException.php +++ b/src/Exception/OAuthServerException.php @@ -304,6 +304,8 @@ class OAuthServerException extends \Exception } /** + * 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 From e4a7fea834bd3b0af06bd18e9eba0dbf41ac1c97 Mon Sep 17 00:00:00 2001 From: Andrew Millington Date: Fri, 25 May 2018 10:00:21 +0100 Subject: [PATCH 3/4] Move OAuthServerExceptionTest to appropriate folder --- .../OAuthServerExceptionTest.php} | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) rename tests/{ExceptionTest.php => Exception/OAuthServerExceptionTest.php} (72%) diff --git a/tests/ExceptionTest.php b/tests/Exception/OAuthServerExceptionTest.php similarity index 72% rename from tests/ExceptionTest.php rename to tests/Exception/OAuthServerExceptionTest.php index 2d77118e..976362e3 100644 --- a/tests/ExceptionTest.php +++ b/tests/Exception/OAuthServerExceptionTest.php @@ -1,17 +1,23 @@ assertFalse($exceptionWithoutRedirect->hasRedirect()); - $exceptionWithRedirect = OAuthServerException::accessDenied('some hint', 'https://example.com/error'); + $this->assertTrue($exceptionWithRedirect->hasRedirect()); } -} \ No newline at end of file + + public function testDoesNotHaveRedirect() + { + $exceptionWithoutRedirect = OAuthServerException::accessDenied('Some hint'); + + $this->assertFalse($exceptionWithoutRedirect->hasRedirect()); + } +} From 3614f8bd7c385f642e003cd9190595b4642cf31d Mon Sep 17 00:00:00 2001 From: Andrew Millington Date: Fri, 25 May 2018 10:03:58 +0100 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) 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)