Skip to content

Commit

Permalink
Revert identifiers to strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Sephster committed Apr 22, 2024
1 parent 6dbbc9f commit 8264a40
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 67 deletions.
4 changes: 2 additions & 2 deletions src/Entities/ClientEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ interface ClientEntityInterface
/**
* Get the client's identifier.
*
* @return int|non-empty-string
* @return non-empty-string
*/
public function getIdentifier(): int|string;
public function getIdentifier(): string;

/**
* Get the client's name.
Expand Down
8 changes: 4 additions & 4 deletions src/Entities/RefreshTokenEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ interface RefreshTokenEntityInterface
/**
* Get the token's identifier.
*
* @return int|non-empty-string
* @return non-empty-string
*/
public function getIdentifier(): int|string;
public function getIdentifier(): string;

/**
* Set the token's identifier.
*
* @param int|non-empty-string $identifier
* @param non-empty-string $identifier
*/
public function setIdentifier(int|string $identifier): void;
public function setIdentifier(string $identifier): void;

/**
* Get the token's expiry date time.
Expand Down
4 changes: 2 additions & 2 deletions src/Entities/ScopeEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface ScopeEntityInterface extends JsonSerializable
/**
* Get the scope's identifier.
*
* @return int|non-empty-string
* @return non-empty-string
*/
public function getIdentifier(): int|string;
public function getIdentifier(): string;
}
16 changes: 8 additions & 8 deletions src/Entities/TokenInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ interface TokenInterface
/**
* Get the token's identifier.
*
* @return int|non-empty-string
* @return non-empty-string
*/
public function getIdentifier(): int|string;
public function getIdentifier(): string;

/**
* Set the token's identifier.
*
* @param int|non-empty-string $identifier
* @param non-empty-string $identifier
*/
public function setIdentifier(int|string $identifier): void;
public function setIdentifier(string $identifier): void;

/**
* Get the token's expiry date time.
Expand All @@ -43,16 +43,16 @@ public function setExpiryDateTime(DateTimeImmutable $dateTime): void;
/**
* Set the identifier of the user associated with the token.
*
* @param non-empty-string|int $identifier
* @param non-empty-string $identifier
*/
public function setUserIdentifier(string|int $identifier): void;
public function setUserIdentifier(string $identifier): void;

/**
* Get the token user's identifier.
*
* @return non-empty-string|int|null
* @return non-empty-string|null
*/
public function getUserIdentifier(): string|int|null;
public function getUserIdentifier(): string|null;

/**
* Get the client that the token was issued to.
Expand Down
18 changes: 9 additions & 9 deletions src/Entities/Traits/AccessTokenTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ private function convertToJWT(): Token
$this->initJwtConfiguration();

return $this->jwtConfiguration->builder()
->permittedFor((string) $this->getClient()->getIdentifier())
->identifiedBy((string) $this->getIdentifier())
->permittedFor($this->getClient()->getIdentifier())
->identifiedBy($this->getIdentifier())
->issuedAt(new DateTimeImmutable())
->canOnlyBeUsedAfter(new DateTimeImmutable())
->expiresAt($this->getExpiryDateTime())
->relatedTo((string) $this->getSubjectIdentifier())
->relatedTo($this->getSubjectIdentifier())
->withClaim('scopes', $this->getScopes())
->getToken($this->jwtConfiguration->signer(), $this->jwtConfiguration->signingKey());
}
Expand All @@ -85,24 +85,24 @@ abstract public function getClient(): ClientEntityInterface;
abstract public function getExpiryDateTime(): DateTimeImmutable;

/**
* @return non-empty-string|int|null
* @return non-empty-string|null
*/
abstract public function getUserIdentifier(): string|int|null;
abstract public function getUserIdentifier(): string|null;

/**
* @return ScopeEntityInterface[]
*/
abstract public function getScopes(): array;

/**
* @return int|non-empty-string
* @return non-empty-string
*/
abstract public function getIdentifier(): int|string;
abstract public function getIdentifier(): string;

/**
* @return int|non-empty-string
* @return non-empty-string
*/
private function getSubjectIdentifier(): int|string
private function getSubjectIdentifier(): string
{
return $this->getUserIdentifier() ?? $this->getClient()->getIdentifier();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Entities/Traits/DeviceCodeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ abstract public function getExpiryDateTime(): DateTimeImmutable;
abstract public function getScopes(): array;

/**
* @return int|non-empty-string
* @return non-empty-string
*/
abstract public function getIdentifier(): int|string;
abstract public function getIdentifier(): string;

public function getLastPolledAt(): ?DateTimeImmutable
{
Expand Down
12 changes: 6 additions & 6 deletions src/Entities/Traits/EntityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
trait EntityTrait
{
/**
* @var int|non-empty-string
* @var non-empty-string
*/
protected int|string $identifier;
protected string $identifier;

/**
* @return int|non-empty-string
* @return non-empty-string
*/
public function getIdentifier(): int|string
public function getIdentifier(): string
{
return $this->identifier;
}

/**
* @param int|non-empty-string $identifier
* @param non-empty-string $identifier
*/
public function setIdentifier(int|string $identifier): void
public function setIdentifier(string $identifier): void
{
$this->identifier = $identifier;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Entities/Traits/TokenEntityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ trait TokenEntityTrait
protected DateTimeImmutable $expiryDateTime;

/**
* @var non-empty-string|int|null
* @var non-empty-string|null
*/
protected string|int|null $userIdentifier = null;
protected string|null $userIdentifier = null;

protected ClientEntityInterface $client;

Expand Down Expand Up @@ -71,19 +71,19 @@ public function setExpiryDateTime(DateTimeImmutable $dateTime): void
/**
* Set the identifier of the user associated with the token.
*
* @param int|non-empty-string $identifier The identifier of the user
* @param non-empty-string $identifier The identifier of the user
*/
public function setUserIdentifier(int|string $identifier): void
public function setUserIdentifier(string $identifier): void
{
$this->userIdentifier = $identifier;
}

/**
* Get the token user's identifier.
*
* @return non-empty-string|int|null
* @return non-empty-string|null
*/
public function getUserIdentifier(): string|int|null
public function getUserIdentifier(): string|null
{
return $this->userIdentifier;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/OAuthServerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function invalidClient(ServerRequestInterface $serverRequest): sta
/**
* Invalid scope error
*/
public static function invalidScope(int|string $scopeId, string|null $redirectUri = null): static
public static function invalidScope(string $scopeId, string|null $redirectUri = null): static
{
$errorMessage = 'The requested scope is invalid, unknown, or malformed';

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

Expand Down
4 changes: 2 additions & 2 deletions src/Grant/AbstractGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected function validateClient(ServerRequestInterface $request): ClientEntity
* getClientEntity might return null. By contrast, this method will
* always either return a ClientEntityInterface or throw.
*/
protected function getClientEntityOrFail(string|int $clientId, ServerRequestInterface $request): ClientEntityInterface
protected function getClientEntityOrFail(string $clientId, ServerRequestInterface $request): ClientEntityInterface
{
$client = $this->clientRepository->getClientEntity($clientId);

Expand Down Expand Up @@ -362,7 +362,7 @@ protected function getServerParameter(string $parameter, ServerRequestInterface
protected function issueAccessToken(
DateInterval $accessTokenTTL,
ClientEntityInterface $client,
string|int|null $userIdentifier,
string|null $userIdentifier,
array $scopes = []
): AccessTokenEntityInterface {
$maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS;
Expand Down
4 changes: 2 additions & 2 deletions src/Grant/DeviceCodeGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ public function respondToAccessTokenRequest(
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/Grant/RefreshTokenGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function respondToAccessTokenRequest(
*
* @return array<string, mixed>
*/
protected function validateOldRefreshToken(ServerRequestInterface $request, int|string $clientId): array
protected function validateOldRefreshToken(ServerRequestInterface $request, string $clientId): array
{
$encryptedRefreshToken = $this->getRequestParameter('refresh_token', $request);
if (!is_string($encryptedRefreshToken)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/AccessTokenRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface AccessTokenRepositoryInterface extends RepositoryInterface
public function getNewToken(
ClientEntityInterface $clientEntity,
array $scopes,
string|int|null $userIdentifier = null
string|null $userIdentifier = null
): AccessTokenEntityInterface;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Repositories/ClientRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ interface ClientRepositoryInterface extends RepositoryInterface
/**
* Get a client.
*/
public function getClientEntity(string|int $clientIdentifier): ?ClientEntityInterface;
public function getClientEntity(string $clientIdentifier): ?ClientEntityInterface;

/**
* Validate a client's secret.
*/
public function validateClient(string|int $clientIdentifier, ?string $clientSecret, ?string $grantType): bool;
public function validateClient(string $clientIdentifier, ?string $clientSecret, ?string $grantType): bool;
}
2 changes: 1 addition & 1 deletion src/Repositories/DeviceCodeRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getDeviceCodeEntityByDeviceCode(
/**
* Revoke a device code.
*/
public function revokeDeviceCode(int|string $codeId): void;
public function revokeDeviceCode(string $codeId): void;

/**
* Check if the device code has been revoked.
Expand Down
2 changes: 1 addition & 1 deletion tests/Grant/AbstractGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public function testIssueAccessToken(): void
$grantMock,
new DateInterval('PT1H'),
new ClientEntity(),
123,
'123',
[new ScopeEntity()]
);

Expand Down
18 changes: 9 additions & 9 deletions tests/Grant/AuthCodeGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public function testRespondToAccessTokenRequest(): void
'auth_code_id' => uniqid(),
'expire_time' => time() + 3600,
'client_id' => 'foo',
'user_id' => 123,
'user_id' => '123',
'scopes' => ['foo'],
'redirect_uri' => self::REDIRECT_URI,
], JSON_THROW_ON_ERROR)
Expand Down Expand Up @@ -665,7 +665,7 @@ public function testRespondToAccessTokenRequestUsingHttpBasicAuth(): void
'auth_code_id' => uniqid(),
'client_id' => 'foo',
'expire_time' => time() + 3600,
'user_id' => 123,
'user_id' => '123',
'scopes' => ['foo'],
'redirect_uri' => self::REDIRECT_URI,
], JSON_THROW_ON_ERROR)
Expand Down Expand Up @@ -730,7 +730,7 @@ public function testRespondToAccessTokenRequestForPublicClient(): void
'auth_code_id' => uniqid(),
'expire_time' => time() + 3600,
'client_id' => 'foo',
'user_id' => 123,
'user_id' => '123',
'scopes' => ['foo'],
'redirect_uri' => self::REDIRECT_URI,
], JSON_THROW_ON_ERROR)
Expand Down Expand Up @@ -795,7 +795,7 @@ public function testRespondToAccessTokenRequestNullRefreshToken(): void
'auth_code_id' => uniqid(),
'expire_time' => time() + 3600,
'client_id' => 'foo',
'user_id' => 123,
'user_id' => '123',
'scopes' => ['foo'],
'redirect_uri' => self::REDIRECT_URI,
], JSON_THROW_ON_ERROR)
Expand Down Expand Up @@ -867,7 +867,7 @@ public function testRespondToAccessTokenRequestCodeChallengePlain(): void
'auth_code_id' => uniqid(),
'expire_time' => time() + 3600,
'client_id' => 'foo',
'user_id' => 123,
'user_id' => '123',
'scopes' => ['foo'],
'redirect_uri' => self::REDIRECT_URI,
'code_challenge' => self::CODE_VERIFIER,
Expand Down Expand Up @@ -941,7 +941,7 @@ public function testRespondToAccessTokenRequestCodeChallengeS256(): void
'auth_code_id' => uniqid(),
'expire_time' => time() + 3600,
'client_id' => 'foo',
'user_id' => 123,
'user_id' => '123',
'scopes' => ['foo'],
'redirect_uri' => self::REDIRECT_URI,
'code_challenge' => self::CODE_CHALLENGE,
Expand Down Expand Up @@ -2034,7 +2034,7 @@ public function testRefreshTokenRepositoryUniqueConstraintCheck(): void
'auth_code_id' => uniqid(),
'expire_time' => time() + 3600,
'client_id' => 'foo',
'user_id' => 123,
'user_id' => '123',
'scopes' => ['foo'],
'redirect_uri' => self::REDIRECT_URI,
], JSON_THROW_ON_ERROR)
Expand Down Expand Up @@ -2099,7 +2099,7 @@ public function testRefreshTokenRepositoryFailToPersist(): void
'auth_code_id' => uniqid(),
'expire_time' => time() + 3600,
'client_id' => 'foo',
'user_id' => 123,
'user_id' => '123',
'scopes' => ['foo'],
'redirect_uri' => self::REDIRECT_URI,
], JSON_THROW_ON_ERROR)
Expand Down Expand Up @@ -2167,7 +2167,7 @@ public function testRefreshTokenRepositoryFailToPersistUniqueNoInfiniteLoop(): v
'auth_code_id' => uniqid(),
'expire_time' => time() + 3600,
'client_id' => 'foo',
'user_id' => 123,
'user_id' => '123',
'scopes' => ['foo'],
'redirect_uri' => self::REDIRECT_URI,
], JSON_THROW_ON_ERROR)
Expand Down
Loading

0 comments on commit 8264a40

Please sign in to comment.