-
-
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.
feature #1112 fix: better API Platform and json_login compatibility (…
…alanpoulain) This PR was merged into the 2.x branch. Discussion ---------- fix: better API Platform and json_login compatibility After #1098. This PR adds two new arguments for the API Platform compatibility: `username_path` and `password_path`. Moreover, it is not necessary anymore to add `check_path` to enable the decoration of the OpenAPI factory: if API Platform is detected and if a `json_login` firewall is available, it is automatically enabled! For complex configuration, the user can take over the configuration. Commits ------- f6f4f6f fix: better API Platform and json_login compatibility
- Loading branch information
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