Skip to content

Commit

Permalink
Registers default token storage if AUTH_TOKEN_STORAGE env variable is…
Browse files Browse the repository at this point in the history
… not used.
  • Loading branch information
butschster committed Feb 19, 2023
1 parent 6436ac9 commit 1d59120
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Bootloader/AuthTokensBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace Spiral\Cycle\Bootloader;

use Spiral\Auth\Config\AuthConfig;
use Spiral\Boot\EnvironmentInterface;
use Spiral\Config\ConfiguratorInterface;
use Spiral\Config\Patch\Set;
use Spiral\Cycle\Auth\Token;
use Spiral\Cycle\Auth\TokenStorage as CycleStorage;
use Spiral\Boot\Bootloader\Bootloader;
Expand All @@ -12,16 +16,33 @@

final class AuthTokensBootloader extends Bootloader
{
private const TOKEN_STORAGE_NAME = 'cycle';

protected const DEPENDENCIES = [
CycleOrmBootloader::class,
AnnotatedBootloader::class,
];

public function __construct(
private readonly ConfiguratorInterface $config,
) {
}

public function init(
TokenizerBootloader $tokenizer,
HttpAuthBootloader $bootloader,
EnvironmentInterface $env
): void {
$bootloader->addTokenStorage('cycle', CycleStorage::class);
$bootloader->addTokenStorage(self::TOKEN_STORAGE_NAME, CycleStorage::class);

// This is a temporary fix and backward compatibility for case when AUTH_TOKEN_STORAGE is not set.
// TODO: Will be removed after release of spiral/framework 4.0.0
if ($env->get('AUTH_TOKEN_STORAGE') === null) {
$this->config->modify(
AuthConfig::CONFIG,
new Set('defaultStorage', self::TOKEN_STORAGE_NAME),
);
}

$tokenClass = new \ReflectionClass(Token::class);
$tokenizer->addDirectory(\dirname($tokenClass->getFileName()));
Expand Down

0 comments on commit 1d59120

Please sign in to comment.