Skip to content

Commit aebd4e4

Browse files
committed
Issue #423: Upgraded mezzio-oauth2 to v3.0.1
Signed-off-by: bota <Bota@dotkernel.com>
1 parent 7e04718 commit aebd4e4

16 files changed

Lines changed: 99 additions & 131 deletions

bin/composer-post-install-script.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ function getEnvironment(): string
5454
],
5555
[
5656
'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist',
57-
'destination' => 'config/autoload/mail.global.php',
57+
'destination' => 'config/autoload/mail.local.php',
58+
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
59+
],
60+
[
61+
'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist',
62+
'destination' => 'config/autoload/mail.local.php.dist',
5863
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
5964
],
6065
];

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"laminas/laminas-component-installer": "^3.7.0",
4848
"laminas/laminas-config-aggregator": "^1.19.0",
4949
"mezzio/mezzio": "^3.26.0",
50-
"mezzio/mezzio-authentication-oauth2": "^2.13.0",
50+
"mezzio/mezzio-authentication-oauth2": "^3.0.1",
5151
"mezzio/mezzio-authorization-rbac": "^1.10.0",
5252
"mezzio/mezzio-cors": "^1.15.0",
5353
"mezzio/mezzio-fastroute": "^3.14.0",

src/Core/src/Admin/src/Entity/Admin.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class Admin extends AbstractEntity implements UserEntityInterface
3232
use TimestampsTrait;
3333
use UuidIdentifierTrait;
3434

35-
/** @var non-empty-string|null $identity */
35+
/** @var non-empty-string $identity */
3636
#[ORM\Column(name: 'identity', type: 'string', length: 191, unique: true)]
37-
protected ?string $identity = null;
37+
protected string $identity;
3838

3939
#[ORM\Column(name: 'firstName', type: 'string', length: 191, nullable: true)]
4040
protected ?string $firstName = null;
@@ -43,7 +43,7 @@ class Admin extends AbstractEntity implements UserEntityInterface
4343
protected ?string $lastName = null;
4444

4545
#[ORM\Column(name: 'password', type: 'string', length: 191)]
46-
protected ?string $password = null;
46+
protected string $password;
4747

4848
#[ORM\Column(
4949
type: 'admin_status_enum',
@@ -71,16 +71,11 @@ public function __construct()
7171
$this->settings = new ArrayCollection();
7272
}
7373

74-
public function getIdentity(): ?string
74+
public function getIdentity(): string
7575
{
7676
return $this->identity;
7777
}
7878

79-
public function hasIdentity(): bool
80-
{
81-
return $this->identity !== null;
82-
}
83-
8479
/**
8580
* @param non-empty-string $identity
8681
*/
@@ -91,6 +86,11 @@ public function setIdentity(string $identity): self
9186
return $this;
9287
}
9388

89+
public function hasIdentity(): bool
90+
{
91+
return ! empty($this->identity);
92+
}
93+
9494
public function getFirstName(): ?string
9595
{
9696
return $this->firstName;
@@ -115,7 +115,7 @@ public function setLastName(string $lastName): self
115115
return $this;
116116
}
117117

118-
public function getPassword(): ?string
118+
public function getPassword(): string
119119
{
120120
return $this->password;
121121
}
@@ -213,9 +213,12 @@ public function isActive(): bool
213213
return $this->status === AdminStatusEnum::Active;
214214
}
215215

216+
/**
217+
* @return non-empty-string
218+
*/
216219
public function getIdentifier(): string
217220
{
218-
return (string) $this->identity;
221+
return $this->identity;
219222
}
220223

221224
/**

src/Core/src/App/src/Entity/NumericIdentifierTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ trait NumericIdentifierTrait
1111
#[ORM\Id]
1212
#[ORM\Column(name: 'id', type: 'integer', options: ['unsigned' => true])]
1313
#[ORM\GeneratedValue(strategy: 'AUTO')]
14-
protected ?int $id;
14+
protected int $id;
1515

16-
public function getId(): ?int
16+
public function getId(): int
1717
{
1818
return $this->id;
1919
}

src/Core/src/Security/src/Entity/OAuthAccessToken.php

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Lcobucci\JWT\Signer\Key\InMemory;
1616
use Lcobucci\JWT\Signer\Rsa\Sha256;
1717
use Lcobucci\JWT\Token;
18-
use League\OAuth2\Server\CryptKey;
18+
use League\OAuth2\Server\CryptKeyInterface;
1919
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
2020
use League\OAuth2\Server\Entities\ClientEntityInterface;
2121
use League\OAuth2\Server\Entities\ScopeEntityInterface;
@@ -33,8 +33,9 @@ class OAuthAccessToken implements AccessTokenEntityInterface
3333
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id')]
3434
private ClientEntityInterface $client;
3535

36-
#[ORM\Column(name: 'user_id', type: 'string', length: 25, nullable: true)]
37-
private ?string $userId = null;
36+
/** @var non-empty-string $userId */
37+
#[ORM\Column(name: 'user_id', type: 'string', length: 25)]
38+
private string $userId;
3839

3940
/** @var non-empty-string $token */
4041
#[ORM\Column(name: 'token', type: 'string', length: 100)]
@@ -53,7 +54,7 @@ class OAuthAccessToken implements AccessTokenEntityInterface
5354
#[ORM\Column(name: 'expires_at', type: 'datetime_immutable')]
5455
private DateTimeImmutable $expiresAt;
5556

56-
private ?CryptKey $privateKey = null;
57+
private ?CryptKeyInterface $privateKey = null;
5758

5859
private ?Configuration $jwtConfiguration = null;
5960

@@ -62,11 +63,9 @@ public function __construct()
6263
$this->scopes = new ArrayCollection();
6364
}
6465

65-
public function setClient(ClientEntityInterface $client): self
66+
public function setClient(ClientEntityInterface $client): void
6667
{
6768
$this->client = $client;
68-
69-
return $this;
7069
}
7170

7271
public function getClient(): ClientEntityInterface
@@ -85,11 +84,9 @@ public function getToken(): string
8584
/**
8685
* @param non-empty-string $token
8786
*/
88-
public function setToken(string $token): self
87+
public function setToken(string $token): void
8988
{
9089
$this->token = $token;
91-
92-
return $this;
9390
}
9491

9592
public function setIsRevoked(bool $isRevoked): self
@@ -122,37 +119,33 @@ public function getIdentifier(): string
122119
/**
123120
* @param mixed $identifier
124121
*/
125-
public function setIdentifier($identifier): self
122+
public function setIdentifier($identifier): void
126123
{
127-
return $this->setToken($identifier);
124+
$this->setToken($identifier);
128125
}
129126

130127
/**
131-
* @param string|int|null $identifier
128+
* @param non-empty-string|int $identifier
132129
*/
133-
public function setUserIdentifier($identifier): self
130+
public function setUserIdentifier($identifier): void
134131
{
135132
if (is_int($identifier)) {
136133
$identifier = (string) $identifier;
137134
}
138135

139136
$this->userId = $identifier;
140-
141-
return $this;
142137
}
143138

144-
public function getUserIdentifier(): ?string
139+
public function getUserIdentifier(): string
145140
{
146141
return $this->userId;
147142
}
148143

149-
public function addScope(ScopeEntityInterface $scope): self
144+
public function addScope(ScopeEntityInterface $scope): void
150145
{
151146
if (! $this->scopes->contains($scope)) {
152147
$this->scopes->add($scope);
153148
}
154-
155-
return $this;
156149
}
157150

158151
public function removeScope(OAuthScope $scope): self
@@ -178,18 +171,14 @@ public function getExpiryDateTime(): DateTimeImmutable
178171
return $this->expiresAt;
179172
}
180173

181-
public function setExpiryDateTime(DateTimeImmutable $dateTime): self
174+
public function setExpiryDateTime(DateTimeImmutable $dateTime): void
182175
{
183176
$this->expiresAt = $dateTime;
184-
185-
return $this;
186177
}
187178

188-
public function setPrivateKey(CryptKey $privateKey): self
179+
public function setPrivateKey(CryptKeyInterface $privateKey): void
189180
{
190181
$this->privateKey = $privateKey;
191-
192-
return $this;
193182
}
194183

195184
public function initJwtConfiguration(): self
@@ -238,4 +227,9 @@ public function __toString(): string
238227
{
239228
return $this->convertToJWT()->toString();
240229
}
230+
231+
public function toString(): string
232+
{
233+
return $this->convertToJWT()->toString();
234+
}
241235
}

src/Core/src/Security/src/Entity/OAuthAuthCode.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ public function __construct()
4848
$this->scopes = new ArrayCollection();
4949
}
5050

51-
public function setClient(ClientEntityInterface $client): self
51+
public function setClient(ClientEntityInterface $client): void
5252
{
5353
$this->client = $client;
54-
55-
return $this;
5654
}
5755

5856
public function getClient(): ClientEntityInterface
@@ -68,19 +66,17 @@ public function getIdentifier(): string
6866
/**
6967
* @param mixed $identifier
7068
*/
71-
public function setIdentifier($identifier): self
69+
public function setIdentifier($identifier): void
7270
{
7371
$this->setId($identifier);
74-
75-
return $this;
7672
}
7773

7874
/**
7975
* @param string|int|null $identifier
8076
*/
81-
public function setUserIdentifier($identifier): self
77+
public function setUserIdentifier($identifier): void
8278
{
83-
return $this;
79+
$this->setUserIdentifier($identifier);
8480
}
8581

8682
public function getUserIdentifier(): ?string
@@ -114,13 +110,11 @@ public function revoke(): self
114110
return $this;
115111
}
116112

117-
public function addScope(ScopeEntityInterface $scope): self
113+
public function addScope(ScopeEntityInterface $scope): void
118114
{
119115
if (! $this->scopes->contains($scope)) {
120116
$this->scopes->add($scope);
121117
}
122-
123-
return $this;
124118
}
125119

126120
public function removeScope(ScopeEntityInterface $scope): self
@@ -156,8 +150,8 @@ public function getExpiryDateTime(): DateTimeImmutable
156150
return $this->getExpiresDatetime();
157151
}
158152

159-
public function setExpiryDateTime(DateTimeImmutable $dateTime): self
153+
public function setExpiryDateTime(DateTimeImmutable $dateTime): void
160154
{
161-
return $this->setExpiresDatetime($dateTime);
155+
$this->setExpiresDatetime($dateTime);
162156
}
163157
}

src/Core/src/Security/src/Entity/OAuthClient.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ class OAuthClient implements ClientEntityInterface
1616
{
1717
use NumericIdentifierTrait;
1818

19-
public const NAME_ADMIN = 'admin';
20-
public const NAME_FRONTEND = 'frontend';
19+
public const string NAME_ADMIN = 'admin';
20+
public const string NAME_FRONTEND = 'frontend';
2121

2222
#[ORM\ManyToOne(targetEntity: User::class)]
2323
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true)]
2424
private ?User $user = null;
2525

26+
/** @var non-empty-string */
2627
#[ORM\Column(name: 'name', type: 'string', length: 40)]
2728
private string $name;
2829

@@ -55,18 +56,25 @@ public function getIdentity(): string
5556
return $this->getName();
5657
}
5758

59+
/**
60+
* @return non-empty-string
61+
*/
5862
public function getIdentifier(): string
5963
{
6064
return $this->getName();
6165
}
6266

67+
/** @param non-empty-string $name */
6368
public function setName(string $name): self
6469
{
6570
$this->name = $name;
6671

6772
return $this;
6873
}
6974

75+
/**
76+
* @return non-empty-string
77+
*/
7078
public function getName(): string
7179
{
7280
return $this->name;
@@ -96,7 +104,7 @@ public function getRedirect(): string
96104
return $this->redirect;
97105
}
98106

99-
public function getRedirectUri(): ?string
107+
public function getRedirectUri(): string
100108
{
101109
return $this->getRedirect();
102110
}

src/Core/src/Security/src/Entity/OAuthRefreshToken.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,13 @@ public function getIdentifier(): string
3232
return (string) $this->getId();
3333
}
3434

35-
public function setIdentifier(mixed $identifier): self
35+
public function setIdentifier(mixed $identifier): void
3636
{
37-
return $this;
3837
}
3938

40-
public function setAccessToken(AccessTokenEntityInterface $accessToken): self
39+
public function setAccessToken(AccessTokenEntityInterface $accessToken): void
4140
{
4241
$this->accessToken = $accessToken;
43-
44-
return $this;
4542
}
4643

4744
public function getAccessToken(): OAuthAccessToken|AccessTokenEntityInterface
@@ -73,10 +70,8 @@ public function getExpiryDateTime(): DateTimeImmutable
7370
return $this->expiresAt;
7471
}
7572

76-
public function setExpiryDateTime(DateTimeImmutable $dateTime): self
73+
public function setExpiryDateTime(DateTimeImmutable $dateTime): void
7774
{
7875
$this->expiresAt = $dateTime;
79-
80-
return $this;
8176
}
8277
}

0 commit comments

Comments
 (0)