Skip to content

[13.x] Fix register a custom rendering closure for OAuthServerException #1763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
"ext-json": "*",
"ext-openssl": "*",
"firebase/php-jwt": "^6.4",
"illuminate/auth": "^10.0|^11.0",
"illuminate/console": "^10.0|^11.0",
"illuminate/container": "^10.0|^11.0",
"illuminate/contracts": "^10.0|^11.0",
"illuminate/cookie": "^10.0|^11.0",
"illuminate/database": "^10.0|^11.0",
"illuminate/encryption": "^10.0|^11.0",
"illuminate/http": "^10.0|^11.0",
"illuminate/support": "^10.0|^11.0",
"illuminate/auth": "^10.48.15|^11.14",
"illuminate/console": "^10.48.15|^11.14",
"illuminate/container": "^10.48.15|^11.14",
"illuminate/contracts": "^10.48.15|^11.14",
"illuminate/cookie": "^10.48.15|^11.14",
"illuminate/database": "^10.48.15|^11.14",
"illuminate/encryption": "^10.48.15|^11.14",
"illuminate/http": "^10.48.15|^11.14",
"illuminate/support": "^10.48.15|^11.14",
"lcobucci/jwt": "^5.0",
"league/oauth2-server": "^9.0",
"nyholm/psr7": "^1.5",
Expand Down
36 changes: 3 additions & 33 deletions src/Exceptions/OAuthServerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@

namespace Laravel\Passport\Exceptions;

use Exception;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\Response;
use League\OAuth2\Server\Exception\OAuthServerException as LeagueException;

class OAuthServerException extends Exception
class OAuthServerException extends HttpResponseException
{
/**
* The response to render.
*
* @var \Illuminate\Http\Response
*/
protected $response;

/**
* Create a new OAuthServerException.
*
Expand All @@ -24,29 +17,6 @@ class OAuthServerException extends Exception
*/
public function __construct(LeagueException $e, Response $response)
{
parent::__construct($e->getMessage(), $e->getCode(), $e);

$this->response = $response;
}

/**
* Render the exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function render($request)
{
return $this->response;
}

/**
* Get the HTTP response status code.
*
* @return int
*/
public function statusCode()
{
return $this->response->getStatusCode();
parent::__construct($response, $e);
}
}
2 changes: 1 addition & 1 deletion tests/Unit/AuthorizationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function test_authorization_denied_if_unauthenticated_and_request_has_pro
} catch (\Laravel\Passport\Exceptions\OAuthServerException $e) {
$this->assertStringStartsWith(
'http://localhost?state=state&error=access_denied&error_description=',
$e->render($request)->headers->get('location')
$e->getResponse()->headers->get('location')
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/HandlesOAuthErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Laravel\Passport\Tests\Unit;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Laravel\Passport\Exceptions\OAuthServerException;
use Laravel\Passport\Http\Controllers\HandlesOAuthErrors;
Expand Down Expand Up @@ -48,9 +47,10 @@ public function testShouldHandleOAuthServerException()

$this->assertInstanceOf(OAuthServerException::class, $e);
$this->assertSame('Error', $e->getMessage());
$this->assertSame(1, $e->getCode());
$this->assertInstanceOf(LeagueException::class, $e->getPrevious());

$response = $e->render(new Request);
$response = $e->getResponse();

$this->assertJsonStringEqualsJsonString(
'{"error":"fatal","error_description":"Error"}',
Expand Down