[PLUGIN][OAuth2] Fix some static issues

This commit is contained in:
2022-02-04 18:34:08 +00:00
parent 4dd976eb22
commit 81f6d496c6
15 changed files with 206 additions and 202 deletions

View File

@@ -41,6 +41,10 @@ use Plugin\OAuth2\Entity;
class AccessToken implements AccessTokenRepositoryInterface
{
/**
* @throws \App\Util\Exception\DuplicateFoundException
* @throws \App\Util\Exception\NotFoundException
*/
public function getAccessTokenEntity(string $identifier): Entity\AccessToken
{
return DB::findOneBy(Entity\AccessToken::class, ['id' => $identifier]);
@@ -56,12 +60,12 @@ class AccessToken implements AccessTokenRepositoryInterface
// Some logic here to revoke the access token
}
public function isAccessTokenRevoked($tokenId)
public function isAccessTokenRevoked($tokenId): bool
{
return false; // Access token hasn't been revoked
}
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null)
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null): Entity\AccessToken
{
$accessToken = new Entity\AccessToken();
$accessToken->setClient($clientEntity);

View File

@@ -50,12 +50,12 @@ class AuthCode implements AuthCodeRepositoryInterface
// Some logic to revoke the auth code in a database
}
public function isAuthCodeRevoked($codeId)
public function isAuthCodeRevoked($codeId): bool
{
return false; // The auth code has not been revoked
}
public function getNewAuthCode()
public function getNewAuthCode(): Entity\AuthCode
{
return new Entity\AuthCode();
}

View File

@@ -40,12 +40,12 @@ use Plugin\OAuth2\Entity;
class Client implements ClientRepositoryInterface
{
public function getClientEntity($clientIdentifier)
{
return DB::findOneBy(Entity\Client::class, ['id' => $clientIdentifier]);
}
public function validateClient($clientIdentifier, $clientSecret, $grantType)
/**
* @param string $clientIdentifier
* @param null|string $clientSecret
* @param null|string $grantType
*/
public function validateClient($clientIdentifier, $clientSecret, $grantType): bool
{
try {
/** @var Entity\Client $client */
@@ -58,4 +58,13 @@ class Client implements ClientRepositoryInterface
}
return true;
}
/**
* @throws \App\Util\Exception\DuplicateFoundException
* @throws NotFoundException
*/
public function getClientEntity($clientIdentifier)
{
return DB::findOneBy(Entity\Client::class, ['id' => $clientIdentifier]);
}
}

View File

@@ -40,9 +40,9 @@ use Plugin\OAuth2\Entity;
class RefreshToken implements RefreshTokenRepositoryInterface
{
public function persistNewRefreshToken(RefreshtokenEntityInterface $refreshtokenEntity)
public function persistNewRefreshToken(RefreshtokenEntityInterface $refreshTokenEntity)
{
DB::persist($refreshtokenEntity);
DB::persist($refreshTokenEntity);
}
public function revokeRefreshToken($tokenId)
@@ -50,12 +50,12 @@ class RefreshToken implements RefreshTokenRepositoryInterface
// Some logic to revoke the auth token in a database
}
public function isRefreshtokenRevoked($tokenId)
public function isRefreshtokenRevoked($tokenId): bool
{
return false; // The auth token has not been revoked
}
public function getNewRefreshToken()
public function getNewRefreshToken(): Entity\RefreshToken
{
return new Entity\RefreshToken();
}

View File

@@ -40,9 +40,9 @@ use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
class Scope implements ScopeRepositoryInterface
{
/**
* @return ?ScopeEntityInterface
* @param string $identifier
*/
public function getScopeEntityByIdentifier($scopeIdentifier)
public function getScopeEntityByIdentifier($identifier): ?ScopeEntityInterface
{
$scopes = [
'basic' => [
@@ -62,19 +62,21 @@ class Scope implements ScopeRepositoryInterface
],
];
if (\array_key_exists($scopeIdentifier, $scopes) === false) {
return;
if (\array_key_exists($identifier, $scopes) === false) {
return null;
}
return new class($scopeIdentifier) implements ScopeEntityInterface {
return new class($identifier) implements ScopeEntityInterface {
public function __construct(private string $identifier)
{
}
public function getIdentifier()
public function getIdentifier(): string
{
return $this->identifier;
}
public function jsonSerialize(): mixed
public function jsonSerialize(): string
{
return $this->getIdentifier();
}
@@ -86,7 +88,7 @@ class Scope implements ScopeRepositoryInterface
$grantType,
ClientEntityInterface $clientEntity,
$userIdentifier = null,
) {
): array {
return $scopes;
}
}