Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the data model, Doctrine, and validation structures #247

Merged
merged 1 commit into from
Jun 29, 2021
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
92 changes: 0 additions & 92 deletions DependencyInjection/Compiler/DoctrineMappingsCompilerPass.php

This file was deleted.

17 changes: 15 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Gesdinet\JWTRefreshTokenBundle\DependencyInjection;

use Symfony\Component\Config\Definition\BaseNode;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand Down Expand Up @@ -50,24 +51,36 @@ public function getConfigTreeBuilder()
->end()
->scalarNode('user_checker')->defaultValue('security.user_checker')->end()
->scalarNode('refresh_token_entity')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated, use the "refresh_token_class" node instead.', '0.5'))
->defaultNull()
->info('Deprecated, use refresh_token_class instead')
->info('Set another refresh token class to use instead of default one (Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken)')
->end()
->scalarNode('entity_manager')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated, use the "object_manager" node instead.', '0.5'))
->defaultNull()
->info('Deprecated, use object_manager instead')
->info('Set entity manager to use')
->end()
->scalarNode('single_use')
->defaultFalse()
->info('When true, generate a new refresh token on consumption (deleting the old one)')
->end()
->scalarNode('token_parameter_name')->defaultValue('refresh_token')->end()
->booleanNode('doctrine_mappings')
->setDeprecated(...$this->getDeprecationParameters('The "%node%" node is deprecated without replacement.', '0.13'))
->info('When true, resolving of Doctrine mapping is done automatically to use either ORM or ODM object manager')
->defaultTrue()
->end()
->end();

return $treeBuilder;
}

private function getDeprecationParameters(string $message, string $version): array
{
if (method_exists(BaseNode::class, 'getDeprecation')) {
return ['gesdinet/jwt-refresh-token-bundle', $version, $message];
}

return [$message];
}
}
112 changes: 8 additions & 104 deletions Document/AbstractRefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,132 +11,36 @@

namespace Gesdinet\JWTRefreshTokenBundle\Document;

use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique;
use Gesdinet\JWTRefreshTokenBundle\Model\AbstractRefreshToken as BaseAbstractRefreshToken;
use Symfony\Component\Validator\Constraints as Assert;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;

/**
* Abstract Refresh Token.
*
* @Unique("refreshToken")
*
* @deprecated Extend from `Gesdinet\JWTRefreshTokenBundle\Model\AbstractRefreshToken` instead
*/
abstract class AbstractRefreshToken implements RefreshTokenInterface
abstract class AbstractRefreshToken extends BaseAbstractRefreshToken
{
/**
* @var string
*
* @Assert\NotBlank()
*/
private $refreshToken;
protected $refreshToken;

/**
* @var string
*
* @Assert\NotBlank()
*/
private $username;
protected $username;

/**
* @var \DateTime
* @var \DateTimeInterface
*
* @Assert\NotBlank()
*/
private $valid;

/**
* {@inheritdoc}
*/
abstract public function getId();

/**
* Set refreshToken.
*
* @param string $refreshToken
*
* @return AbstractRefreshToken
*/
public function setRefreshToken($refreshToken = null)
{
$this->refreshToken = null === $refreshToken
? bin2hex(openssl_random_pseudo_bytes(64))
: $refreshToken;

return $this;
}

/**
* Get refreshToken.
*
* @return string
*/
public function getRefreshToken()
{
return $this->refreshToken;
}

/**
* Set valid.
*
* @param \DateTime $valid
*
* @return AbstractRefreshToken
*/
public function setValid($valid)
{
$this->valid = $valid;

return $this;
}

/**
* Get valid.
*
* @return \DateTime
*/
public function getValid()
{
return $this->valid;
}

/**
* Set username.
*
* @param string $username
*
* @return AbstractRefreshToken
*/
public function setUsername($username)
{
$this->username = $username;

return $this;
}

/**
* Get username.
*
* @return string
*/
public function getUsername()
{
return $this->username;
}

/**
* Check if is a valid refresh token.
*
* @return bool
*/
public function isValid()
{
return $this->valid >= new \DateTime();
}

/**
* @return string Refresh Token
*/
public function __toString()
{
return $this->getRefreshToken();
}
protected $valid;
}
16 changes: 1 addition & 15 deletions Document/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,11 @@

namespace Gesdinet\JWTRefreshTokenBundle\Document;

use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique;
use Gesdinet\JWTRefreshTokenBundle\Model\AbstractRefreshToken;

/**
* Refresh Token.
*
* @Unique("refreshToken")
*/
class RefreshToken extends AbstractRefreshToken
{
/**
* @var string
*/
protected $id;

/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
}
Loading