Skip to content
Merged
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
10 changes: 3 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.4"

dependencies:
- "highest"
Expand Down Expand Up @@ -53,11 +53,9 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
- "8.4"

dependencies:
- "lowest"
- "highest"

steps:
Expand Down Expand Up @@ -91,11 +89,9 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
- "8.4"

dependencies:
- "lowest"
- "highest"

steps:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"sylius-labs/coding-standard": "^4.2",
"symfony/cache": "^6.0",
"symfony/http-client": "^6.0",
"vimeo/psalm": "^4.26"
"vimeo/psalm": "^6.9.4"
},
"provide": {
"symfony/http-client-implementation": "^2.3.1"
Expand Down
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
errorLevel="1"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
phpVersion="8.1"
phpVersion="8.4"
>
<projectFiles>
<directory name="src"/>
Expand Down
1 change: 1 addition & 0 deletions src/Exception/OAuthException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* Represents errors during OAuth protocol.
* @psalm-api
*/
class OAuthException extends RuntimeException implements OAuthExceptionInterface
{
Expand Down
3 changes: 3 additions & 0 deletions src/GrantType/AuthorizationCodeGrantType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* Implementation of the OAuth authorization grant type.
* @psalm-api
*/
class AuthorizationCodeGrantType implements RefreshableGrantTypeInterface
{
Expand Down Expand Up @@ -50,6 +51,7 @@ public function __construct(
*
* @throws TransportExceptionInterface
*/
#[\Override]
public function getTokens(): Tokens
{
$response = $this->client->request('POST', $this->tokenUrl, [
Expand All @@ -64,6 +66,7 @@ public function getTokens(): Tokens
return $this->extractTokens($response);
}

#[\Override]
public function getRefreshTokenGrant(string $refreshToken): GrantTypeInterface
{
return new RefreshTokenGrantType($this->client, $this->tokenUrl, $refreshToken, $this->clientId, $this->clientSecret);
Expand Down
2 changes: 2 additions & 0 deletions src/GrantType/ClientCredentialsGrantType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* Implementation of the OAuth client credentials grant type.
* @psalm-api
*/
class ClientCredentialsGrantType implements GrantTypeInterface
{
Expand Down Expand Up @@ -45,6 +46,7 @@ public function __construct(
*
* @throws TransportExceptionInterface
*/
#[\Override]
public function getTokens(): Tokens
{
$response = $this->client->request('POST', $this->tokenUrl, [
Expand Down
2 changes: 2 additions & 0 deletions src/GrantType/PasswordGrantType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* Implementation of the OAuth password grant type.
* @psalm-api
*/
class PasswordGrantType implements GrantTypeInterface
{
Expand Down Expand Up @@ -55,6 +56,7 @@ public function __construct(
*
* @throws TransportExceptionInterface
*/
#[\Override]
public function getTokens(): Tokens
{
$parameters = [
Expand Down
2 changes: 2 additions & 0 deletions src/GrantType/RefreshTokenGrantType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* Implementation of the OAuth refresh token grant type.
* @psalm-api
*/
class RefreshTokenGrantType implements GrantTypeInterface
{
Expand Down Expand Up @@ -50,6 +51,7 @@ public function __construct(
*
* @throws TransportExceptionInterface
*/
#[\Override]
public function getTokens(): Tokens
{
$response = $this->client->request('POST', $this->tokenUrl, [
Expand Down
1 change: 1 addition & 0 deletions src/GrantType/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* Value object for an access token and a refresh token.
* @psalm-api
*/
class Tokens
{
Expand Down
14 changes: 13 additions & 1 deletion src/OAuthHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,37 @@ public function __construct(
$this->cache = new MemoryTokensCache();
}

/**
* @psalm-api
*/
public function setSigner(RequestSignerInterface $signer): self
{
$this->signer = $signer;

return $this;
}

/**
* @psalm-api
*/
public function setChecker(ResponseCheckerInterface $checker): self
{
$this->checker = $checker;

return $this;
}

/**
* @psalm-api
*/
public function setCache(TokensCacheInterface $cache): self
{
$this->cache = $cache;

return $this;
}

#[\Override]
public function request(string $method, string $url, array $options = []): ResponseInterface
{
$grant = $this->grant;
Expand All @@ -84,11 +94,13 @@ public function request(string $method, string $url, array $options = []): Respo
throw new RuntimeException();
}

public function stream($responses, float $timeout = null): ResponseStreamInterface
#[\Override]
public function stream($responses, ?float $timeout = null): ResponseStreamInterface
{
return $this->client->stream($responses, $timeout);
}

#[\Override]
public function withOptions(array $options): static
{
return new self($this->client->withOptions($options), $this->grant);
Expand Down
3 changes: 3 additions & 0 deletions src/RequestSigner/BearerHeaderRequestSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace BenjaminFavre\OAuthHttpClient\RequestSigner;

/**
* @psalm-api
*/
class BearerHeaderRequestSigner extends HeaderRequestSigner
{
public function __construct()
Expand Down
1 change: 1 addition & 0 deletions src/RequestSigner/HeaderRequestSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function __construct(string $headerName, string $headerValueFormat)
$this->headerValueFormat = $headerValueFormat;
}

#[\Override]
public function modify(array &$options, string $token): void
{
if (!array_key_exists('headers', $options)) {
Expand Down
4 changes: 4 additions & 0 deletions src/ResponseChecker/StatusCode401ResponseChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

use Symfony\Contracts\HttpClient\ResponseInterface;

/**
* @psalm-api
*/
class StatusCode401ResponseChecker implements ResponseCheckerInterface
{
#[\Override]
public function hasAuthenticationFailed(ResponseInterface $response): bool
{
return $response->getStatusCode() === 401;
Expand Down
5 changes: 5 additions & 0 deletions src/TokensCache/MemoryTokensCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
use BenjaminFavre\OAuthHttpClient\GrantType\GrantTypeInterface;
use BenjaminFavre\OAuthHttpClient\GrantType\Tokens;

/**
* @psalm-api
*/
class MemoryTokensCache implements TokensCacheInterface
{
private ?Tokens $tokens = null;

#[\Override]
public function get(GrantTypeInterface $grant): Tokens
{
if ($this->tokens === null) {
Expand All @@ -20,6 +24,7 @@ public function get(GrantTypeInterface $grant): Tokens
return $this->tokens;
}

#[\Override]
public function clear(): void
{
$this->tokens = null;
Expand Down
5 changes: 5 additions & 0 deletions src/TokensCache/SymfonyTokensCacheAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use RuntimeException;
use Symfony\Contracts\Cache\CacheInterface;

/**
* @psalm-api
*/
class SymfonyTokensCacheAdapter implements TokensCacheInterface
{
private CacheInterface $cache;
Expand All @@ -21,6 +24,7 @@ public function __construct(CacheInterface $cache, string $cacheKey)
$this->cacheKey = $cacheKey;
}

#[\Override]
public function get(GrantTypeInterface $grant): Tokens
{
$tokens = $this->cache->get($this->cacheKey, function () use ($grant) {
Expand All @@ -34,6 +38,7 @@ public function get(GrantTypeInterface $grant): Tokens
return $tokens;
}

#[\Override]
public function clear(): void
{
$this->cache->delete($this->cacheKey);
Expand Down