Skip to content

Commit 133cbdc

Browse files
committed
fixes multiples auth
1 parent 460362d commit 133cbdc

File tree

12 files changed

+233
-181
lines changed

12 files changed

+233
-181
lines changed

composer.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"codeigniter4/devkit": "^1",
2727
"codeigniter4/framework": "^4",
2828
"mikey179/vfsstream": "^1",
29-
"mockery/mockery": "^1"
29+
"mockery/mockery": "^1",
30+
"rector/rector": "0.15.12"
3031
},
3132
"autoload":
3233
{
@@ -50,16 +51,14 @@
5051
"bash admin/setup.sh"
5152
],
5253
"analyze": [
53-
"phpstan analyze",
54-
"psalm",
55-
"rector process --dry-run"
54+
"vendor/bin/phpstan analyze",
55+
"vendor/bin/rector process --dry-run"
5656
],
5757
"sa": "@analyze",
5858
"ci": [
5959
"Composer\\Config::disableProcessTimeout",
6060
"@cs",
6161
"@deduplicate",
62-
"@inspect",
6362
"@analyze",
6463
"@test"
6564
],
@@ -71,11 +70,13 @@
7170
"php-cs-fixer fix src --ansi --verbose --diff",
7271
"php-cs-fixer fix tests --ansi --verbose --diff"
7372
],
74-
"deduplicate": "phpcpd app/ src/ --exclude src/Database/Migrations/2023-03-13-000001_create_core_tables.php",
75-
"inspect": "deptrac analyze --cache-file=build/deptrac.cache",
73+
"deduplicate": "php phpcpd.phar src/ --exclude src/Database/Migrations/2023-03-13-000001_create_core_tables.php",
7674
"mutate": "infection --threads=2 --skip-initial-tests --coverage=build/phpunit",
7775
"style": "@cs-fix",
78-
"test": "vendor/bin/phpunit"
76+
"test": [
77+
"Composer\\Config::disableProcessTimeout",
78+
"vendor/bin/phpunit"
79+
]
7980
},
8081
"config": {
8182
"allow-plugins": {

phpcpd.phar

69.1 KB
Binary file not shown.

rector.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->paths([
11+
__DIR__ . '/src',
12+
__DIR__ . '/tests',
13+
]);
14+
15+
// register a single rule
16+
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
17+
18+
// define sets of rules
19+
// $rectorConfig->sets([
20+
// LevelSetList::UP_TO_PHP_74
21+
// ]);
22+
};

src/Authenticators/AccessToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AccessToken extends Base implements AuthenticatorInterface
1717

1818
public function __construct(UserModel $provider)
1919
{
20-
$this->method = 'session';
20+
$this->method = 'token';
2121
$this->provider = $provider;
2222
parent::__construct();
2323
}

src/Authenticators/Base.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,16 @@ protected function checkLogin(?string $username = null, ?string $password = null
5555
$this->forceLogin();
5656
}
5757

58-
$authSource = service('settings')->get('RestFul.authSource');
58+
5959
$authMethod = \strtolower($this->method);
6060

61+
$authSource = null;
62+
if(isset(service('settings')->get('RestFul.authSource')[$this->method])) {
63+
$authSource = service('settings')->get('RestFul.authSource')[$this->method];
64+
}
65+
66+
$authSource = service('settings')->get('RestFul.authSource')[$this->method];
67+
6168
if ($authSource === 'library') {
6269
log_message('debug', "Performing Library authentication for $username");
6370

src/Authenticators/Session.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public function check(): ?User
2424
$session = \Config\Services::session();
2525

2626
// If false, then the user isn't logged in
27-
if (!$session->get(service('settings')->get('RestFul.authSource'))) {
27+
if (!$session->get(service('settings')->get('RestFul.authSource')[$this->method])) {
2828
throw AuthenticationException::forInvalidCredentials();
2929
}
3030

31-
return $this->checkLogin($session->get(service('settings')->get('RestFul.authSource')));
31+
return $this->checkLogin($session->get(service('settings')->get('RestFul.authSource')[$this->method]));
3232
}
3333

3434
/**

src/Config/RestFul.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,16 @@ class RestFul extends BaseConfig
108108
*
109109
* e.g: md5('admin:REST API:1234') = '1e957ebc35631ab22d5bd6526bd14ea2'
110110
*
111-
* @var string
111+
* @var array
112112
*/
113-
public ?string $authSource = null;
113+
public array $authSource = [
114+
'basic' => null,
115+
'digest' => null,
116+
'bearer' => null,
117+
'session' => null,
118+
'whitelist' => null,
119+
'token' => null
120+
];
114121

115122
/**
116123
* --------------------------------------------------------------------
@@ -123,10 +130,12 @@ class RestFul extends BaseConfig
123130

124131
public array $libraryCustomAuthenticators =
125132
[
126-
'basic' => null,
127-
'digest' => null,
128-
'bearer' => null,
129-
'session' => null
133+
'basic' => null,
134+
'digest' => null,
135+
'bearer' => null,
136+
'session' => null,
137+
'whitelist' => null,
138+
'token' => null
130139
];
131140

132141
/**

0 commit comments

Comments
 (0)