Skip to content

Commit 338205e

Browse files
committed
Issue #422: Split the /security/token endpoint into two separate endpoints
Signed-off-by: alexmerlin <[email protected]>
1 parent a24d18a commit 338205e

File tree

6 files changed

+50
-48
lines changed

6 files changed

+50
-48
lines changed

config/autoload/authorization.global.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
'user::update-account-reset-password',
7373
'user::create-account-reset-password',
7474
'user::create-account',
75-
'security::token',
76-
'security::token',
75+
'security::generate-token',
76+
'security::refresh-token',
7777
],
7878
],
7979
],

documentation/Dotkernel_API.postman_collection.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info": {
3-
"_postman_id": "f837d47b-cc12-4897-8b1a-ecd26b4bbe44",
3+
"_postman_id": "f9da948e-3325-4595-a55b-ca31958433d0",
44
"name": "Dotkernel_API",
55
"description": "Dotkernel API documentation.",
66
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
@@ -357,13 +357,13 @@
357357
}
358358
},
359359
"url": {
360-
"raw": "{{APPLICATION_URL}}/security/token",
360+
"raw": "{{APPLICATION_URL}}/security/generate-token",
361361
"host": [
362362
"{{APPLICATION_URL}}"
363363
],
364364
"path": [
365365
"security",
366-
"token"
366+
"generate-token"
367367
]
368368
},
369369
"description": "Generate OAuth2 Bearer token for identity with admin privileges."
@@ -407,13 +407,13 @@
407407
}
408408
},
409409
"url": {
410-
"raw": "{{APPLICATION_URL}}/security/token",
410+
"raw": "{{APPLICATION_URL}}/security/refresh-token",
411411
"host": [
412412
"{{APPLICATION_URL}}"
413413
],
414414
"path": [
415415
"security",
416-
"token"
416+
"refresh-token"
417417
]
418418
},
419419
"description": "Refresh OAuth2 Bearer token for identity with admin privileges."
@@ -982,13 +982,13 @@
982982
}
983983
},
984984
"url": {
985-
"raw": "{{APPLICATION_URL}}/security/token",
985+
"raw": "{{APPLICATION_URL}}/security/generate-token",
986986
"host": [
987987
"{{APPLICATION_URL}}"
988988
],
989989
"path": [
990990
"security",
991-
"token"
991+
"generate-token"
992992
]
993993
},
994994
"description": "Generate OAuth2 Bearer token for identity with regular user privileges."
@@ -1022,13 +1022,13 @@
10221022
}
10231023
},
10241024
"url": {
1025-
"raw": "{{APPLICATION_URL}}/security/token",
1025+
"raw": "{{APPLICATION_URL}}/security/refresh-token",
10261026
"host": [
10271027
"{{APPLICATION_URL}}"
10281028
],
10291029
"path": [
10301030
"security",
1031-
"token"
1031+
"refresh-token"
10321032
]
10331033
},
10341034
"description": "Refresh OAuth2 Bearer token for identity with regular user privileges."

documentation/command/route-list.md

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The command runs through all routes and extracts endpoint information in realtim
1212
The output should be similar to the following:
1313

1414
```text
15-
+------+----------------+-------------------- 37 Routes ------+-------------------------------------+
15+
+------+----------------+-------------------- 38 Routes ------+-------------------------------------+
1616
| # | Request method | Route name | Route path |
1717
+------+----------------+-------------------------------------+-------------------------------------+
1818
| 1 | GET | app::view-index | / |
@@ -26,32 +26,33 @@ The output should be similar to the following:
2626
| 9 | GET | admin::view-admin | /admin/{uuid} |
2727
| 10 | PATCH | admin::update-admin | /admin/{uuid} |
2828
| 11 | POST | app::create-error-report | /error-report |
29-
| 12 | POST | security::token | /security/token |
30-
| 13 | GET | user::list-user | /user |
31-
| 14 | POST | user::create-user | /user |
32-
| 15 | DELETE | user::delete-account | /user/account |
33-
| 16 | GET | user::view-account | /user/account |
34-
| 17 | PATCH | user::update-account | /user/account |
35-
| 18 | POST | user::create-account | /user/account |
36-
| 19 | POST | user::request-activate-account | /user/account/activate |
37-
| 20 | PATCH | user::activate-account | /user/account/activate/{hash} |
38-
| 21 | DELETE | user::delete-account-avatar | /user/account/avatar |
39-
| 22 | GET | user::view-account-avatar | /user/account/avatar |
40-
| 23 | POST | user::create-account-avatar | /user/account/avatar |
41-
| 24 | POST | user::recover-account | /user/account/recover |
42-
| 25 | POST | user::create-account-reset-password | /user/account/reset-password |
43-
| 26 | GET | user::check-account-reset-password | /user/account/reset-password/{hash} |
44-
| 27 | PATCH | user::update-account-reset-password | /user/account/reset-password/{hash} |
45-
| 28 | GET | user::list-role | /user/role |
46-
| 29 | GET | user::view-role | /user/role/{uuid} |
47-
| 30 | DELETE | user::delete-user | /user/{uuid} |
48-
| 31 | GET | user::view-user | /user/{uuid} |
49-
| 32 | PATCH | user::update-user | /user/{uuid} |
50-
| 33 | PATCH | user::activate-user | /user/{uuid}/activate |
51-
| 34 | DELETE | user::delete-user-avatar | /user/{uuid}/avatar |
52-
| 35 | GET | user::view-user-avatar | /user/{uuid}/avatar |
53-
| 36 | POST | user::create-user-avatar | /user/{uuid}/avatar |
54-
| 37 | PATCH | user::deactivate-user | /user/{uuid}/deactivate |
29+
| 12 | POST | security::generate-token | /security/generate-token |
30+
| 13 | POST | security::refresh-token | /security/refresh-token |
31+
| 14 | GET | user::list-user | /user |
32+
| 15 | POST | user::create-user | /user |
33+
| 16 | DELETE | user::delete-account | /user/account |
34+
| 17 | GET | user::view-account | /user/account |
35+
| 18 | PATCH | user::update-account | /user/account |
36+
| 19 | POST | user::create-account | /user/account |
37+
| 20 | POST | user::request-activate-account | /user/account/activate |
38+
| 21 | PATCH | user::activate-account | /user/account/activate/{hash} |
39+
| 22 | DELETE | user::delete-account-avatar | /user/account/avatar |
40+
| 23 | GET | user::view-account-avatar | /user/account/avatar |
41+
| 24 | POST | user::create-account-avatar | /user/account/avatar |
42+
| 25 | POST | user::recover-account | /user/account/recover |
43+
| 26 | POST | user::create-account-reset-password | /user/account/reset-password |
44+
| 27 | GET | user::check-account-reset-password | /user/account/reset-password/{hash} |
45+
| 28 | PATCH | user::update-account-reset-password | /user/account/reset-password/{hash} |
46+
| 29 | GET | user::list-role | /user/role |
47+
| 30 | GET | user::view-role | /user/role/{uuid} |
48+
| 31 | DELETE | user::delete-user | /user/{uuid} |
49+
| 32 | GET | user::view-user | /user/{uuid} |
50+
| 33 | PATCH | user::update-user | /user/{uuid} |
51+
| 34 | PATCH | user::activate-user | /user/{uuid}/activate |
52+
| 35 | DELETE | user::delete-user-avatar | /user/{uuid}/avatar |
53+
| 36 | GET | user::view-user-avatar | /user/{uuid}/avatar |
54+
| 37 | POST | user::create-user-avatar | /user/{uuid}/avatar |
55+
| 38 | PATCH | user::deactivate-user | /user/{uuid}/deactivate |
5556
+------+----------------+-------------------------------------+-------------------------------------+
5657
```
5758

src/Security/src/OpenAPI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @see TokenEndpointHandler::handle()
1313
*/
1414
#[OA\Post(
15-
path: '/security/token',
15+
path: '/security/generate-token',
1616
description: 'Client generates access token using username and password',
1717
summary: 'Generate access token',
1818
requestBody: new OA\RequestBody(
@@ -49,7 +49,7 @@
4949
* @see TokenEndpointHandler::handle()
5050
*/
5151
#[OA\Post(
52-
path: '/security/token',
52+
path: '/security/refresh-token',
5353
description: 'Client refreshes access token using refresh token',
5454
summary: 'Refresh access token',
5555
requestBody: new OA\RequestBody(

src/Security/src/RoutesDelegator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal
2424
$routeCollector = $container->get(RouteCollectorInterface::class);
2525

2626
$routeCollector->group('/security', ErrorResponseMiddleware::class)
27-
->post('/token', TokenEndpointHandler::class, 'security::token');
27+
->post('/generate-token', TokenEndpointHandler::class, 'security::generate-token')
28+
->post('/refresh-token', TokenEndpointHandler::class, 'security::refresh-token');
2829

2930
return $callback();
3031
}

test/Functional/AuthenticationTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testAuthenticateAdmin(): void
3737
{
3838
$this->createAdmin();
3939

40-
$response = $this->post('/security/token', $this->getValidAdminAccessTokenCredentials());
40+
$response = $this->post('/security/generate-token', $this->getValidAdminAccessTokenCredentials());
4141

4242
$data = json_decode($response->getBody()->getContents(), true);
4343

@@ -59,7 +59,7 @@ public function testAuthenticateUser(): void
5959
{
6060
$this->createUser();
6161

62-
$response = $this->post('/security/token', $this->getValidFrontendAccessTokenCredentials());
62+
$response = $this->post('/security/generate-token', $this->getValidFrontendAccessTokenCredentials());
6363

6464
$data = json_decode($response->getBody()->getContents(), true);
6565

@@ -76,7 +76,7 @@ public function testAuthenticateUser(): void
7676

7777
public function testInvalidRefreshToken(): void
7878
{
79-
$response = $this->post('/security/token', $this->getInvalidFrontendRefreshTokenCredentials());
79+
$response = $this->post('/security/refresh-token', $this->getInvalidFrontendRefreshTokenCredentials());
8080

8181
$data = json_decode($response->getBody()->getContents(), true);
8282

@@ -99,7 +99,7 @@ public function testRefreshToken(): void
9999
$identity = $this->createUser()->getIdentity();
100100
$this->loginAs($identity, self::DEFAULT_PASSWORD);
101101

102-
$response = $this->post('/security/token', $this->getValidFrontendRefreshTokenCredentials());
102+
$response = $this->post('/security/refresh-token', $this->getValidFrontendRefreshTokenCredentials());
103103
$this->assertResponseOk($response);
104104

105105
$data = json_decode($response->getBody()->getContents(), true);
@@ -122,7 +122,7 @@ public function testAdminCannotAuthenticateAsUser(): void
122122
$admin = $this->createAdmin();
123123
$errorMessages = $this->getContainer()->get('config')['authentication']['invalid_credentials'];
124124

125-
$response = $this->post('/security/token', $this->getValidFrontendAccessTokenCredentials([
125+
$response = $this->post('/security/generate-token', $this->getValidFrontendAccessTokenCredentials([
126126
'username' => $admin->getIdentity(),
127127
]));
128128

@@ -146,7 +146,7 @@ public function testUserCannotAuthenticateAsAdmin(): void
146146
$errorMessages = $this->getContainer()->get('config')['authentication']['invalid_credentials'];
147147

148148
$user = $this->createUser();
149-
$response = $this->post('/security/token', $this->getValidAdminAccessTokenCredentials([
149+
$response = $this->post('/security/generate-token', $this->getValidAdminAccessTokenCredentials([
150150
'username' => $user->getIdentity(),
151151
]));
152152

@@ -170,7 +170,7 @@ private function authenticateInvalidIdentity(array $credentials): void
170170
{
171171
$errorMessages = $this->getContainer()->get('config')['authentication']['invalid_credentials'];
172172

173-
$response = $this->post('/security/token', $credentials);
173+
$response = $this->post('/security/generate-token', $credentials);
174174
$this->assertResponseBadRequest($response);
175175

176176
$data = json_decode($response->getBody()->getContents(), true);

0 commit comments

Comments
 (0)