Skip to content

Commit

Permalink
Revert "Revert "Added AuthenticationException to extend the behaviour…
Browse files Browse the repository at this point in the history
… of Laravel's default exception handler (#1633)""

This reverts commit db543b0.
  • Loading branch information
driesvints committed Feb 20, 2023
1 parent f3d0315 commit 67c3e33
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/Exceptions/AuthenticationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Laravel\Passport\Exceptions;

use Illuminate\Auth\AuthenticationException as Exception;

class AuthenticationException extends Exception
{
}
4 changes: 2 additions & 2 deletions src/Http/Controllers/AuthorizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Laravel\Passport\Http\Controllers;

use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Laravel\Passport\Bridge\User;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Contracts\AuthorizationViewResponse;
use Laravel\Passport\Exceptions\AuthenticationException;
use Laravel\Passport\Passport;
use Laravel\Passport\TokenRepository;
use League\OAuth2\Server\AuthorizationServer;
Expand Down Expand Up @@ -208,7 +208,7 @@ protected function denyRequest($authRequest, $user = null)
*
* @param \Illuminate\Http\Request $request
*
* @throws \Illuminate\Auth\AuthenticationException
* @throws \Laravel\Passport\Exceptions\AuthenticationException
*/
protected function promptForLogin($request)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Middleware/CheckClientCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Laravel\Passport\Http\Middleware;

use Illuminate\Auth\AuthenticationException;
use Laravel\Passport\Exceptions\AuthenticationException;
use Laravel\Passport\Exceptions\MissingScopeException;

class CheckClientCredentials extends CheckCredentials
Expand All @@ -13,7 +13,7 @@ class CheckClientCredentials extends CheckCredentials
* @param \Laravel\Passport\Token $token
* @return void
*
* @throws \Illuminate\Auth\AuthenticationException
* @throws \Laravel\Passport\Exceptions\AuthenticationException
*/
protected function validateCredentials($token)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Middleware/CheckClientCredentialsForAnyScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Laravel\Passport\Http\Middleware;

use Illuminate\Auth\AuthenticationException;
use Laravel\Passport\Exceptions\AuthenticationException;
use Laravel\Passport\Exceptions\MissingScopeException;

class CheckClientCredentialsForAnyScope extends CheckCredentials
Expand All @@ -13,7 +13,7 @@ class CheckClientCredentialsForAnyScope extends CheckCredentials
* @param \Laravel\Passport\Token $token
* @return void
*
* @throws \Illuminate\Auth\AuthenticationException
* @throws \Laravel\Passport\Exceptions\AuthenticationException
*/
protected function validateCredentials($token)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Middleware/CheckCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Laravel\Passport\Http\Middleware;

use Closure;
use Illuminate\Auth\AuthenticationException;
use Laravel\Passport\Exceptions\AuthenticationException;
use Laravel\Passport\TokenRepository;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\ResourceServer;
Expand Down Expand Up @@ -47,7 +47,7 @@ public function __construct(ResourceServer $server, TokenRepository $repository)
* @param mixed ...$scopes
* @return mixed
*
* @throws \Illuminate\Auth\AuthenticationException
* @throws \Laravel\Passport\Exceptions\AuthenticationException
*/
public function handle($request, Closure $next, ...$scopes)
{
Expand Down Expand Up @@ -93,7 +93,7 @@ protected function validate($psr, $scopes)
* @param \Laravel\Passport\Token $token
* @return void
*
* @throws \Illuminate\Auth\AuthenticationException
* @throws \Laravel\Passport\Exceptions\AuthenticationException
*/
abstract protected function validateCredentials($token);

Expand Down
4 changes: 2 additions & 2 deletions src/Http/Middleware/CheckForAnyScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Laravel\Passport\Http\Middleware;

use Illuminate\Auth\AuthenticationException;
use Laravel\Passport\Exceptions\AuthenticationException;
use Laravel\Passport\Exceptions\MissingScopeException;

class CheckForAnyScope
Expand All @@ -15,7 +15,7 @@ class CheckForAnyScope
* @param mixed ...$scopes
* @return \Illuminate\Http\Response
*
* @throws \Illuminate\Auth\AuthenticationException|\Laravel\Passport\Exceptions\MissingScopeException
* @throws \Laravel\Passport\Exceptions\AuthenticationException|\Laravel\Passport\Exceptions\MissingScopeException
*/
public function handle($request, $next, ...$scopes)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Middleware/CheckScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Laravel\Passport\Http\Middleware;

use Illuminate\Auth\AuthenticationException;
use Laravel\Passport\Exceptions\AuthenticationException;
use Laravel\Passport\Exceptions\MissingScopeException;

class CheckScopes
Expand All @@ -15,7 +15,7 @@ class CheckScopes
* @param mixed ...$scopes
* @return \Illuminate\Http\Response
*
* @throws \Illuminate\Auth\AuthenticationException|\Laravel\Passport\Exceptions\MissingScopeException
* @throws \Laravel\Passport\Exceptions\AuthenticationException|\Laravel\Passport\Exceptions\MissingScopeException
*/
public function handle($request, $next, ...$scopes)
{
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/AuthorizationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laravel\Passport\Bridge\Scope;
use Laravel\Passport\Client;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Exceptions\AuthenticationException;
use Laravel\Passport\Exceptions\OAuthServerException;
use Laravel\Passport\Http\Controllers\AuthorizationController;
use Laravel\Passport\Http\Responses\AuthorizationViewResponse;
Expand Down Expand Up @@ -336,7 +337,7 @@ public function test_authorization_denied_if_unauthenticated_and_request_has_pro

public function test_logout_and_prompt_login_if_request_has_prompt_equals_to_login()
{
$this->expectException('Illuminate\Auth\AuthenticationException');
$this->expectException(AuthenticationException::class);

$server = m::mock(AuthorizationServer::class);
$response = m::mock(AuthorizationViewResponse::class);
Expand Down Expand Up @@ -367,7 +368,7 @@ public function test_logout_and_prompt_login_if_request_has_prompt_equals_to_log

public function test_user_should_be_authenticated()
{
$this->expectException('Illuminate\Auth\AuthenticationException');
$this->expectException(AuthenticationException::class);

$server = m::mock(AuthorizationServer::class);
$response = m::mock(AuthorizationViewResponse::class);
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/CheckClientCredentialsForAnyScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Laravel\Passport\Client;
use Laravel\Passport\Exceptions\AuthenticationException;
use Laravel\Passport\Http\Middleware\CheckClientCredentialsForAnyScope;
use Laravel\Passport\Token;
use Laravel\Passport\TokenRepository;
Expand Down Expand Up @@ -85,7 +86,7 @@ public function test_request_is_passed_along_if_token_has_any_required_scope()

public function test_exception_is_thrown_when_oauth_throws_exception()
{
$this->expectException('Illuminate\Auth\AuthenticationException');
$this->expectException(AuthenticationException::class);

$tokenRepository = m::mock(TokenRepository::class);
$resourceServer = m::mock(ResourceServer::class);
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/CheckClientCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Laravel\Passport\Client;
use Laravel\Passport\Exceptions\AuthenticationException;
use Laravel\Passport\Http\Middleware\CheckClientCredentials;
use Laravel\Passport\Token;
use Laravel\Passport\TokenRepository;
Expand Down Expand Up @@ -84,7 +85,7 @@ public function test_request_is_passed_along_if_token_and_scope_are_valid()

public function test_exception_is_thrown_when_oauth_throws_exception()
{
$this->expectException('Illuminate\Auth\AuthenticationException');
$this->expectException(AuthenticationException::class);

$tokenRepository = m::mock(TokenRepository::class);
$resourceServer = m::mock(ResourceServer::class);
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/CheckForAnyScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Passport\Tests\Unit;

use Laravel\Passport\Exceptions\AuthenticationException;
use Laravel\Passport\Http\Middleware\CheckForAnyScope as CheckScopes;
use Mockery as m;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -47,7 +48,7 @@ public function test_exception_is_thrown_if_token_doesnt_have_scope()

public function test_exception_is_thrown_if_no_authenticated_user()
{
$this->expectException('Illuminate\Auth\AuthenticationException');
$this->expectException(AuthenticationException::class);

$middleware = new CheckScopes;
$request = m::mock();
Expand All @@ -60,7 +61,7 @@ public function test_exception_is_thrown_if_no_authenticated_user()

public function test_exception_is_thrown_if_no_token()
{
$this->expectException('Illuminate\Auth\AuthenticationException');
$this->expectException(AuthenticationException::class);

$middleware = new CheckScopes;
$request = m::mock();
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/CheckScopesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Passport\Tests\Unit;

use Laravel\Passport\Exceptions\AuthenticationException;
use Laravel\Passport\Http\Middleware\CheckScopes;
use Mockery as m;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -46,7 +47,7 @@ public function test_exception_is_thrown_if_token_doesnt_have_scope()

public function test_exception_is_thrown_if_no_authenticated_user()
{
$this->expectException('Illuminate\Auth\AuthenticationException');
$this->expectException(AuthenticationException::class);

$middleware = new CheckScopes;
$request = m::mock();
Expand All @@ -59,7 +60,7 @@ public function test_exception_is_thrown_if_no_authenticated_user()

public function test_exception_is_thrown_if_no_token()
{
$this->expectException('Illuminate\Auth\AuthenticationException');
$this->expectException(AuthenticationException::class);

$middleware = new CheckScopes;
$request = m::mock();
Expand Down

0 comments on commit 67c3e33

Please sign in to comment.