From 1c8a9405e5d67073782f74f386f5e5d92438dca2 Mon Sep 17 00:00:00 2001
From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com>
Date: Wed, 17 Apr 2024 11:23:59 +0200
Subject: [PATCH 1/6] 1190: Added post redirect
---
CHANGELOG.md | 3 +++
config/packages/nelmio_cors.yaml | 3 ++-
config/packages/security.yaml | 3 ++-
src/Controller/ApiV1RedirectController.php | 13 ++++++++++---
4 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 656af09f..bb100fa6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
+- [#205](https://github.com/os2display/display-api-service/pull/205)
+ - Fixed redirecting post requests.
+
## [2.0.3] - 2024-04-10
- [#203](https://github.com/os2display/display-api-service/pull/203)
diff --git a/config/packages/nelmio_cors.yaml b/config/packages/nelmio_cors.yaml
index 2ae9f080..f815f4e3 100644
--- a/config/packages/nelmio_cors.yaml
+++ b/config/packages/nelmio_cors.yaml
@@ -8,6 +8,7 @@ nelmio_cors:
expose_headers: ['Link']
max_age: 3600
paths:
- '^/v2/authentication/':
+ # v1 is added for backwards compatability: See App/Controller/ApiV1RedirectController
+ '^/(v1|v2)/authentication/':
allow_credentials: true
'^/': null
diff --git a/config/packages/security.yaml b/config/packages/security.yaml
index 9f55876f..e9310ab1 100644
--- a/config/packages/security.yaml
+++ b/config/packages/security.yaml
@@ -33,8 +33,9 @@ security:
login_oidc:
pattern: ^/v2/authentication/oidc
security: false
+ # v1 is added for backwards compatability: See App/Controller/ApiV1RedirectController
api_token_refresh:
- pattern: ^/v2/authentication/token/refresh
+ pattern: ^/(v1|v2)/authentication/token/refresh
stateless: true
refresh_jwt:
provider: user_provider
diff --git a/src/Controller/ApiV1RedirectController.php b/src/Controller/ApiV1RedirectController.php
index 246caf1d..d95b6f71 100644
--- a/src/Controller/ApiV1RedirectController.php
+++ b/src/Controller/ApiV1RedirectController.php
@@ -6,13 +6,20 @@
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
+use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class ApiV1RedirectController extends AbstractController
{
- #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['GET'])]
- public function index(string $endpoint): RedirectResponse
+ #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect_get', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['GET'])]
+ public function redirectGets(string $endpoint): RedirectResponse
{
- return $this->redirect('/v2/'.$endpoint, \Symfony\Component\HttpFoundation\Response::HTTP_MOVED_PERMANENTLY);
+ return $this->redirect('/v2/'.$endpoint, Response::HTTP_MOVED_PERMANENTLY);
+ }
+
+ #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect_post', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['POST'])]
+ public function redirectPosts(string $endpoint): RedirectResponse
+ {
+ return $this->redirect('/v2/'.$endpoint, Response::HTTP_TEMPORARY_REDIRECT);
}
}
From 2e4cbb7ae58132af6977c1afeb033b9758aae48e Mon Sep 17 00:00:00 2001
From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com>
Date: Wed, 17 Apr 2024 11:31:00 +0200
Subject: [PATCH 2/6] 1190: Merged routes
---
src/Controller/ApiV1RedirectController.php | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/src/Controller/ApiV1RedirectController.php b/src/Controller/ApiV1RedirectController.php
index d95b6f71..e318f0c6 100644
--- a/src/Controller/ApiV1RedirectController.php
+++ b/src/Controller/ApiV1RedirectController.php
@@ -11,15 +11,9 @@
class ApiV1RedirectController extends AbstractController
{
- #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect_get', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['GET'])]
- public function redirectGets(string $endpoint): RedirectResponse
+ #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['GET', 'POST'])]
+ public function index(string $endpoint): RedirectResponse
{
return $this->redirect('/v2/'.$endpoint, Response::HTTP_MOVED_PERMANENTLY);
}
-
- #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect_post', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['POST'])]
- public function redirectPosts(string $endpoint): RedirectResponse
- {
- return $this->redirect('/v2/'.$endpoint, Response::HTTP_TEMPORARY_REDIRECT);
- }
}
From bf7f63c2ac46e03066ae58a34e1d28a356b44a39 Mon Sep 17 00:00:00 2001
From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com>
Date: Wed, 17 Apr 2024 11:54:57 +0200
Subject: [PATCH 3/6] 1190: Updated baseline for ThemeProcessor
---
psalm-baseline.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index a98c5bdd..b9b3cf40 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -751,8 +751,8 @@
-
+
From 4294cb83790b623fab158d2a96e758085ece01e2 Mon Sep 17 00:00:00 2001
From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com>
Date: Wed, 17 Apr 2024 13:13:41 +0200
Subject: [PATCH 4/6] 1190: Moved redirect for post into own function to use
HTTP_TEMPORARY_REDIRECT
---
src/Controller/ApiV1RedirectController.php | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/Controller/ApiV1RedirectController.php b/src/Controller/ApiV1RedirectController.php
index e318f0c6..1597f9b4 100644
--- a/src/Controller/ApiV1RedirectController.php
+++ b/src/Controller/ApiV1RedirectController.php
@@ -11,9 +11,15 @@
class ApiV1RedirectController extends AbstractController
{
- #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['GET', 'POST'])]
+ #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['GET'])]
public function index(string $endpoint): RedirectResponse
{
return $this->redirect('/v2/'.$endpoint, Response::HTTP_MOVED_PERMANENTLY);
}
+
+ #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect_post', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['POST'])]
+ public function indexPost(string $endpoint): RedirectResponse
+ {
+ return $this->redirect('/v2/'.$endpoint, Response::HTTP_TEMPORARY_REDIRECT);
+ }
}
From 0310d31fcf8d871e492e0b94eca47b14ee85ad60 Mon Sep 17 00:00:00 2001
From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com>
Date: Thu, 18 Apr 2024 06:57:11 +0200
Subject: [PATCH 5/6] 1190: Changed to HTTP_PERMANENTLY_REDIRECT
---
src/Controller/ApiV1RedirectController.php | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/src/Controller/ApiV1RedirectController.php b/src/Controller/ApiV1RedirectController.php
index 1597f9b4..f176c94c 100644
--- a/src/Controller/ApiV1RedirectController.php
+++ b/src/Controller/ApiV1RedirectController.php
@@ -11,15 +11,9 @@
class ApiV1RedirectController extends AbstractController
{
- #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['GET'])]
+ #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null])]
public function index(string $endpoint): RedirectResponse
{
- return $this->redirect('/v2/'.$endpoint, Response::HTTP_MOVED_PERMANENTLY);
- }
-
- #[Route('/v1/{endpoint}', name: 'app_api_v1_redirect_post', requirements: ['endpoint' => '.+'], defaults: ['endpoint' => null], methods: ['POST'])]
- public function indexPost(string $endpoint): RedirectResponse
- {
- return $this->redirect('/v2/'.$endpoint, Response::HTTP_TEMPORARY_REDIRECT);
+ return $this->redirect('/v2/'.$endpoint, Response::HTTP_PERMANENTLY_REDIRECT);
}
}
From ed32213d9cc5389d3fc845c3e833c7147ee3e50d Mon Sep 17 00:00:00 2001
From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com>
Date: Thu, 18 Apr 2024 07:27:50 +0200
Subject: [PATCH 6/6] 1190: Fixed tests
---
tests/Controller/ApiV1RedirectControllerTest.php | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tests/Controller/ApiV1RedirectControllerTest.php b/tests/Controller/ApiV1RedirectControllerTest.php
index 0b2b6ec4..cfd8f9fa 100644
--- a/tests/Controller/ApiV1RedirectControllerTest.php
+++ b/tests/Controller/ApiV1RedirectControllerTest.php
@@ -5,14 +5,19 @@
namespace App\Tests\Controller;
use App\Tests\AbstractBaseApiTestCase;
+use Symfony\Component\HttpFoundation\Request;
class ApiV1RedirectControllerTest extends AbstractBaseApiTestCase
{
public function testIndex()
{
$client = $this->getAuthenticatedClient('ROLE_ADMIN');
- $crawler = $client->request('GET', '/v1/screens/01GN9PW2Z03V8VQG7SN6Q9R17H');
+ $client->request(Request::METHOD_GET, '/v1/screens/01GN9PW2Z03V8VQG7SN6Q9R17H');
- $this->assertResponseRedirects('/v2/screens/01GN9PW2Z03V8VQG7SN6Q9R17H', 301);
+ $this->assertResponseRedirects('/v2/screens/01GN9PW2Z03V8VQG7SN6Q9R17H', 308);
+
+ $client->request(Request::METHOD_POST, '/v1/authentication/screen');
+
+ $this->assertResponseRedirects('/v2/authentication/screen', 308);
}
}