mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-27 01:02:12 +05:30
Merge pull request #703 from iansltx/exception-has-redirect
Add hasRedirect() method for OAuthServerException Fixes #694
This commit is contained in:
commit
519543e925
@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Function `hasRedirect()` added to `OAuthServerException` (PR #703)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Catch and handle `BadMethodCallException` from the `verify()` method of the JWT token in the `validateAuthorization` method (PR #904)
|
- Catch and handle `BadMethodCallException` from the `verify()` method of the JWT token in the `validateAuthorization` method (PR #904)
|
||||||
|
|
||||||
|
@ -303,6 +303,21 @@ class OAuthServerException extends \Exception
|
|||||||
return $headers;
|
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.
|
* Returns the HTTP status code to send when the exceptions is output.
|
||||||
*
|
*
|
||||||
|
23
tests/Exception/OAuthServerExceptionTest.php
Normal file
23
tests/Exception/OAuthServerExceptionTest.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace LeagueTests\Exception;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class OAuthServerExceptionTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testHasRedirect()
|
||||||
|
{
|
||||||
|
$exceptionWithRedirect = OAuthServerException::accessDenied('some hint', 'https://example.com/error');
|
||||||
|
|
||||||
|
$this->assertTrue($exceptionWithRedirect->hasRedirect());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDoesNotHaveRedirect()
|
||||||
|
{
|
||||||
|
$exceptionWithoutRedirect = OAuthServerException::accessDenied('Some hint');
|
||||||
|
|
||||||
|
$this->assertFalse($exceptionWithoutRedirect->hasRedirect());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user