diff --git a/src/AuthCode.php b/src/AuthCode.php index feda66b4..6c3ce859 100644 --- a/src/AuthCode.php +++ b/src/AuthCode.php @@ -54,6 +54,8 @@ class AuthCode extends Model /** * Get the client that owns the authentication code. * + * @deprecated Will be removed in a future Laravel version. + * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function client() diff --git a/src/Bridge/PersonalAccessGrant.php b/src/Bridge/PersonalAccessGrant.php index fd2d4aec..58d6da24 100644 --- a/src/Bridge/PersonalAccessGrant.php +++ b/src/Bridge/PersonalAccessGrant.php @@ -19,7 +19,7 @@ public function respondToAccessTokenRequest( ): ResponseTypeInterface { // Validate request $client = $this->validateClient($request); - $scopes = $this->validateScopes($this->getRequestParameter('scope', $request)); + $scopes = $this->validateScopes($this->getRequestParameter('scope', $request, $this->defaultScope)); $userIdentifier = $this->getRequestParameter('user_id', $request); // Finalize the requested scopes diff --git a/src/Client.php b/src/Client.php index 4fc50933..4ba8432c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -91,6 +91,8 @@ public function user() /** * Get all of the authentication codes for the client. * + * @deprecated Will be removed in a future Laravel version. + * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function authCodes() diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index a9ffb38a..1d26a4a8 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -44,11 +44,8 @@ public function handle() if ($this->confirm('Would you like to run all pending database migrations?', true)) { $this->call('migrate'); - if ($this->confirm('Would you like to create the "personal access" and "password grant" clients?', true)) { - $provider = in_array('users', array_keys(config('auth.providers'))) ? 'users' : null; - + if ($this->confirm('Would you like to create the "personal access" grant client?', true)) { $this->call('passport:client', ['--personal' => true, '--name' => config('app.name').' Personal Access Client']); - $this->call('passport:client', ['--password' => true, '--name' => config('app.name').' Password Grant Client', '--provider' => $provider]); } } } diff --git a/src/Guards/TokenGuard.php b/src/Guards/TokenGuard.php index eecbbc24..8ffbb931 100644 --- a/src/Guards/TokenGuard.php +++ b/src/Guards/TokenGuard.php @@ -19,7 +19,6 @@ use Laravel\Passport\ClientRepository; use Laravel\Passport\Passport; use Laravel\Passport\PassportUserProvider; -use Laravel\Passport\TokenRepository; use Laravel\Passport\TransientToken; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\ResourceServer; @@ -44,13 +43,6 @@ class TokenGuard implements Guard */ protected $provider; - /** - * The token repository instance. - * - * @var \Laravel\Passport\TokenRepository - */ - protected $tokens; - /** * The client repository instance. * @@ -84,7 +76,6 @@ class TokenGuard implements Guard * * @param \League\OAuth2\Server\ResourceServer $server * @param \Laravel\Passport\PassportUserProvider $provider - * @param \Laravel\Passport\TokenRepository $tokens * @param \Laravel\Passport\ClientRepository $clients * @param \Illuminate\Contracts\Encryption\Encrypter $encrypter * @param \Illuminate\Http\Request $request @@ -93,13 +84,11 @@ class TokenGuard implements Guard public function __construct( ResourceServer $server, PassportUserProvider $provider, - TokenRepository $tokens, ClientRepository $clients, Encrypter $encrypter, Request $request ) { $this->server = $server; - $this->tokens = $tokens; $this->clients = $clients; $this->provider = $provider; $this->encrypter = $encrypter; @@ -109,7 +98,7 @@ public function __construct( /** * Get the user for the incoming request. * - * @return mixed + * @return \Illuminate\Contracts\Auth\Authenticatable|null */ public function user() { @@ -135,7 +124,6 @@ public function validate(array $credentials = []) return ! is_null((new static( $this->server, $this->provider, - $this->tokens, $this->clients, $this->encrypter, $credentials['request'], @@ -172,7 +160,7 @@ public function client() * Authenticate the incoming request via the Bearer token. * * @param \Illuminate\Http\Request $request - * @return mixed + * @return \Illuminate\Contracts\Auth\Authenticatable|null */ protected function authenticateViaBearerToken($request) { @@ -190,6 +178,8 @@ protected function authenticateViaBearerToken($request) return; } + $this->setClient($client); + // If the access token is valid we will retrieve the user according to the user ID // associated with the token. We will use the provider implementation which may // be used to retrieve users from Eloquent. Next, we'll be ready to continue. @@ -206,7 +196,7 @@ protected function authenticateViaBearerToken($request) // authorization such as within the developer's Laravel model policy classes. $token = AccessToken::fromPsrRequest($psr); - return $token ? $user->withAccessToken($token) : null; + return $user->withAccessToken($token); } /** @@ -242,7 +232,7 @@ protected function getPsrRequestViaBearerToken($request) * Authenticate the incoming request via the token cookie. * * @param \Illuminate\Http\Request $request - * @return mixed + * @return \Illuminate\Contracts\Auth\Authenticatable|null */ protected function authenticateViaCookie($request) { @@ -262,7 +252,7 @@ protected function authenticateViaCookie($request) * Get the token cookie via the incoming request. * * @param \Illuminate\Http\Request $request - * @return mixed + * @return array|null */ protected function getTokenViaCookie($request) { diff --git a/src/HasApiTokens.php b/src/HasApiTokens.php index 463c5728..6eb2af9e 100644 --- a/src/HasApiTokens.php +++ b/src/HasApiTokens.php @@ -51,7 +51,7 @@ public function token() */ public function tokenCan($scope) { - return $this->accessToken ? $this->accessToken->can($scope) : false; + return $this->accessToken && $this->accessToken->can($scope); } /** diff --git a/src/Http/Middleware/CheckCredentials.php b/src/Http/Middleware/CheckCredentials.php index 1965003f..64bf6082 100644 --- a/src/Http/Middleware/CheckCredentials.php +++ b/src/Http/Middleware/CheckCredentials.php @@ -5,7 +5,6 @@ use Closure; use Laravel\Passport\AccessToken; use Laravel\Passport\Exceptions\AuthenticationException; -use Laravel\Passport\TokenRepository; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\ResourceServer; use Nyholm\Psr7\Factory\Psr17Factory; @@ -20,24 +19,15 @@ abstract class CheckCredentials */ protected $server; - /** - * Token Repository. - * - * @var \Laravel\Passport\TokenRepository - */ - protected $repository; - /** * Create a new middleware instance. * * @param \League\OAuth2\Server\ResourceServer $server - * @param \Laravel\Passport\TokenRepository $repository * @return void */ - public function __construct(ResourceServer $server, TokenRepository $repository) + public function __construct(ResourceServer $server) { $this->server = $server; - $this->repository = $repository; } /** diff --git a/src/PassportServiceProvider.php b/src/PassportServiceProvider.php index c3eb97a8..a22dc37c 100644 --- a/src/PassportServiceProvider.php +++ b/src/PassportServiceProvider.php @@ -352,7 +352,6 @@ protected function makeGuard(array $config) return new TokenGuard( $this->app->make(ResourceServer::class), new PassportUserProvider(Auth::createUserProvider($config['provider']), $config['provider']), - $this->app->make(TokenRepository::class), $this->app->make(ClientRepository::class), $this->app->make('encrypter'), $this->app->make('request') diff --git a/src/RefreshToken.php b/src/RefreshToken.php index cf6a09b5..6b408793 100644 --- a/src/RefreshToken.php +++ b/src/RefreshToken.php @@ -71,16 +71,6 @@ public function revoke() return $this->forceFill(['revoked' => true])->save(); } - /** - * Determine if the token is a transient JWT token. - * - * @return bool - */ - public function transient() - { - return false; - } - /** * Get the current connection name for the model. * diff --git a/src/TokenRepository.php b/src/TokenRepository.php index 5886b01f..d6493592 100644 --- a/src/TokenRepository.php +++ b/src/TokenRepository.php @@ -54,6 +54,8 @@ public function forUser($userId) /** * Get a valid token instance for the given user and client. * + * @deprecated use findValidToken + * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param \Laravel\Passport\Client $client * @return \Laravel\Passport\Token|null diff --git a/tests/Unit/CheckClientCredentialsForAnyScopeTest.php b/tests/Unit/CheckClientCredentialsForAnyScopeTest.php index bd93a24c..5131cfc8 100644 --- a/tests/Unit/CheckClientCredentialsForAnyScopeTest.php +++ b/tests/Unit/CheckClientCredentialsForAnyScopeTest.php @@ -5,7 +5,6 @@ use Illuminate\Http\Request; use Laravel\Passport\Exceptions\AuthenticationException; use Laravel\Passport\Http\Middleware\CheckClientCredentialsForAnyScope; -use Laravel\Passport\TokenRepository; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\ResourceServer; use Mockery as m; @@ -30,9 +29,7 @@ public function test_request_is_passed_along_if_token_is_valid() 'oauth_scopes' => ['*'], ]); - $tokenRepository = m::mock(TokenRepository::class); - - $middleware = new CheckClientCredentialsForAnyScope($resourceServer, $tokenRepository); + $middleware = new CheckClientCredentialsForAnyScope($resourceServer); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); @@ -55,9 +52,7 @@ public function test_request_is_passed_along_if_token_has_any_required_scope() 'oauth_scopes' => ['foo', 'bar', 'baz'], ]); - $tokenRepository = m::mock(TokenRepository::class); - - $middleware = new CheckClientCredentialsForAnyScope($resourceServer, $tokenRepository); + $middleware = new CheckClientCredentialsForAnyScope($resourceServer); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); @@ -73,13 +68,12 @@ public function test_exception_is_thrown_when_oauth_throws_exception() { $this->expectException(AuthenticationException::class); - $tokenRepository = m::mock(TokenRepository::class); $resourceServer = m::mock(ResourceServer::class); $resourceServer->shouldReceive('validateAuthenticatedRequest')->andThrow( new OAuthServerException('message', 500, 'error type') ); - $middleware = new CheckClientCredentialsForAnyScope($resourceServer, $tokenRepository); + $middleware = new CheckClientCredentialsForAnyScope($resourceServer); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); @@ -102,9 +96,7 @@ public function test_exception_is_thrown_if_token_does_not_have_required_scope() 'oauth_scopes' => ['foo', 'bar'], ]); - $tokenRepository = m::mock(TokenRepository::class); - - $middleware = new CheckClientCredentialsForAnyScope($resourceServer, $tokenRepository); + $middleware = new CheckClientCredentialsForAnyScope($resourceServer); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); diff --git a/tests/Unit/CheckClientCredentialsTest.php b/tests/Unit/CheckClientCredentialsTest.php index 45dcd813..1c89404e 100644 --- a/tests/Unit/CheckClientCredentialsTest.php +++ b/tests/Unit/CheckClientCredentialsTest.php @@ -5,7 +5,6 @@ use Illuminate\Http\Request; use Laravel\Passport\Exceptions\AuthenticationException; use Laravel\Passport\Http\Middleware\CheckClientCredentials; -use Laravel\Passport\TokenRepository; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\ResourceServer; use Mockery as m; @@ -30,9 +29,7 @@ public function test_request_is_passed_along_if_token_is_valid() 'oauth_scopes' => ['*'], ]); - $tokenRepository = m::mock(TokenRepository::class); - - $middleware = new CheckClientCredentials($resourceServer, $tokenRepository); + $middleware = new CheckClientCredentials($resourceServer); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); @@ -55,9 +52,7 @@ public function test_request_is_passed_along_if_token_and_scope_are_valid() 'oauth_scopes' => ['see-profile'], ]); - $tokenRepository = m::mock(TokenRepository::class); - - $middleware = new CheckClientCredentials($resourceServer, $tokenRepository); + $middleware = new CheckClientCredentials($resourceServer); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); @@ -73,13 +68,12 @@ public function test_exception_is_thrown_when_oauth_throws_exception() { $this->expectException(AuthenticationException::class); - $tokenRepository = m::mock(TokenRepository::class); $resourceServer = m::mock(ResourceServer::class); $resourceServer->shouldReceive('validateAuthenticatedRequest')->andThrow( new OAuthServerException('message', 500, 'error type') ); - $middleware = new CheckClientCredentials($resourceServer, $tokenRepository); + $middleware = new CheckClientCredentials($resourceServer); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); @@ -102,9 +96,7 @@ public function test_exception_is_thrown_if_token_does_not_have_required_scopes( 'oauth_scopes' => ['foo', 'notbar'], ]); - $tokenRepository = m::mock(TokenRepository::class); - - $middleware = new CheckClientCredentials($resourceServer, $tokenRepository); + $middleware = new CheckClientCredentials($resourceServer); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); diff --git a/tests/Unit/TokenGuardTest.php b/tests/Unit/TokenGuardTest.php index 2e34e2a6..d9a0513e 100644 --- a/tests/Unit/TokenGuardTest.php +++ b/tests/Unit/TokenGuardTest.php @@ -11,12 +11,12 @@ use Illuminate\Encryption\Encrypter; use Illuminate\Http\Request; use Laravel\Passport\AccessToken; +use Laravel\Passport\Client; use Laravel\Passport\ClientRepository; use Laravel\Passport\Guards\TokenGuard; use Laravel\Passport\HasApiTokens; use Laravel\Passport\Passport; use Laravel\Passport\PassportUserProvider; -use Laravel\Passport\TokenRepository; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\ResourceServer; use Mockery as m; @@ -35,14 +35,13 @@ public function test_user_can_be_pulled_via_bearer_token() { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = m::mock(Encrypter::class); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $resourceServer->shouldReceive('validateAuthenticatedRequest')->andReturn($psr = m::mock(ServerRequestInterface::class)); $psr->shouldReceive('getAttribute')->with('oauth_user_id')->andReturn(1); @@ -69,14 +68,13 @@ public function test_user_is_resolved_only_once() { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = m::mock(Encrypter::class); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $resourceServer->shouldReceive('validateAuthenticatedRequest')->andReturn($psr = m::mock(ServerRequestInterface::class)); $psr->shouldReceive('getAttribute')->with('oauth_user_id')->andReturn(1); @@ -113,14 +111,13 @@ public function test_no_user_is_returned_when_oauth_throws_exception() $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = m::mock(Encrypter::class); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $resourceServer->shouldReceive('validateAuthenticatedRequest')->andThrow( new OAuthServerException('message', 500, 'error type') @@ -136,7 +133,6 @@ public function test_null_is_returned_if_no_user_is_found() { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = m::mock(Encrypter::class); @@ -147,7 +143,7 @@ public function test_null_is_returned_if_no_user_is_found() $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $resourceServer->shouldReceive('validateAuthenticatedRequest')->andReturn($psr = m::mock(ServerRequestInterface::class)); $psr->shouldReceive('getAttribute')->with('oauth_user_id')->andReturn(1); @@ -162,7 +158,6 @@ public function test_users_may_be_retrieved_from_cookies_with_csrf_token_header( { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = new Encrypter(str_repeat('a', 16)); @@ -181,7 +176,7 @@ public function test_users_may_be_retrieved_from_cookies_with_csrf_token_header( ], str_repeat('a', 16), 'HS256'), false) ); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $userProvider->shouldReceive('retrieveById')->with(1)->andReturn($expectedUser = new TokenGuardTestUser); $userProvider->shouldReceive('getProviderName')->andReturn(null); @@ -195,7 +190,6 @@ public function test_users_may_be_retrieved_from_cookies_with_xsrf_token_header( { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = new Encrypter(str_repeat('a', 16)); @@ -214,7 +208,7 @@ public function test_users_may_be_retrieved_from_cookies_with_xsrf_token_header( ], str_repeat('a', 16), 'HS256'), false) ); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $userProvider->shouldReceive('retrieveById')->with(1)->andReturn($expectedUser = new TokenGuardTestUser); $userProvider->shouldReceive('getProviderName')->andReturn(null); @@ -228,7 +222,6 @@ public function test_cookie_xsrf_is_verified_against_csrf_token_header() { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = new Encrypter(str_repeat('a', 16)); @@ -243,7 +236,7 @@ public function test_cookie_xsrf_is_verified_against_csrf_token_header() ], str_repeat('a', 16), 'HS256')) ); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $userProvider->shouldReceive('retrieveById')->never(); @@ -254,7 +247,6 @@ public function test_cookie_xsrf_is_verified_against_xsrf_token_header() { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = new Encrypter(str_repeat('a', 16)); @@ -269,7 +261,7 @@ public function test_cookie_xsrf_is_verified_against_xsrf_token_header() ], str_repeat('a', 16), 'HS256')) ); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $userProvider->shouldReceive('retrieveById')->never(); @@ -284,7 +276,6 @@ public function test_users_may_be_retrieved_from_cookies_with_xsrf_token_header_ $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = new Encrypter(str_repeat('a', 16)); @@ -303,7 +294,7 @@ public function test_users_may_be_retrieved_from_cookies_with_xsrf_token_header_ ], Passport::tokenEncryptionKey($encrypter), 'HS256'), false) ); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $userProvider->shouldReceive('retrieveById')->with(1)->andReturn($expectedUser = new TokenGuardTestUser); $userProvider->shouldReceive('getProviderName')->andReturn(null); @@ -325,7 +316,6 @@ public function test_users_may_be_retrieved_from_cookies_without_encryption() $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = new Encrypter(str_repeat('a', 16)); @@ -344,7 +334,7 @@ public function test_users_may_be_retrieved_from_cookies_without_encryption() ], Passport::tokenEncryptionKey($encrypter), 'HS256') ); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $userProvider->shouldReceive('retrieveById')->with(1)->andReturn($expectedUser = new TokenGuardTestUser); $userProvider->shouldReceive('getProviderName')->andReturn(null); @@ -362,7 +352,6 @@ public function test_xsrf_token_cookie_without_a_token_header_is_not_accepted() { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = new Encrypter(str_repeat('a', 16)); @@ -377,7 +366,7 @@ public function test_xsrf_token_cookie_without_a_token_header_is_not_accepted() ], str_repeat('a', 16), 'HS256')) ); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $userProvider->shouldReceive('retrieveById')->never(); @@ -388,7 +377,6 @@ public function test_expired_cookies_may_not_be_used() { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = new Encrypter(str_repeat('a', 16)); @@ -403,7 +391,7 @@ public function test_expired_cookies_may_not_be_used() ], str_repeat('a', 16), 'HS256')) ); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $userProvider->shouldReceive('retrieveById')->never(); @@ -414,7 +402,6 @@ public function test_csrf_check_can_be_disabled() { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = new Encrypter(str_repeat('a', 16)); @@ -433,7 +420,7 @@ public function test_csrf_check_can_be_disabled() ], str_repeat('a', 16), 'HS256'), false) ); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $userProvider->shouldReceive('retrieveById')->with(1)->andReturn($expectedUser = new TokenGuardTestUser); $userProvider->shouldReceive('getProviderName')->andReturn(null); @@ -447,14 +434,13 @@ public function test_client_can_be_pulled_via_bearer_token() { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = m::mock(Encrypter::class); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $resourceServer->shouldReceive('validateAuthenticatedRequest')->andReturn($psr = m::mock(ServerRequestInterface::class)); $psr->shouldReceive('getAttribute')->with('oauth_client_id')->andReturn(1); @@ -469,14 +455,13 @@ public function test_client_is_resolved_only_once() { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = m::mock(Encrypter::class); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $resourceServer->shouldReceive('validateAuthenticatedRequest')->andReturn($psr = m::mock(ServerRequestInterface::class)); $psr->shouldReceive('getAttribute')->with('oauth_client_id')->andReturn(1); @@ -501,14 +486,13 @@ public function test_no_client_is_returned_when_oauth_throws_exception() $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = m::mock(Encrypter::class); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $resourceServer->shouldReceive('validateAuthenticatedRequest')->andThrow( new OAuthServerException('message', 500, 'error type') @@ -524,14 +508,13 @@ public function test_null_is_returned_if_no_client_is_found() { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = m::mock(Encrypter::class); $request = Request::create('/'); $request->headers->set('Authorization', 'Bearer token'); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $resourceServer->shouldReceive('validateAuthenticatedRequest')->andReturn($psr = m::mock(ServerRequestInterface::class)); $psr->shouldReceive('getAttribute')->with('oauth_client_id')->andReturn(1); @@ -544,7 +527,6 @@ public function test_clients_may_be_retrieved_from_cookies() { $resourceServer = m::mock(ResourceServer::class); $userProvider = m::mock(PassportUserProvider::class); - $tokens = m::mock(TokenRepository::class); $clients = m::mock(ClientRepository::class); $encrypter = new Encrypter(str_repeat('a', 16)); @@ -559,7 +541,7 @@ public function test_clients_may_be_retrieved_from_cookies() ], str_repeat('a', 16), 'HS256'), false) ); - $guard = new TokenGuard($resourceServer, $userProvider, $tokens, $clients, $encrypter, $request); + $guard = new TokenGuard($resourceServer, $userProvider, $clients, $encrypter, $request); $clients->shouldReceive('findActive')->with(1)->andReturn($expectedClient = new TokenGuardTestClient); @@ -574,7 +556,7 @@ class TokenGuardTestUser use HasApiTokens; } -class TokenGuardTestClient +class TokenGuardTestClient extends Client { public $provider; }