Skip to content

Commit 7458bfd

Browse files
Merge branch '13.x' into 13.x-device-code-grant
2 parents 688830c + 0c33c4c commit 7458bfd

File tree

69 files changed

+764
-1471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+764
-1471
lines changed

database/factories/ClientFactory.php

+20-13
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ class ClientFactory extends Factory
1414
/**
1515
* Get the name of the model that is generated by the factory.
1616
*
17-
* @return class-string<\Illuminate\Database\Eloquent\Model>
17+
* @return class-string<\Laravel\Passport\Client>
1818
*/
19-
public function modelName()
19+
public function modelName(): string
2020
{
2121
return $this->model ?? Passport::clientModel();
2222
}
2323

2424
/**
2525
* Define the model's default state.
2626
*
27-
* @return array
27+
* @return array<string, mixed>
2828
*/
29-
public function definition()
29+
public function definition(): array
3030
{
3131
return [
3232
'user_id' => null,
@@ -40,37 +40,44 @@ public function definition()
4040

4141
/**
4242
* Use as a Password client.
43-
*
44-
* @return $this
4543
*/
46-
public function asPasswordClient()
44+
public function asPasswordClient(): static
4745
{
4846
return $this->state([
4947
'grant_types' => ['password', 'refresh_token'],
48+
'redirect_uris' => [],
5049
]);
5150
}
5251

5352
/**
5453
* Use as a Personal Access Token client.
55-
*
56-
* @return $this
5754
*/
58-
public function asPersonalAccessTokenClient()
55+
public function asPersonalAccessTokenClient(): static
5956
{
6057
return $this->state([
6158
'grant_types' => ['personal_access'],
59+
'redirect_uris' => [],
60+
]);
61+
}
62+
63+
/**
64+
* Use as an Implicit client.
65+
*/
66+
public function asImplicitClient(): static
67+
{
68+
return $this->state([
69+
'grant_types' => ['implicit'],
6270
]);
6371
}
6472

6573
/**
6674
* Use as a Client Credentials client.
67-
*
68-
* @return $this
6975
*/
70-
public function asClientCredentials()
76+
public function asClientCredentials(): static
7177
{
7278
return $this->state([
7379
'grant_types' => ['client_credentials'],
80+
'redirect_uris' => [],
7481
]);
7582
}
7683

database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ public function down(): void
3131

3232
/**
3333
* Get the migration connection name.
34-
*
35-
* @return string|null
3634
*/
37-
public function getConnection()
35+
public function getConnection(): ?string
3836
{
3937
return $this->connection ?? config('passport.connection');
4038
}

database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ public function down(): void
3333

3434
/**
3535
* Get the migration connection name.
36-
*
37-
* @return string|null
3836
*/
39-
public function getConnection()
37+
public function getConnection(): ?string
4038
{
4139
return $this->connection ?? config('passport.connection');
4240
}

database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ public function down(): void
2929

3030
/**
3131
* Get the migration connection name.
32-
*
33-
* @return string|null
3432
*/
35-
public function getConnection()
33+
public function getConnection(): ?string
3634
{
3735
return $this->connection ?? config('passport.connection');
3836
}

database/migrations/2016_06_01_000004_create_oauth_clients_table.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ public function down(): void
3434

3535
/**
3636
* Get the migration connection name.
37-
*
38-
* @return string|null
3937
*/
40-
public function getConnection()
38+
public function getConnection(): ?string
4139
{
4240
return $this->connection ?? config('passport.connection');
4341
}

src/AccessToken.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AccessToken implements Arrayable, Jsonable, JsonSerializable
3838
/**
3939
* Create a new access token instance.
4040
*
41-
* @param array<string, mixed> $attributes
41+
* @param array<TKey, TValue> $attributes
4242
*/
4343
public function __construct(array $attributes = [])
4444
{
@@ -84,7 +84,7 @@ public function transient(): bool
8484
*/
8585
public function revoke(): bool
8686
{
87-
return Passport::token()->newQuery()->whereKey($this->oauth_access_token_id)->update(['revoked' => true]);
87+
return (bool) Passport::token()->newQuery()->whereKey($this->oauth_access_token_id)->update(['revoked' => true]);
8888
}
8989

9090
/**

src/ApiTokenCookieFactory.php

+6-33
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,19 @@
1010

1111
class ApiTokenCookieFactory
1212
{
13-
/**
14-
* The configuration repository implementation.
15-
*
16-
* @var \Illuminate\Contracts\Config\Repository
17-
*/
18-
protected $config;
19-
20-
/**
21-
* The encrypter implementation.
22-
*
23-
* @var \Illuminate\Contracts\Encryption\Encrypter
24-
*/
25-
protected $encrypter;
26-
2713
/**
2814
* Create an API token cookie factory instance.
29-
*
30-
* @param \Illuminate\Contracts\Config\Repository $config
31-
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
32-
* @return void
3315
*/
34-
public function __construct(Config $config, Encrypter $encrypter)
35-
{
36-
$this->config = $config;
37-
$this->encrypter = $encrypter;
16+
public function __construct(
17+
protected Config $config,
18+
protected Encrypter $encrypter
19+
) {
3820
}
3921

4022
/**
4123
* Create a new API token cookie.
42-
*
43-
* @param mixed $userId
44-
* @param string $csrfToken
45-
* @return \Symfony\Component\HttpFoundation\Cookie
4624
*/
47-
public function make($userId, $csrfToken)
25+
public function make(string|int $userId, string $csrfToken): Cookie
4826
{
4927
$config = $this->config->get('session');
5028

@@ -65,13 +43,8 @@ public function make($userId, $csrfToken)
6543

6644
/**
6745
* Create a new JWT token for the given user ID and CSRF token.
68-
*
69-
* @param mixed $userId
70-
* @param string $csrfToken
71-
* @param \Carbon\Carbon $expiration
72-
* @return string
7346
*/
74-
protected function createToken($userId, $csrfToken, Carbon $expiration)
47+
protected function createToken(string|int $userId, string $csrfToken, Carbon $expiration): string
7548
{
7649
return JWT::encode([
7750
'sub' => $userId,

src/AuthCode.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Laravel\Passport;
44

55
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
67

78
class AuthCode extends Model
89
{
@@ -23,14 +24,14 @@ class AuthCode extends Model
2324
/**
2425
* The guarded attributes on the model.
2526
*
26-
* @var array
27+
* @var array<string>|bool
2728
*/
28-
protected $guarded = [];
29+
protected $guarded = false;
2930

3031
/**
3132
* The attributes that should be cast to native types.
3233
*
33-
* @var array
34+
* @var array<string, \Illuminate\Contracts\Database\Eloquent\Castable|string>
3435
*/
3536
protected $casts = [
3637
'revoked' => 'bool',
@@ -56,19 +57,17 @@ class AuthCode extends Model
5657
*
5758
* @deprecated Will be removed in a future Laravel version.
5859
*
59-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
60+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Laravel\Passport\Client, $this>
6061
*/
61-
public function client()
62+
public function client(): BelongsTo
6263
{
6364
return $this->belongsTo(Passport::clientModel());
6465
}
6566

6667
/**
6768
* Get the current connection name for the model.
68-
*
69-
* @return string|null
7069
*/
71-
public function getConnectionName()
70+
public function getConnectionName(): ?string
7271
{
7372
return $this->connection ?? config('passport.connection');
7473
}

src/Bridge/AccessToken.php

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class AccessToken implements AccessTokenEntityInterface
1515
/**
1616
* Create a new token instance.
1717
*
18+
* @param non-empty-string|null $userIdentifier
1819
* @param \League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes
1920
*/
2021
public function __construct(string|null $userIdentifier, array $scopes, ClientEntityInterface $client)

src/Bridge/AccessTokenRepository.php

+6-18
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Laravel\Passport\Events\AccessTokenCreated;
88
use Laravel\Passport\Events\AccessTokenRevoked;
99
use Laravel\Passport\Passport;
10-
use Laravel\Passport\TokenRepository;
1110
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
1211
use League\OAuth2\Server\Entities\ClientEntityInterface;
1312
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
@@ -16,23 +15,12 @@ class AccessTokenRepository implements AccessTokenRepositoryInterface
1615
{
1716
use FormatsScopesForStorage;
1817

19-
/**
20-
* The token repository instance.
21-
*/
22-
protected TokenRepository $tokenRepository;
23-
24-
/**
25-
* The event dispatcher instance.
26-
*/
27-
protected Dispatcher $events;
28-
2918
/**
3019
* Create a new repository instance.
3120
*/
32-
public function __construct(TokenRepository $tokenRepository, Dispatcher $events)
33-
{
34-
$this->events = $events;
35-
$this->tokenRepository = $tokenRepository;
21+
public function __construct(
22+
protected Dispatcher $events
23+
) {
3624
}
3725

3826
/**
@@ -51,7 +39,7 @@ public function getNewToken(
5139
*/
5240
public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity): void
5341
{
54-
$this->tokenRepository->create([
42+
Passport::token()->newQuery()->create([
5543
'id' => $id = $accessTokenEntity->getIdentifier(),
5644
'user_id' => $userId = $accessTokenEntity->getUserIdentifier(),
5745
'client_id' => $clientId = $accessTokenEntity->getClient()->getIdentifier(),
@@ -70,7 +58,7 @@ public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEnt
7058
*/
7159
public function revokeAccessToken(string $tokenId): void
7260
{
73-
if ($this->tokenRepository->revokeAccessToken($tokenId)) {
61+
if (Passport::token()->newQuery()->whereKey($tokenId)->update(['revoked' => true])) {
7462
$this->events->dispatch(new AccessTokenRevoked($tokenId));
7563
}
7664
}
@@ -80,6 +68,6 @@ public function revokeAccessToken(string $tokenId): void
8068
*/
8169
public function isAccessTokenRevoked(string $tokenId): bool
8270
{
83-
return $this->tokenRepository->isAccessTokenRevoked($tokenId);
71+
return Passport::token()->newQuery()->whereKey($tokenId)->where('revoked', false)->doesntExist();
8472
}
8573
}

src/Bridge/AuthCodeRepository.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,29 @@ public function getNewAuthCode(): AuthCodeEntityInterface
2323
*/
2424
public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity): void
2525
{
26-
$attributes = [
26+
Passport::authCode()->forceFill([
2727
'id' => $authCodeEntity->getIdentifier(),
2828
'user_id' => $authCodeEntity->getUserIdentifier(),
2929
'client_id' => $authCodeEntity->getClient()->getIdentifier(),
3030
'scopes' => $this->formatScopesForStorage($authCodeEntity->getScopes()),
3131
'revoked' => false,
3232
'expires_at' => $authCodeEntity->getExpiryDateTime(),
33-
];
34-
35-
Passport::authCode()->forceFill($attributes)->save();
33+
])->save();
3634
}
3735

3836
/**
3937
* {@inheritdoc}
4038
*/
4139
public function revokeAuthCode(string $codeId): void
4240
{
43-
Passport::authCode()->where('id', $codeId)->update(['revoked' => true]);
41+
Passport::authCode()->newQuery()->whereKey($codeId)->update(['revoked' => true]);
4442
}
4543

4644
/**
4745
* {@inheritdoc}
4846
*/
4947
public function isAuthCodeRevoked(string $codeId): bool
5048
{
51-
return Passport::authCode()->where('id', $codeId)->where('revoked', 0)->doesntExist();
49+
return Passport::authCode()->newQuery()->whereKey($codeId)->where('revoked', false)->doesntExist();
5250
}
5351
}

src/Bridge/Client.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@ class Client implements ClientEntityInterface
1010
{
1111
use ClientTrait, EntityTrait;
1212

13-
/**
14-
* The client's provider.
15-
*/
16-
public ?string $provider;
17-
1813
/**
1914
* Create a new client instance.
15+
*
16+
* @param non-empty-string $identifier
17+
* @param string[] $redirectUri
2018
*/
2119
public function __construct(
2220
string $identifier,
2321
?string $name = null,
2422
array $redirectUri = [],
2523
bool $isConfidential = false,
26-
?string $provider = null
24+
public ?string $provider = null
2725
) {
2826
$this->setIdentifier($identifier);
2927

@@ -33,6 +31,5 @@ public function __construct(
3331

3432
$this->isConfidential = $isConfidential;
3533
$this->redirectUri = $redirectUri;
36-
$this->provider = $provider;
3734
}
3835
}

0 commit comments

Comments
 (0)