Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/AuthorizationServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use SensitiveParameter;

class AuthorizationServer implements EmitterAwareInterface
{
Expand Down Expand Up @@ -61,7 +62,9 @@ public function __construct(
private ClientRepositoryInterface $clientRepository,
private AccessTokenRepositoryInterface $accessTokenRepository,
private ScopeRepositoryInterface $scopeRepository,
#[SensitiveParameter]
CryptKeyInterface|string $privateKey,
#[SensitiveParameter]
Key|string $encryptionKey,
ResponseTypeInterface|null $responseType = null
) {
Expand Down
17 changes: 13 additions & 4 deletions src/CryptKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use LogicException;
use OpenSSLAsymmetricKey;
use SensitiveParameter;

use function decoct;
use function file_get_contents;
Expand All @@ -40,8 +41,12 @@ class CryptKey implements CryptKeyInterface

protected string $keyPath;

public function __construct(string $keyPath, protected ?string $passPhrase = null, bool $keyPermissionsCheck = true)
{
public function __construct(
string $keyPath,
#[SensitiveParameter]
protected ?string $passPhrase = null,
bool $keyPermissionsCheck = true
) {
if (str_starts_with($keyPath, self::FILE_PREFIX) === false && $this->isValidKey($keyPath, $this->passPhrase ?? '')) {
$this->keyContents = $keyPath;
$this->keyPath = '';
Expand Down Expand Up @@ -99,8 +104,12 @@ public function getKeyContents(): string
/**
* Validate key contents.
*/
private function isValidKey(string $contents, string $passPhrase): bool
{
private function isValidKey(
#[SensitiveParameter]
string $contents,
#[SensitiveParameter]
string $passPhrase
): bool {
$privateKey = openssl_pkey_get_private($contents, $passPhrase);

$key = $privateKey instanceof OpenSSLAsymmetricKey ? $privateKey : openssl_pkey_get_public($contents);
Expand Down
7 changes: 5 additions & 2 deletions src/CryptTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Exception;
use InvalidArgumentException;
use LogicException;
use SensitiveParameter;

use function is_string;

Expand Down Expand Up @@ -83,8 +84,10 @@ protected function decrypt(string $encryptedData): string
}
}

public function setEncryptionKey(Key|string|null $key = null): void
{
public function setEncryptionKey(
#[SensitiveParameter]
Key|string|null $key = null
): void {
$this->encryptionKey = $key;
}
}
6 changes: 5 additions & 1 deletion src/Entities/AccessTokenEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
namespace League\OAuth2\Server\Entities;

use League\OAuth2\Server\CryptKeyInterface;
use SensitiveParameter;

interface AccessTokenEntityInterface extends TokenInterface
{
/**
* Set a private key used to encrypt the access token.
*/
public function setPrivateKey(CryptKeyInterface $privateKey): void;
public function setPrivateKey(
#[SensitiveParameter]
CryptKeyInterface $privateKey
): void;

/**
* Generate a string representation of the access token.
Expand Down
7 changes: 5 additions & 2 deletions src/Entities/Traits/AccessTokenTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Entities\ScopeEntityInterface;
use RuntimeException;
use SensitiveParameter;

trait AccessTokenTrait
{
Expand All @@ -31,8 +32,10 @@ trait AccessTokenTrait
/**
* Set the private key used to encrypt this access token.
*/
public function setPrivateKey(CryptKeyInterface $privateKey): void
{
public function setPrivateKey(
#[SensitiveParameter]
CryptKeyInterface $privateKey
): void {
$this->privateKey = $privateKey;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Repositories/AccessTokenRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Entities\ScopeEntityInterface;
use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException;
use SensitiveParameter;

/**
* Access token interface.
Expand All @@ -36,7 +37,10 @@ public function getNewToken(
/**
* @throws UniqueTokenIdentifierConstraintViolationException
*/
public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity): void;
public function persistNewAccessToken(
#[SensitiveParameter]
AccessTokenEntityInterface $accessTokenEntity
): void;

public function revokeAccessToken(string $tokenId): void;

Expand Down
6 changes: 5 additions & 1 deletion src/Repositories/AuthCodeRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use League\OAuth2\Server\Entities\AuthCodeEntityInterface;
use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException;
use SensitiveParameter;

/**
* Auth code storage interface.
Expand All @@ -25,7 +26,10 @@ public function getNewAuthCode(): AuthCodeEntityInterface;
/**
* @throws UniqueTokenIdentifierConstraintViolationException
*/
public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity): void;
public function persistNewAuthCode(
#[SensitiveParameter]
AuthCodeEntityInterface $authCodeEntity
): void;

public function revokeAuthCode(string $codeId): void;

Expand Down
8 changes: 7 additions & 1 deletion src/Repositories/ClientRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace League\OAuth2\Server\Repositories;

use League\OAuth2\Server\Entities\ClientEntityInterface;
use SensitiveParameter;

/**
* Client storage interface.
Expand All @@ -27,5 +28,10 @@ public function getClientEntity(string $clientIdentifier): ?ClientEntityInterfac
/**
* Validate a client's secret.
*/
public function validateClient(string $clientIdentifier, ?string $clientSecret, ?string $grantType): bool;
public function validateClient(
string $clientIdentifier,
#[SensitiveParameter]
?string $clientSecret,
?string $grantType
): bool;
}
6 changes: 5 additions & 1 deletion src/Repositories/RefreshTokenRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException;
use SensitiveParameter;

/**
* Refresh token interface.
Expand All @@ -25,7 +26,10 @@ public function getNewRefreshToken(): ?RefreshTokenEntityInterface;
/**
* @throws UniqueTokenIdentifierConstraintViolationException
*/
public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity): void;
public function persistNewRefreshToken(
#[SensitiveParameter]
RefreshTokenEntityInterface $refreshTokenEntity
): void;

public function revokeRefreshToken(string $tokenId): void;

Expand Down
2 changes: 2 additions & 0 deletions src/Repositories/UserRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Entities\UserEntityInterface;
use SensitiveParameter;

interface UserRepositoryInterface extends RepositoryInterface
{
Expand All @@ -22,6 +23,7 @@ interface UserRepositoryInterface extends RepositoryInterface
*/
public function getUserEntityByUserCredentials(
string $username,
#[SensitiveParameter]
string $password,
string $grantType,
ClientEntityInterface $clientEntity
Expand Down
9 changes: 7 additions & 2 deletions src/RequestAccessTokenEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@

use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
use Psr\Http\Message\ServerRequestInterface;
use SensitiveParameter;

class RequestAccessTokenEvent extends RequestEvent
{
public function __construct(string $name, ServerRequestInterface $request, private AccessTokenEntityInterface $accessToken)
{
public function __construct(
string $name,
ServerRequestInterface $request,
#[SensitiveParameter]
private AccessTokenEntityInterface $accessToken
) {
parent::__construct($name, $request);
}

Expand Down
9 changes: 7 additions & 2 deletions src/RequestRefreshTokenEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@

use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
use Psr\Http\Message\ServerRequestInterface;
use SensitiveParameter;

class RequestRefreshTokenEvent extends RequestEvent
{
public function __construct(string $name, ServerRequestInterface $request, private RefreshTokenEntityInterface $refreshToken)
{
public function __construct(
string $name,
ServerRequestInterface $request,
#[SensitiveParameter]
private RefreshTokenEntityInterface $refreshToken
) {
parent::__construct($name, $request);
}

Expand Down
19 changes: 13 additions & 6 deletions src/ResponseTypes/AbstractResponseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use League\OAuth2\Server\CryptTrait;
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
use SensitiveParameter;

abstract class AbstractResponseType implements ResponseTypeInterface
{
Expand All @@ -29,18 +30,24 @@ abstract class AbstractResponseType implements ResponseTypeInterface

protected CryptKeyInterface $privateKey;

public function setAccessToken(AccessTokenEntityInterface $accessToken): void
{
public function setAccessToken(
#[SensitiveParameter]
AccessTokenEntityInterface $accessToken
): void {
$this->accessToken = $accessToken;
}

public function setRefreshToken(RefreshTokenEntityInterface $refreshToken): void
{
public function setRefreshToken(
#[SensitiveParameter]
RefreshTokenEntityInterface $refreshToken
): void {
$this->refreshToken = $refreshToken;
}

public function setPrivateKey(CryptKeyInterface $key): void
{
public function setPrivateKey(
#[SensitiveParameter]
CryptKeyInterface $key
): void {
$this->privateKey = $key;
}
}
7 changes: 5 additions & 2 deletions src/ResponseTypes/BearerTokenResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
use LogicException;
use Psr\Http\Message\ResponseInterface;
use SensitiveParameter;

use function array_merge;
use function json_encode;
Expand Down Expand Up @@ -75,8 +76,10 @@ public function generateHttpResponse(ResponseInterface $response): ResponseInter
*
* @return array<array-key,mixed>
*/
protected function getExtraParams(AccessTokenEntityInterface $accessToken): array
{
protected function getExtraParams(
#[SensitiveParameter]
AccessTokenEntityInterface $accessToken
): array {
return [];
}
}
16 changes: 13 additions & 3 deletions src/ResponseTypes/ResponseTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
use Psr\Http\Message\ResponseInterface;
use SensitiveParameter;

interface ResponseTypeInterface
{
public function setAccessToken(AccessTokenEntityInterface $accessToken): void;
public function setAccessToken(
#[SensitiveParameter]
AccessTokenEntityInterface $accessToken
): void;

public function setRefreshToken(RefreshTokenEntityInterface $refreshToken): void;
public function setRefreshToken(
#[SensitiveParameter]
RefreshTokenEntityInterface $refreshToken
): void;

public function generateHttpResponse(ResponseInterface $response): ResponseInterface;

public function setEncryptionKey(Key|string|null $key = null): void;
public function setEncryptionKey(
#[SensitiveParameter]
Key|string|null $key = null
): void;
}