aboutsummaryrefslogtreecommitdiff
path: root/middlewares/BasicAuthMiddleware.php
blob: 6b0803e268c70e76c55de53641ec6adb69962a17 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php

declare(strict_types=1);

/**
 * HTTP Basic auth check
 */
class BasicAuthMiddleware implements Middleware
{
    public function __invoke(Request $request, $next): Response
    {
        if (!Configuration::getConfig('authentication', 'enable')) {
            return $next($request);
        }

        if (Configuration::getConfig('authentication', 'password') === '') {
            return new Response('The authentication password cannot be the empty string', 500);
        }
        $user = $request->server('PHP_AUTH_USER');
        $password = $request->server('PHP_AUTH_PW');
        if ($user === null || $password === null) {
            $html = render(__DIR__ . '/../templates/error.html.php', [
                'message' => 'Please authenticate in order to access this instance!',
            ]);
            return new Response($html, 401, ['WWW-Authenticate' => 'Basic realm="RSS-Bridge"']);
        }
        if (
            (Configuration::getConfig('authentication', 'username') !== $user)
            || (!hash_equals(Configuration::getConfig('authentication', 'password'), $password))
        ) {
            $html = render(__DIR__ . '/../templates/error.html.php', [
                'message' => 'Please authenticate in order to access this instance!',
            ]);
            return new Response($html, 401, ['WWW-Authenticate' => 'Basic realm="RSS-Bridge"']);
        }
        return $next($request);
    }
}
jarred/upgrade-zig-2 Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/bundled (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-06-22Disable modules in the linkerGravatar Jarred Sumner 1-0/+6
2022-06-22this assertion isn't good enoughGravatar Jarred Sumner 1-1/+1
2022-06-22Disable modules constently for bun in`bun bun`Gravatar Jarred Sumner 1-0/+16
2022-06-22Fix bug with exceptions inside EventTargetGravatar Jarred Sumner 11-137/+413
2022-06-22Add a way to schedule microtasks from C++Gravatar Jarred Sumner 5-35/+77
2022-06-22Update javascript.zigGravatar Jarred Sumner 1-13/+152
2022-06-22Clean up perf hooks a littleGravatar Jarred Sumner 1-9/+21
2022-06-22use JSValue for `bun test`Gravatar Jarred Sumner 1-13/+19