diff --git a/Services/JWSProvider/LcobucciJWSProvider.php b/Services/JWSProvider/LcobucciJWSProvider.php index c9b51f0d..923091c2 100644 --- a/Services/JWSProvider/LcobucciJWSProvider.php +++ b/Services/JWSProvider/LcobucciJWSProvider.php @@ -214,6 +214,10 @@ private function getSignerForAlgorithm($signatureAlgorithm) $signerClass = $signerMap[$signatureAlgorithm]; + if (is_subclass_of($signerClass, Signer\Ecdsa::class) && method_exists($signerClass, 'create')) { + return $signerClass::create(); + } + return new $signerClass(); } diff --git a/Tests/Services/JWSProvider/AbstractJWSProviderTest.php b/Tests/Services/JWSProvider/AbstractJWSProviderTest.php index 7f4e0ba5..d8916de8 100644 --- a/Tests/Services/JWSProvider/AbstractJWSProviderTest.php +++ b/Tests/Services/JWSProvider/AbstractJWSProviderTest.php @@ -181,7 +181,7 @@ public function testCreateWithExtraStandardClaims() $this->assertNotEmpty($created->getToken()); } - private function getKeyLoaderMock() + protected function getKeyLoaderMock() { return $this ->getMockBuilder(static::$keyLoaderClass) diff --git a/Tests/Services/JWSProvider/LcobucciJWSProviderTest.php b/Tests/Services/JWSProvider/LcobucciJWSProviderTest.php index 07e0880b..b1eb80a3 100644 --- a/Tests/Services/JWSProvider/LcobucciJWSProviderTest.php +++ b/Tests/Services/JWSProvider/LcobucciJWSProviderTest.php @@ -4,6 +4,7 @@ use Lexik\Bundle\JWTAuthenticationBundle\Services\JWSProvider\LcobucciJWSProvider; use Lexik\Bundle\JWTAuthenticationBundle\Services\KeyLoader\RawKeyLoader; +use Lexik\Bundle\JWTAuthenticationBundle\Signature\CreatedJWS; /** * Tests the LcobucciJWSProvider. @@ -14,4 +15,25 @@ final class LcobucciJWSProviderTest extends AbstractJWSProviderTest { protected static $providerClass = LcobucciJWSProvider::class; protected static $keyLoaderClass = RawKeyLoader::class; + + public function testCreateWithEcdsa() + { + $keyLoaderMock = $this->getKeyLoaderMock(); + $keyLoaderMock + ->expects($this->once()) + ->method('loadKey') + ->with('private') + ->willReturn(self::$privateKey); + $keyLoaderMock + ->expects($this->once()) + ->method('getPassphrase') + ->willReturn('foobar'); + + $payload = ['username' => 'chalasr']; + $jwsProvider = new LcobucciJWSProvider($keyLoaderMock, 'openssl', 'EC512', 3600, 0); + + $this->assertInstanceOf(CreatedJWS::class, $created = $jwsProvider->create($payload)); + + return $created->getToken(); + } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e0b14d35..95ab2af2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -26,4 +26,8 @@ + + + +