Skip to content

Commit

Permalink
fixes multiples auth
Browse files Browse the repository at this point in the history
  • Loading branch information
daycry committed Jun 21, 2023
1 parent 460362d commit 133cbdc
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 181 deletions.
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"codeigniter4/devkit": "^1",
"codeigniter4/framework": "^4",
"mikey179/vfsstream": "^1",
"mockery/mockery": "^1"
"mockery/mockery": "^1",
"rector/rector": "0.15.12"
},
"autoload":
{
Expand All @@ -50,16 +51,14 @@
"bash admin/setup.sh"
],
"analyze": [
"phpstan analyze",
"psalm",
"rector process --dry-run"
"vendor/bin/phpstan analyze",
"vendor/bin/rector process --dry-run"
],
"sa": "@analyze",
"ci": [
"Composer\\Config::disableProcessTimeout",
"@cs",
"@deduplicate",
"@inspect",
"@analyze",
"@test"
],
Expand All @@ -71,11 +70,13 @@
"php-cs-fixer fix src --ansi --verbose --diff",
"php-cs-fixer fix tests --ansi --verbose --diff"
],
"deduplicate": "phpcpd app/ src/ --exclude src/Database/Migrations/2023-03-13-000001_create_core_tables.php",
"inspect": "deptrac analyze --cache-file=build/deptrac.cache",
"deduplicate": "php phpcpd.phar src/ --exclude src/Database/Migrations/2023-03-13-000001_create_core_tables.php",
"mutate": "infection --threads=2 --skip-initial-tests --coverage=build/phpunit",
"style": "@cs-fix",
"test": "vendor/bin/phpunit"
"test": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/phpunit"
]
},
"config": {
"allow-plugins": {
Expand Down
Binary file added phpcpd.phar
Binary file not shown.
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
// $rectorConfig->sets([
// LevelSetList::UP_TO_PHP_74
// ]);
};
2 changes: 1 addition & 1 deletion src/Authenticators/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AccessToken extends Base implements AuthenticatorInterface

public function __construct(UserModel $provider)
{
$this->method = 'session';
$this->method = 'token';
$this->provider = $provider;
parent::__construct();
}
Expand Down
9 changes: 8 additions & 1 deletion src/Authenticators/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,16 @@ protected function checkLogin(?string $username = null, ?string $password = null
$this->forceLogin();
}

$authSource = service('settings')->get('RestFul.authSource');

$authMethod = \strtolower($this->method);

$authSource = null;
if(isset(service('settings')->get('RestFul.authSource')[$this->method])) {
$authSource = service('settings')->get('RestFul.authSource')[$this->method];
}

$authSource = service('settings')->get('RestFul.authSource')[$this->method];

if ($authSource === 'library') {
log_message('debug', "Performing Library authentication for $username");

Expand Down
4 changes: 2 additions & 2 deletions src/Authenticators/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public function check(): ?User
$session = \Config\Services::session();

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

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

/**
Expand Down
21 changes: 15 additions & 6 deletions src/Config/RestFul.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,16 @@ class RestFul extends BaseConfig
*
* e.g: md5('admin:REST API:1234') = '1e957ebc35631ab22d5bd6526bd14ea2'
*
* @var string
* @var array
*/
public ?string $authSource = null;
public array $authSource = [
'basic' => null,
'digest' => null,
'bearer' => null,
'session' => null,
'whitelist' => null,
'token' => null
];

/**
* --------------------------------------------------------------------
Expand All @@ -123,10 +130,12 @@ class RestFul extends BaseConfig

public array $libraryCustomAuthenticators =
[
'basic' => null,
'digest' => null,
'bearer' => null,
'session' => null
'basic' => null,
'digest' => null,
'bearer' => null,
'session' => null,
'whitelist' => null,
'token' => null
];

/**
Expand Down
Loading

0 comments on commit 133cbdc

Please sign in to comment.