-
-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: better API Platform and json_login compatibility
- Loading branch information
1 parent
407de37
commit f6f4f6f
Showing
9 changed files
with
138 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class ApiPlatformOpenApiPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition('lexik_jwt_authentication.api_platform.openapi.factory') || !$container->hasParameter('security.firewalls')) { | ||
return; | ||
} | ||
|
||
$checkPath = null; | ||
$usernamePath = null; | ||
$passwordPath = null; | ||
$firewalls = $container->getParameter('security.firewalls'); | ||
foreach ($firewalls as $firewallName) { | ||
if ($container->hasDefinition('security.authenticator.json_login.' . $firewallName)) { | ||
$firewallOptions = $container->getDefinition('security.authenticator.json_login.' . $firewallName)->getArgument(4); | ||
$checkPath = $firewallOptions['check_path']; | ||
$usernamePath = $firewallOptions['username_path']; | ||
$passwordPath = $firewallOptions['password_path']; | ||
|
||
break; | ||
} | ||
} | ||
|
||
$openApiFactoryDefinition = $container->getDefinition('lexik_jwt_authentication.api_platform.openapi.factory'); | ||
$checkPathArg = $openApiFactoryDefinition->getArgument(1); | ||
$usernamePathArg = $openApiFactoryDefinition->getArgument(2); | ||
$passwordPathArg = $openApiFactoryDefinition->getArgument(3); | ||
|
||
if (!$checkPath && !$checkPathArg) { | ||
$container->removeDefinition('lexik_jwt_authentication.api_platform.openapi.factory'); | ||
|
||
return; | ||
} | ||
|
||
if (!$checkPathArg) { | ||
$openApiFactoryDefinition->replaceArgument(1, $checkPath); | ||
} | ||
if (!$usernamePathArg) { | ||
$openApiFactoryDefinition->replaceArgument(2, $usernamePath ?? 'username'); | ||
} | ||
if (!$passwordPathArg) { | ||
$openApiFactoryDefinition->replaceArgument(3, $passwordPath ?? 'password'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\Tests\Functional\Command; | ||
|
||
use ApiPlatform\Symfony\Bundle\ApiPlatformBundle; | ||
use Lexik\Bundle\JWTAuthenticationBundle\Tests\Functional\TestCase; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
@@ -12,7 +11,7 @@ | |
* | ||
* @author Vincent Chalamon <[email protected]> | ||
* | ||
* @requires function ApiPlatformBundle::build | ||
* @requires function ApiPlatform\Symfony\Bundle\ApiPlatformBundle::build | ||
*/ | ||
class ApiPlatformOpenApiExportCommandTest extends TestCase | ||
{ | ||
|
@@ -43,10 +42,7 @@ public function testCheckOpenApiExportCommand() | |
"paths": { | ||
"/login_check": { | ||
"post": { | ||
"deprecated": false, | ||
"description": "", | ||
"operationId": "login_check_post", | ||
"parameters": [], | ||
"requestBody": { | ||
"description": "The login data", | ||
"required": true, | ||
|
@@ -55,18 +51,30 @@ public function testCheckOpenApiExportCommand() | |
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"_username": { | ||
"email": { | ||
"nullable": false, | ||
"type": "string" | ||
}, | ||
"_password": { | ||
"nullable": false, | ||
"type": "string" | ||
"security": { | ||
"type": "object", | ||
"properties": { | ||
"credentials": { | ||
"type": "object", | ||
"properties": { | ||
"password": { | ||
"nullable": false, | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["password"] | ||
} | ||
}, | ||
"required": ["credentials"] | ||
} | ||
}, | ||
"required": [ | ||
"_username", | ||
"_password" | ||
"email", | ||
"security" | ||
] | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters