Skip to content

Commit f8161af

Browse files
Introduce Authentication and Authorization plugins (#1924)
* feat: introduce authentication plugin * feat: add ApplicationMiddleware * feat: postman update * feat: load auth_providers + UUID implementation * chore: cs fix * refactor: use `grant_type` methods * fix: handle UUID auth header case * feat: OAuth2 authentication * chore: use `AbstractIdentifier` * refactor: DinamicForm + minor changes * feat: OTP auth * feat: `isIdentityRequired` method * fix: `afterIdentify` event * refactor: remove old authenticate classes * chore: do not use config but set finder instead * test: remove tests + TokenMiddleware ref * fix: update or comment Auth component references * refactor: use return types * chore: use `grant_type` * feat: update identity usage * feat: restore password hasher fallback * chore: comment `setGrantType` for now * chore: comment unnecessary tests * feat: add `LoggedUserMiddleware` * feat: add authorization plugin * feat: endpoint policy * fix: use checkAcceptable * refactor: remove unused EndpointAuthorize class * chore: @var annotations * refactor: fix tests, add auth checks, code style * fix: add auth checks * test: update login tests * chore: remove commented lines [ci skip] * chore: remove commented lines * feat: handle `Authentication.afterIdentify` * refactor: handle various `/auth` cases * refactor: cleanup controller actions * chore: remove attribute * refactor: code improvements * test: update unit tests * fix: add `enabled` finder * chore: use string constants * test: identifier tests * refactor: update identifiers * test: identifier related tests * test: update tests * fix: add `otp` field * chore: remove unnecessary lines * feat: handle `ExpiredTokenException` * refactor: checkLoggedUser/setupLoggedUser methods * chore: minor middleware refactor * test: update controller tests * fix: handle empty result * test: `AuthenticationComponent` test * test: use `AuthenticationService` in tests * chore: don't use class property * refactor: simplify some methods * test: add ApplicationMiddleware tests * test: endpoint policy test * doc: rename postman files * test: refactor extracting reusable logic in trait * test: add LoggedUserMiddleware tests * refactor: endpointperms signature + test * chore: cover expired token exception * test: fix test + improve coverage * chore: add fixtures * test: remove parenthesis from @dataProvder * test: fix invalid daya provider * chore: use class const * test: 403 on auth failure Co-authored-by: stefanorosanelli <[email protected]>
1 parent fef3d10 commit f8161af

File tree

70 files changed

+9009
-5845
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+9009
-5845
lines changed

composer.json

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
],
2323
"require": {
2424
"php": "^7.4 || ^8.0",
25+
"cakephp/authentication": "^2.9",
26+
"cakephp/authorization": "^2.2",
2527
"cakephp/cakephp": "~4.4.1",
2628
"firebase/php-jwt": "^5.5.1"
2729
},

config/routes.php

+12-17
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,30 @@
6262
);
6363

6464
// Login.
65-
$routes->connect(
65+
$routes->post(
6666
'/auth',
67-
['controller' => 'Login', 'action' => 'login', '_method' => 'POST'],
68-
['_name' => 'login']
67+
['controller' => 'Login', 'action' => 'login'],
68+
'login'
6969
);
70-
$routes->connect(
70+
$routes->post(
7171
'/auth/optout',
72-
['controller' => 'Login', 'action' => 'optout', '_method' => 'POST'],
73-
['_name' => 'login:optout']
72+
['controller' => 'Login', 'action' => 'optout'],
73+
'login:optout'
7474
);
7575
$routes->connect(
7676
'/auth/change',
7777
['controller' => 'Login', 'action' => 'change'],
7878
['_name' => 'login:change']
7979
);
80-
// GET /auth *deprecated* - to remove before `stable` relase
81-
$routes->connect(
82-
'/auth',
83-
['controller' => 'Login', 'action' => 'whoami', '_method' => 'GET']
84-
);
85-
$routes->connect(
80+
$routes->get(
8681
'/auth/user',
87-
['controller' => 'Login', 'action' => 'whoami', '_method' => 'GET'],
88-
['_name' => 'login:whoami']
82+
['controller' => 'Login', 'action' => 'whoami'],
83+
'login:whoami',
8984
);
90-
$routes->connect(
85+
$routes->patch(
9186
'/auth/user',
92-
['controller' => 'Login', 'action' => 'update', '_method' => 'PATCH'],
93-
['_name' => 'login:update']
87+
['controller' => 'Login', 'action' => 'update'],
88+
'login:update'
9489
);
9590

9691
// Signup.

postman/BE4-template.postman_environment.json postman/BE5-template.postman_environment.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "7054b9c8-4e47-4eac-863e-708b8ff3455d",
3-
"name": "BE4-template",
3+
"name": "BE5-template",
44
"values": [
55
{
66
"enabled": true,

0 commit comments

Comments
 (0)