Skip to content

Commit 8264a40

Browse files
committed
Revert identifiers to strings
1 parent 6dbbc9f commit 8264a40

19 files changed

+67
-67
lines changed

src/Entities/ClientEntityInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ interface ClientEntityInterface
1717
/**
1818
* Get the client's identifier.
1919
*
20-
* @return int|non-empty-string
20+
* @return non-empty-string
2121
*/
22-
public function getIdentifier(): int|string;
22+
public function getIdentifier(): string;
2323

2424
/**
2525
* Get the client's name.

src/Entities/RefreshTokenEntityInterface.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ interface RefreshTokenEntityInterface
1919
/**
2020
* Get the token's identifier.
2121
*
22-
* @return int|non-empty-string
22+
* @return non-empty-string
2323
*/
24-
public function getIdentifier(): int|string;
24+
public function getIdentifier(): string;
2525

2626
/**
2727
* Set the token's identifier.
2828
*
29-
* @param int|non-empty-string $identifier
29+
* @param non-empty-string $identifier
3030
*/
31-
public function setIdentifier(int|string $identifier): void;
31+
public function setIdentifier(string $identifier): void;
3232

3333
/**
3434
* Get the token's expiry date time.

src/Entities/ScopeEntityInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface ScopeEntityInterface extends JsonSerializable
1919
/**
2020
* Get the scope's identifier.
2121
*
22-
* @return int|non-empty-string
22+
* @return non-empty-string
2323
*/
24-
public function getIdentifier(): int|string;
24+
public function getIdentifier(): string;
2525
}

src/Entities/TokenInterface.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ interface TokenInterface
1919
/**
2020
* Get the token's identifier.
2121
*
22-
* @return int|non-empty-string
22+
* @return non-empty-string
2323
*/
24-
public function getIdentifier(): int|string;
24+
public function getIdentifier(): string;
2525

2626
/**
2727
* Set the token's identifier.
2828
*
29-
* @param int|non-empty-string $identifier
29+
* @param non-empty-string $identifier
3030
*/
31-
public function setIdentifier(int|string $identifier): void;
31+
public function setIdentifier(string $identifier): void;
3232

3333
/**
3434
* Get the token's expiry date time.
@@ -43,16 +43,16 @@ public function setExpiryDateTime(DateTimeImmutable $dateTime): void;
4343
/**
4444
* Set the identifier of the user associated with the token.
4545
*
46-
* @param non-empty-string|int $identifier
46+
* @param non-empty-string $identifier
4747
*/
48-
public function setUserIdentifier(string|int $identifier): void;
48+
public function setUserIdentifier(string $identifier): void;
4949

5050
/**
5151
* Get the token user's identifier.
5252
*
53-
* @return non-empty-string|int|null
53+
* @return non-empty-string|null
5454
*/
55-
public function getUserIdentifier(): string|int|null;
55+
public function getUserIdentifier(): string|null;
5656

5757
/**
5858
* Get the client that the token was issued to.

src/Entities/Traits/AccessTokenTrait.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ private function convertToJWT(): Token
6262
$this->initJwtConfiguration();
6363

6464
return $this->jwtConfiguration->builder()
65-
->permittedFor((string) $this->getClient()->getIdentifier())
66-
->identifiedBy((string) $this->getIdentifier())
65+
->permittedFor($this->getClient()->getIdentifier())
66+
->identifiedBy($this->getIdentifier())
6767
->issuedAt(new DateTimeImmutable())
6868
->canOnlyBeUsedAfter(new DateTimeImmutable())
6969
->expiresAt($this->getExpiryDateTime())
70-
->relatedTo((string) $this->getSubjectIdentifier())
70+
->relatedTo($this->getSubjectIdentifier())
7171
->withClaim('scopes', $this->getScopes())
7272
->getToken($this->jwtConfiguration->signer(), $this->jwtConfiguration->signingKey());
7373
}
@@ -85,24 +85,24 @@ abstract public function getClient(): ClientEntityInterface;
8585
abstract public function getExpiryDateTime(): DateTimeImmutable;
8686

8787
/**
88-
* @return non-empty-string|int|null
88+
* @return non-empty-string|null
8989
*/
90-
abstract public function getUserIdentifier(): string|int|null;
90+
abstract public function getUserIdentifier(): string|null;
9191

9292
/**
9393
* @return ScopeEntityInterface[]
9494
*/
9595
abstract public function getScopes(): array;
9696

9797
/**
98-
* @return int|non-empty-string
98+
* @return non-empty-string
9999
*/
100-
abstract public function getIdentifier(): int|string;
100+
abstract public function getIdentifier(): string;
101101

102102
/**
103-
* @return int|non-empty-string
103+
* @return non-empty-string
104104
*/
105-
private function getSubjectIdentifier(): int|string
105+
private function getSubjectIdentifier(): string
106106
{
107107
return $this->getUserIdentifier() ?? $this->getClient()->getIdentifier();
108108
}

src/Entities/Traits/DeviceCodeTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ abstract public function getExpiryDateTime(): DateTimeImmutable;
6060
abstract public function getScopes(): array;
6161

6262
/**
63-
* @return int|non-empty-string
63+
* @return non-empty-string
6464
*/
65-
abstract public function getIdentifier(): int|string;
65+
abstract public function getIdentifier(): string;
6666

6767
public function getLastPolledAt(): ?DateTimeImmutable
6868
{

src/Entities/Traits/EntityTrait.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@
1515
trait EntityTrait
1616
{
1717
/**
18-
* @var int|non-empty-string
18+
* @var non-empty-string
1919
*/
20-
protected int|string $identifier;
20+
protected string $identifier;
2121

2222
/**
23-
* @return int|non-empty-string
23+
* @return non-empty-string
2424
*/
25-
public function getIdentifier(): int|string
25+
public function getIdentifier(): string
2626
{
2727
return $this->identifier;
2828
}
2929

3030
/**
31-
* @param int|non-empty-string $identifier
31+
* @param non-empty-string $identifier
3232
*/
33-
public function setIdentifier(int|string $identifier): void
33+
public function setIdentifier(string $identifier): void
3434
{
3535
$this->identifier = $identifier;
3636
}

src/Entities/Traits/TokenEntityTrait.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ trait TokenEntityTrait
2828
protected DateTimeImmutable $expiryDateTime;
2929

3030
/**
31-
* @var non-empty-string|int|null
31+
* @var non-empty-string|null
3232
*/
33-
protected string|int|null $userIdentifier = null;
33+
protected string|null $userIdentifier = null;
3434

3535
protected ClientEntityInterface $client;
3636

@@ -71,19 +71,19 @@ public function setExpiryDateTime(DateTimeImmutable $dateTime): void
7171
/**
7272
* Set the identifier of the user associated with the token.
7373
*
74-
* @param int|non-empty-string $identifier The identifier of the user
74+
* @param non-empty-string $identifier The identifier of the user
7575
*/
76-
public function setUserIdentifier(int|string $identifier): void
76+
public function setUserIdentifier(string $identifier): void
7777
{
7878
$this->userIdentifier = $identifier;
7979
}
8080

8181
/**
8282
* Get the token user's identifier.
8383
*
84-
* @return non-empty-string|int|null
84+
* @return non-empty-string|null
8585
*/
86-
public function getUserIdentifier(): string|int|null
86+
public function getUserIdentifier(): string|null
8787
{
8888
return $this->userIdentifier;
8989
}

src/Exception/OAuthServerException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static function invalidClient(ServerRequestInterface $serverRequest): sta
114114
/**
115115
* Invalid scope error
116116
*/
117-
public static function invalidScope(int|string $scopeId, string|null $redirectUri = null): static
117+
public static function invalidScope(string $scopeId, string|null $redirectUri = null): static
118118
{
119119
$errorMessage = 'The requested scope is invalid, unknown, or malformed';
120120

@@ -123,7 +123,7 @@ public static function invalidScope(int|string $scopeId, string|null $redirectUr
123123
} else {
124124
$hint = sprintf(
125125
'Check the `%s` scope',
126-
htmlspecialchars((string) $scopeId, ENT_QUOTES, 'UTF-8', false)
126+
htmlspecialchars($scopeId, ENT_QUOTES, 'UTF-8', false)
127127
);
128128
}
129129

src/Grant/AbstractGrant.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ protected function validateClient(ServerRequestInterface $request): ClientEntity
184184
* getClientEntity might return null. By contrast, this method will
185185
* always either return a ClientEntityInterface or throw.
186186
*/
187-
protected function getClientEntityOrFail(string|int $clientId, ServerRequestInterface $request): ClientEntityInterface
187+
protected function getClientEntityOrFail(string $clientId, ServerRequestInterface $request): ClientEntityInterface
188188
{
189189
$client = $this->clientRepository->getClientEntity($clientId);
190190

@@ -362,7 +362,7 @@ protected function getServerParameter(string $parameter, ServerRequestInterface
362362
protected function issueAccessToken(
363363
DateInterval $accessTokenTTL,
364364
ClientEntityInterface $client,
365-
string|int|null $userIdentifier,
365+
string|null $userIdentifier,
366366
array $scopes = []
367367
): AccessTokenEntityInterface {
368368
$maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS;

src/Grant/DeviceCodeGrant.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ public function respondToAccessTokenRequest(
153153
}
154154

155155
// Finalize the requested scopes
156-
$finalizedScopes = $this->scopeRepository->finalizeScopes($scopes, $this->getIdentifier(), $client, (string) $deviceCodeEntity->getUserIdentifier());
156+
$finalizedScopes = $this->scopeRepository->finalizeScopes($scopes, $this->getIdentifier(), $client, $deviceCodeEntity->getUserIdentifier());
157157

158158
// Issue and persist new access token
159-
$accessToken = $this->issueAccessToken($accessTokenTTL, $client, (string) $deviceCodeEntity->getUserIdentifier(), $finalizedScopes);
159+
$accessToken = $this->issueAccessToken($accessTokenTTL, $client, $deviceCodeEntity->getUserIdentifier(), $finalizedScopes);
160160
$this->getEmitter()->emit(new RequestEvent(RequestEvent::ACCESS_TOKEN_ISSUED, $request));
161161
$responseType->setAccessToken($accessToken);
162162

src/Grant/RefreshTokenGrant.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function respondToAccessTokenRequest(
101101
*
102102
* @return array<string, mixed>
103103
*/
104-
protected function validateOldRefreshToken(ServerRequestInterface $request, int|string $clientId): array
104+
protected function validateOldRefreshToken(ServerRequestInterface $request, string $clientId): array
105105
{
106106
$encryptedRefreshToken = $this->getRequestParameter('refresh_token', $request);
107107
if (!is_string($encryptedRefreshToken)) {

src/Repositories/AccessTokenRepositoryInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface AccessTokenRepositoryInterface extends RepositoryInterface
3030
public function getNewToken(
3131
ClientEntityInterface $clientEntity,
3232
array $scopes,
33-
string|int|null $userIdentifier = null
33+
string|null $userIdentifier = null
3434
): AccessTokenEntityInterface;
3535

3636
/**

src/Repositories/ClientRepositoryInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ interface ClientRepositoryInterface extends RepositoryInterface
2222
/**
2323
* Get a client.
2424
*/
25-
public function getClientEntity(string|int $clientIdentifier): ?ClientEntityInterface;
25+
public function getClientEntity(string $clientIdentifier): ?ClientEntityInterface;
2626

2727
/**
2828
* Validate a client's secret.
2929
*/
30-
public function validateClient(string|int $clientIdentifier, ?string $clientSecret, ?string $grantType): bool;
30+
public function validateClient(string $clientIdentifier, ?string $clientSecret, ?string $grantType): bool;
3131
}

src/Repositories/DeviceCodeRepositoryInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function getDeviceCodeEntityByDeviceCode(
3939
/**
4040
* Revoke a device code.
4141
*/
42-
public function revokeDeviceCode(int|string $codeId): void;
42+
public function revokeDeviceCode(string $codeId): void;
4343

4444
/**
4545
* Check if the device code has been revoked.

tests/Grant/AbstractGrantTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public function testIssueAccessToken(): void
432432
$grantMock,
433433
new DateInterval('PT1H'),
434434
new ClientEntity(),
435-
123,
435+
'123',
436436
[new ScopeEntity()]
437437
);
438438

tests/Grant/AuthCodeGrantTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ public function testRespondToAccessTokenRequest(): void
602602
'auth_code_id' => uniqid(),
603603
'expire_time' => time() + 3600,
604604
'client_id' => 'foo',
605-
'user_id' => 123,
605+
'user_id' => '123',
606606
'scopes' => ['foo'],
607607
'redirect_uri' => self::REDIRECT_URI,
608608
], JSON_THROW_ON_ERROR)
@@ -665,7 +665,7 @@ public function testRespondToAccessTokenRequestUsingHttpBasicAuth(): void
665665
'auth_code_id' => uniqid(),
666666
'client_id' => 'foo',
667667
'expire_time' => time() + 3600,
668-
'user_id' => 123,
668+
'user_id' => '123',
669669
'scopes' => ['foo'],
670670
'redirect_uri' => self::REDIRECT_URI,
671671
], JSON_THROW_ON_ERROR)
@@ -730,7 +730,7 @@ public function testRespondToAccessTokenRequestForPublicClient(): void
730730
'auth_code_id' => uniqid(),
731731
'expire_time' => time() + 3600,
732732
'client_id' => 'foo',
733-
'user_id' => 123,
733+
'user_id' => '123',
734734
'scopes' => ['foo'],
735735
'redirect_uri' => self::REDIRECT_URI,
736736
], JSON_THROW_ON_ERROR)
@@ -795,7 +795,7 @@ public function testRespondToAccessTokenRequestNullRefreshToken(): void
795795
'auth_code_id' => uniqid(),
796796
'expire_time' => time() + 3600,
797797
'client_id' => 'foo',
798-
'user_id' => 123,
798+
'user_id' => '123',
799799
'scopes' => ['foo'],
800800
'redirect_uri' => self::REDIRECT_URI,
801801
], JSON_THROW_ON_ERROR)
@@ -867,7 +867,7 @@ public function testRespondToAccessTokenRequestCodeChallengePlain(): void
867867
'auth_code_id' => uniqid(),
868868
'expire_time' => time() + 3600,
869869
'client_id' => 'foo',
870-
'user_id' => 123,
870+
'user_id' => '123',
871871
'scopes' => ['foo'],
872872
'redirect_uri' => self::REDIRECT_URI,
873873
'code_challenge' => self::CODE_VERIFIER,
@@ -941,7 +941,7 @@ public function testRespondToAccessTokenRequestCodeChallengeS256(): void
941941
'auth_code_id' => uniqid(),
942942
'expire_time' => time() + 3600,
943943
'client_id' => 'foo',
944-
'user_id' => 123,
944+
'user_id' => '123',
945945
'scopes' => ['foo'],
946946
'redirect_uri' => self::REDIRECT_URI,
947947
'code_challenge' => self::CODE_CHALLENGE,
@@ -2034,7 +2034,7 @@ public function testRefreshTokenRepositoryUniqueConstraintCheck(): void
20342034
'auth_code_id' => uniqid(),
20352035
'expire_time' => time() + 3600,
20362036
'client_id' => 'foo',
2037-
'user_id' => 123,
2037+
'user_id' => '123',
20382038
'scopes' => ['foo'],
20392039
'redirect_uri' => self::REDIRECT_URI,
20402040
], JSON_THROW_ON_ERROR)
@@ -2099,7 +2099,7 @@ public function testRefreshTokenRepositoryFailToPersist(): void
20992099
'auth_code_id' => uniqid(),
21002100
'expire_time' => time() + 3600,
21012101
'client_id' => 'foo',
2102-
'user_id' => 123,
2102+
'user_id' => '123',
21032103
'scopes' => ['foo'],
21042104
'redirect_uri' => self::REDIRECT_URI,
21052105
], JSON_THROW_ON_ERROR)
@@ -2167,7 +2167,7 @@ public function testRefreshTokenRepositoryFailToPersistUniqueNoInfiniteLoop(): v
21672167
'auth_code_id' => uniqid(),
21682168
'expire_time' => time() + 3600,
21692169
'client_id' => 'foo',
2170-
'user_id' => 123,
2170+
'user_id' => '123',
21712171
'scopes' => ['foo'],
21722172
'redirect_uri' => self::REDIRECT_URI,
21732173
], JSON_THROW_ON_ERROR)

0 commit comments

Comments
 (0)