Skip to content

Commit b2bb7df

Browse files
[13.x] Fix register a custom rendering closure for OAuthServerException (#1763)
* fix rendering `OAuthServerException` * formatting * use `HttpResponseException` * wip * formatting * fix rendering `OAuthServerException` * formatting * use `HttpResponseException` * wip * formatting * remove `render` method * remove redundant method * update dependencies
1 parent e1040f3 commit b2bb7df

File tree

4 files changed

+15
-45
lines changed

4 files changed

+15
-45
lines changed

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
"ext-json": "*",
1919
"ext-openssl": "*",
2020
"firebase/php-jwt": "^6.4",
21-
"illuminate/auth": "^10.0|^11.0",
22-
"illuminate/console": "^10.0|^11.0",
23-
"illuminate/container": "^10.0|^11.0",
24-
"illuminate/contracts": "^10.0|^11.0",
25-
"illuminate/cookie": "^10.0|^11.0",
26-
"illuminate/database": "^10.0|^11.0",
27-
"illuminate/encryption": "^10.0|^11.0",
28-
"illuminate/http": "^10.0|^11.0",
29-
"illuminate/support": "^10.0|^11.0",
21+
"illuminate/auth": "^10.48.15|^11.14",
22+
"illuminate/console": "^10.48.15|^11.14",
23+
"illuminate/container": "^10.48.15|^11.14",
24+
"illuminate/contracts": "^10.48.15|^11.14",
25+
"illuminate/cookie": "^10.48.15|^11.14",
26+
"illuminate/database": "^10.48.15|^11.14",
27+
"illuminate/encryption": "^10.48.15|^11.14",
28+
"illuminate/http": "^10.48.15|^11.14",
29+
"illuminate/support": "^10.48.15|^11.14",
3030
"lcobucci/jwt": "^5.0",
3131
"league/oauth2-server": "^9.0",
3232
"nyholm/psr7": "^1.5",

src/Exceptions/OAuthServerException.php

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,12 @@
22

33
namespace Laravel\Passport\Exceptions;
44

5-
use Exception;
5+
use Illuminate\Http\Exceptions\HttpResponseException;
66
use Illuminate\Http\Response;
77
use League\OAuth2\Server\Exception\OAuthServerException as LeagueException;
88

9-
class OAuthServerException extends Exception
9+
class OAuthServerException extends HttpResponseException
1010
{
11-
/**
12-
* The response to render.
13-
*
14-
* @var \Illuminate\Http\Response
15-
*/
16-
protected $response;
17-
1811
/**
1912
* Create a new OAuthServerException.
2013
*
@@ -24,29 +17,6 @@ class OAuthServerException extends Exception
2417
*/
2518
public function __construct(LeagueException $e, Response $response)
2619
{
27-
parent::__construct($e->getMessage(), $e->getCode(), $e);
28-
29-
$this->response = $response;
30-
}
31-
32-
/**
33-
* Render the exception into an HTTP response.
34-
*
35-
* @param \Illuminate\Http\Request $request
36-
* @return \Illuminate\Http\Response
37-
*/
38-
public function render($request)
39-
{
40-
return $this->response;
41-
}
42-
43-
/**
44-
* Get the HTTP response status code.
45-
*
46-
* @return int
47-
*/
48-
public function statusCode()
49-
{
50-
return $this->response->getStatusCode();
20+
parent::__construct($response, $e);
5121
}
5222
}

tests/Unit/AuthorizationControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public function test_authorization_denied_if_unauthenticated_and_request_has_pro
333333
} catch (\Laravel\Passport\Exceptions\OAuthServerException $e) {
334334
$this->assertStringStartsWith(
335335
'http://localhost?state=state&error=access_denied&error_description=',
336-
$e->render($request)->headers->get('location')
336+
$e->getResponse()->headers->get('location')
337337
);
338338
}
339339
}

tests/Unit/HandlesOAuthErrorsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Laravel\Passport\Tests\Unit;
44

5-
use Illuminate\Http\Request;
65
use Illuminate\Http\Response;
76
use Laravel\Passport\Exceptions\OAuthServerException;
87
use Laravel\Passport\Http\Controllers\HandlesOAuthErrors;
@@ -48,9 +47,10 @@ public function testShouldHandleOAuthServerException()
4847

4948
$this->assertInstanceOf(OAuthServerException::class, $e);
5049
$this->assertSame('Error', $e->getMessage());
50+
$this->assertSame(1, $e->getCode());
5151
$this->assertInstanceOf(LeagueException::class, $e->getPrevious());
5252

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

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

0 commit comments

Comments
 (0)