Skip to content

Commit

Permalink
Don't register lcobucci encoder if lcobucci/jwt is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr committed Oct 6, 2017
1 parent aa5ad3d commit b2da6b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection;

use Lcobucci\JWT\Token;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand Down Expand Up @@ -40,6 +41,12 @@ public function getConfigTreeBuilder()
->children()
->scalarNode('service')
->defaultValue('lexik_jwt_authentication.encoder.default')
->validate()
->ifTrue(function ($encoder) {
return 'lexik_jwt_authentication.encoder.lcobucci' === $encoder && !class_exists(Token::class);
})
->thenInvalid('You must require "lcobucci/jwt" in your composer.json for using the lcobucci encoder.')
->end()
->end()
->scalarNode('signature_algorithm')
->defaultValue('RS256')
Expand Down
6 changes: 6 additions & 0 deletions DependencyInjection/LexikJWTAuthenticationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection;

use Lcobucci\JWT\Token;
use Lexik\Bundle\JWTAuthenticationBundle\Encoder\JWTEncoderInterface;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWSProvider\JWSProviderInterface;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTManagerInterface;
Expand Down Expand Up @@ -32,6 +33,11 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');

if (!class_exists(Token::class)) {
$container->removeDefinition('lexik_jwt_authentication.encoder.lcobucci');
$container->removeDefinition('lexik_jwt_authentication.jws_provider.lcobucci');
}

$container->setParameter('lexik_jwt_authentication.private_key_path', $config['private_key_path']);
$container->setParameter('lexik_jwt_authentication.public_key_path', $config['public_key_path']);
$container->setParameter('lexik_jwt_authentication.pass_phrase', $config['pass_phrase']);
Expand Down

0 comments on commit b2da6b3

Please sign in to comment.