Skip to content

Commit 1cf9234

Browse files
[13.x] Cleanup (#1758)
* cleanup * wip * undo null returns
1 parent 1e3fcd9 commit 1cf9234

13 files changed

+45
-107
lines changed

src/AuthCode.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class AuthCode extends Model
5454
/**
5555
* Get the client that owns the authentication code.
5656
*
57+
* @deprecated Will be removed in a future Laravel version.
58+
*
5759
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
5860
*/
5961
public function client()

src/Bridge/PersonalAccessGrant.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function respondToAccessTokenRequest(
1919
): ResponseTypeInterface {
2020
// Validate request
2121
$client = $this->validateClient($request);
22-
$scopes = $this->validateScopes($this->getRequestParameter('scope', $request));
22+
$scopes = $this->validateScopes($this->getRequestParameter('scope', $request, $this->defaultScope));
2323
$userIdentifier = $this->getRequestParameter('user_id', $request);
2424

2525
// Finalize the requested scopes

src/Client.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public function user()
9191
/**
9292
* Get all of the authentication codes for the client.
9393
*
94+
* @deprecated Will be removed in a future Laravel version.
95+
*
9496
* @return \Illuminate\Database\Eloquent\Relations\HasMany
9597
*/
9698
public function authCodes()

src/Console/InstallCommand.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ public function handle()
4444
if ($this->confirm('Would you like to run all pending database migrations?', true)) {
4545
$this->call('migrate');
4646

47-
if ($this->confirm('Would you like to create the "personal access" and "password grant" clients?', true)) {
48-
$provider = in_array('users', array_keys(config('auth.providers'))) ? 'users' : null;
49-
47+
if ($this->confirm('Would you like to create the "personal access" grant client?', true)) {
5048
$this->call('passport:client', ['--personal' => true, '--name' => config('app.name').' Personal Access Client']);
51-
$this->call('passport:client', ['--password' => true, '--name' => config('app.name').' Password Grant Client', '--provider' => $provider]);
5249
}
5350
}
5451
}

src/Guards/TokenGuard.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Laravel\Passport\ClientRepository;
2020
use Laravel\Passport\Passport;
2121
use Laravel\Passport\PassportUserProvider;
22-
use Laravel\Passport\TokenRepository;
2322
use Laravel\Passport\TransientToken;
2423
use League\OAuth2\Server\Exception\OAuthServerException;
2524
use League\OAuth2\Server\ResourceServer;
@@ -44,13 +43,6 @@ class TokenGuard implements Guard
4443
*/
4544
protected $provider;
4645

47-
/**
48-
* The token repository instance.
49-
*
50-
* @var \Laravel\Passport\TokenRepository
51-
*/
52-
protected $tokens;
53-
5446
/**
5547
* The client repository instance.
5648
*
@@ -84,7 +76,6 @@ class TokenGuard implements Guard
8476
*
8577
* @param \League\OAuth2\Server\ResourceServer $server
8678
* @param \Laravel\Passport\PassportUserProvider $provider
87-
* @param \Laravel\Passport\TokenRepository $tokens
8879
* @param \Laravel\Passport\ClientRepository $clients
8980
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
9081
* @param \Illuminate\Http\Request $request
@@ -93,13 +84,11 @@ class TokenGuard implements Guard
9384
public function __construct(
9485
ResourceServer $server,
9586
PassportUserProvider $provider,
96-
TokenRepository $tokens,
9787
ClientRepository $clients,
9888
Encrypter $encrypter,
9989
Request $request
10090
) {
10191
$this->server = $server;
102-
$this->tokens = $tokens;
10392
$this->clients = $clients;
10493
$this->provider = $provider;
10594
$this->encrypter = $encrypter;
@@ -109,7 +98,7 @@ public function __construct(
10998
/**
11099
* Get the user for the incoming request.
111100
*
112-
* @return mixed
101+
* @return \Illuminate\Contracts\Auth\Authenticatable|null
113102
*/
114103
public function user()
115104
{
@@ -135,7 +124,6 @@ public function validate(array $credentials = [])
135124
return ! is_null((new static(
136125
$this->server,
137126
$this->provider,
138-
$this->tokens,
139127
$this->clients,
140128
$this->encrypter,
141129
$credentials['request'],
@@ -172,7 +160,7 @@ public function client()
172160
* Authenticate the incoming request via the Bearer token.
173161
*
174162
* @param \Illuminate\Http\Request $request
175-
* @return mixed
163+
* @return \Illuminate\Contracts\Auth\Authenticatable|null
176164
*/
177165
protected function authenticateViaBearerToken($request)
178166
{
@@ -190,6 +178,8 @@ protected function authenticateViaBearerToken($request)
190178
return;
191179
}
192180

181+
$this->setClient($client);
182+
193183
// If the access token is valid we will retrieve the user according to the user ID
194184
// associated with the token. We will use the provider implementation which may
195185
// be used to retrieve users from Eloquent. Next, we'll be ready to continue.
@@ -206,7 +196,7 @@ protected function authenticateViaBearerToken($request)
206196
// authorization such as within the developer's Laravel model policy classes.
207197
$token = AccessToken::fromPsrRequest($psr);
208198

209-
return $token ? $user->withAccessToken($token) : null;
199+
return $user->withAccessToken($token);
210200
}
211201

212202
/**
@@ -242,7 +232,7 @@ protected function getPsrRequestViaBearerToken($request)
242232
* Authenticate the incoming request via the token cookie.
243233
*
244234
* @param \Illuminate\Http\Request $request
245-
* @return mixed
235+
* @return \Illuminate\Contracts\Auth\Authenticatable|null
246236
*/
247237
protected function authenticateViaCookie($request)
248238
{
@@ -262,7 +252,7 @@ protected function authenticateViaCookie($request)
262252
* Get the token cookie via the incoming request.
263253
*
264254
* @param \Illuminate\Http\Request $request
265-
* @return mixed
255+
* @return array|null
266256
*/
267257
protected function getTokenViaCookie($request)
268258
{

src/HasApiTokens.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function token()
5151
*/
5252
public function tokenCan($scope)
5353
{
54-
return $this->accessToken ? $this->accessToken->can($scope) : false;
54+
return $this->accessToken && $this->accessToken->can($scope);
5555
}
5656

5757
/**

src/Http/Middleware/CheckCredentials.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Closure;
66
use Laravel\Passport\AccessToken;
77
use Laravel\Passport\Exceptions\AuthenticationException;
8-
use Laravel\Passport\TokenRepository;
98
use League\OAuth2\Server\Exception\OAuthServerException;
109
use League\OAuth2\Server\ResourceServer;
1110
use Nyholm\Psr7\Factory\Psr17Factory;
@@ -20,24 +19,15 @@ abstract class CheckCredentials
2019
*/
2120
protected $server;
2221

23-
/**
24-
* Token Repository.
25-
*
26-
* @var \Laravel\Passport\TokenRepository
27-
*/
28-
protected $repository;
29-
3022
/**
3123
* Create a new middleware instance.
3224
*
3325
* @param \League\OAuth2\Server\ResourceServer $server
34-
* @param \Laravel\Passport\TokenRepository $repository
3526
* @return void
3627
*/
37-
public function __construct(ResourceServer $server, TokenRepository $repository)
28+
public function __construct(ResourceServer $server)
3829
{
3930
$this->server = $server;
40-
$this->repository = $repository;
4131
}
4232

4333
/**

src/PassportServiceProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ protected function makeGuard(array $config)
352352
return new TokenGuard(
353353
$this->app->make(ResourceServer::class),
354354
new PassportUserProvider(Auth::createUserProvider($config['provider']), $config['provider']),
355-
$this->app->make(TokenRepository::class),
356355
$this->app->make(ClientRepository::class),
357356
$this->app->make('encrypter'),
358357
$this->app->make('request')

src/RefreshToken.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,6 @@ public function revoke()
7171
return $this->forceFill(['revoked' => true])->save();
7272
}
7373

74-
/**
75-
* Determine if the token is a transient JWT token.
76-
*
77-
* @return bool
78-
*/
79-
public function transient()
80-
{
81-
return false;
82-
}
83-
8474
/**
8575
* Get the current connection name for the model.
8676
*

src/TokenRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public function forUser($userId)
5454
/**
5555
* Get a valid token instance for the given user and client.
5656
*
57+
* @deprecated use findValidToken
58+
*
5759
* @param \Illuminate\Contracts\Auth\Authenticatable $user
5860
* @param \Laravel\Passport\Client $client
5961
* @return \Laravel\Passport\Token|null

0 commit comments

Comments
 (0)