Skip to content

Commit

Permalink
feat: Add Symfony Cache component support (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
evansims authored Dec 15, 2022
1 parent 5124465 commit 752c4f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
19 changes: 8 additions & 11 deletions src/Auth0Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@ public function configure(DefinitionConfigurator $definition): void

public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{
$tokenCache = $config['sdk']['token_cache'] ?? null;
$managementTokenCache = $config['sdk']['management_token_cache'] ?? null;
$tokenCache = $config['sdk']['token_cache'] ?? '';
$managementTokenCache = $config['sdk']['management_token_cache'] ?? '';
$transientStorage = $config['sdk']['transient_storage'] ?? null;
$sessionStorage = $config['sdk']['session_storage'] ?? null;
$eventListenerProvider = $config['sdk']['event_listener_provider'] ?? null;

if (null !== $tokenCache && '' !== $tokenCache) {
$tokenCache = new Reference($tokenCache);
}

if (null !== $managementTokenCache && '' !== $managementTokenCache) {
$managementTokenCache = new Reference($managementTokenCache);
}
$tokenCache = new Reference('' === $tokenCache ? 'cache.app' : $tokenCache);
$managementTokenCache = new Reference('' === $managementTokenCache ? 'cache.app' : $managementTokenCache);

if (null !== $transientStorage && '' !== $transientStorage) {
$transientStorage = new Reference($transientStorage);
Expand Down Expand Up @@ -87,7 +82,7 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
->arg('$tokenJwksUri', $config['sdk']['token_jwks_uri'])
->arg('$tokenMaxAge', $config['sdk']['token_max_age'])
->arg('$tokenLeeway', $config['sdk']['token_leeway'] ?? 60)
->arg('$tokenCache', $tokenCache)
->arg('$tokenCache', null)
->arg('$tokenCacheTtl', $config['sdk']['token_cache_ttl'])
->arg('$httpClient', $config['sdk']['http_client'])
->arg('$httpMaxRetries', $config['sdk']['http_max_retries'])
Expand All @@ -111,14 +106,16 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
->arg('$transientStorageId', $config['sdk']['transient_storage_id'])
->arg('$queryUserInfo', false)
->arg('$managementToken', $config['sdk']['management_token'])
->arg('$managementTokenCache', $managementTokenCache)
->arg('$managementTokenCache', null)
->arg('$eventListenerProvider', $eventListenerProvider)
;

$container->services()
->set('auth0', Service::class)
->arg('$configuration', new Reference('auth0.configuration'))
->arg('$logger', new Reference('logger'))
->arg('$tokenCache', $tokenCache)
->arg('$managementTokenCache', $managementTokenCache)
;

$container->services()
Expand Down
12 changes: 11 additions & 1 deletion src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@
use Auth0\Symfony\Contracts\ServiceInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\Cache\CacheInterface;

final class Service implements ServiceInterface
{
private ?Auth0 $sdk = null;

public function __construct(
private SdkConfiguration $configuration,
private LoggerInterface $logger
private LoggerInterface $logger,
private ?CacheItemPoolInterface $tokenCache,
private ?CacheItemPoolInterface $managementTokenCache,
)
{
if (null !== $tokenCache) {
$configuration->setTokenCache($tokenCache);
}

if (null !== $managementTokenCache) {
$configuration->setManagementTokenCache($managementTokenCache);
}
}

public function getSdk()
Expand Down

0 comments on commit 752c4f8

Please sign in to comment.