Skip to content

Commit 0e8e09d

Browse files
committed
Merge branch 'release/3.2.2'
2 parents b595ea8 + 3e564dc commit 0e8e09d

6 files changed

Lines changed: 26 additions & 49 deletions

File tree

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: true
1616
matrix:
17-
php: [ 8.0 ]
17+
php: [ 8.0, 8.1, 8.2 ]
1818
stability: [ prefer-lowest, prefer-stable ]
1919

2020
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [3.2.2] - 2023-03-03
8+
9+
- Fix Basic Authentication Middleware registration.
10+
711
## [3.2.1] - 2022-11-28
812

913
- Minor changes to plugin documentation.

Plugin.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
namespace Vdlp\BasicAuthentication;
66

77
use Backend\Helpers\Backend as BackendHelper;
8-
use Illuminate\Routing\Router;
9-
use October\Rain\Foundation\Application;
8+
use Illuminate\Contracts\Http\Kernel;
109
use System\Classes\PluginBase;
1110
use Vdlp\BasicAuthentication\Console\CreateCredentialsCommand;
1211
use Vdlp\BasicAuthentication\Http\Middleware\BasicAuthenticationMiddleware;
@@ -24,29 +23,25 @@ public function pluginDetails(): array
2423
];
2524
}
2625

27-
public function register(): void
28-
{
29-
$this->app->register(BasicAuthenticationServiceProvider::class);
30-
31-
$this->registerConsoleCommand(CreateCredentialsCommand::class, CreateCredentialsCommand::class);
32-
}
33-
3426
public function boot(): void
3527
{
36-
/** @var Application $application */
37-
$application = $this->app;
38-
3928
if (
4029
(bool) config('basicauthentication.enabled', false) === false
41-
|| $application->runningInConsole()
42-
|| $application->runningUnitTests()
30+
|| $this->app->runningInConsole()
31+
|| $this->app->runningUnitTests()
4332
) {
4433
return;
4534
}
4635

47-
/** @var Router $router */
48-
$router = $application->make(Router::class);
49-
$router->pushMiddlewareToGroup('web', BasicAuthenticationMiddleware::class);
36+
$this->app[Kernel::class]
37+
->pushMiddleware(BasicAuthenticationMiddleware::class);
38+
}
39+
40+
public function register(): void
41+
{
42+
$this->app->register(BasicAuthenticationServiceProvider::class);
43+
44+
$this->registerConsoleCommand(CreateCredentialsCommand::class, CreateCredentialsCommand::class);
5045
}
5146

5247
public function registerPermissions(): array

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"require": {
1616
"php": "^8.0.2",
1717
"composer/installers": "^1.0 || ^2.0",
18-
"october/system": ">=2.0"
18+
"october/rain": ">=2.0"
1919
},
2020
"repositories": [
2121
{

http/middleware/BasicAuthenticationMiddleware.php

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,22 @@
66

77
use Closure;
88
use Illuminate\Contracts\Hashing\Hasher;
9-
use Illuminate\Contracts\Session\Session;
109
use Illuminate\Contracts\Translation\Translator;
11-
use Illuminate\Database\Eloquent\ModelNotFoundException;
1210
use Illuminate\Http\Request;
1311
use Illuminate\Http\Response;
1412
use Illuminate\Support\Str;
15-
use InvalidArgumentException;
16-
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
13+
use Throwable;
1714
use Vdlp\BasicAuthentication\Models\Credential;
1815

1916
final class BasicAuthenticationMiddleware
2017
{
21-
private Session $session;
22-
private Translator $translator;
23-
private Hasher $hasher;
24-
25-
public function __construct(Session $session, Translator $translator, Hasher $hasher)
26-
{
27-
$this->session = $session;
28-
$this->translator = $translator;
29-
$this->hasher = $hasher;
18+
public function __construct(
19+
private Translator $translator,
20+
private Hasher $hasher,
21+
) {
3022
}
3123

32-
/**
33-
* @return mixed
34-
*
35-
* @throws SuspiciousOperationException
36-
* @throws InvalidArgumentException
37-
*/
38-
public function handle(Request $request, Closure $next)
24+
public function handle(Request $request, Closure $next): mixed
3925
{
4026
if ($this->isIpAddressWhitelisted((string) $request->ip())) {
4127
return $next($request);
@@ -47,7 +33,7 @@ public function handle(Request $request, Closure $next)
4733
->where('hostname', $request->getHost())
4834
->where('is_enabled', true)
4935
->firstOrFail(['hostname', 'username', 'password', 'realm', 'whitelist']);
50-
} catch (ModelNotFoundException $exception) {
36+
} catch (Throwable) {
5137
// @ignoreException
5238
return $next($request);
5339
}
@@ -59,13 +45,6 @@ public function handle(Request $request, Closure $next)
5945
return $next($request);
6046
}
6147

62-
$sessionKey = str_slug(str_replace('.', '_', $credential->hostname) . '_basic_authentication');
63-
64-
// Session is authorized.
65-
if ($this->session->has($sessionKey)) {
66-
return $next($request);
67-
}
68-
6948
$needsRehash = $this->hasher->needsRehash($credential->password);
7049

7150
// Validate credentials.
@@ -80,8 +59,6 @@ public function handle(Request $request, Closure $next)
8059
return $this->getUnauthorizedResponse($credential);
8160
}
8261

83-
$this->session->put($sessionKey, $request->getUser());
84-
8562
return $next($request);
8663
}
8764

updates/version.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ v3.0.2:
1616
v3.1.0: "Add October CMS 3.x to supported versions."
1717
v3.2.0: "Basic Authentication added to October CMS backend routes."
1818
v3.2.1: "Minor changes to plugin documentation."
19+
v3.2.2: "Fix Basic Authentication Middleware registration."

0 commit comments

Comments
 (0)