Completed
Push — master ( e7aef5...b1aac2 )
by Avtandil
03:02
created

SimpleBasicAuth::handle()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 2
dl 0
loc 14
ccs 0
cts 7
cp 0
crap 20
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Laravel Lodash package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
declare(strict_types=1);
11
12
namespace Longman\LaravelLodash\Middlewares;
13
14
use Closure;
15
use Illuminate\Http\Response;
16
17
use function config;
18
use function response;
19
20
class SimpleBasicAuth
21
{
22
    public function handle($request, Closure $next)
23
    {
24
        $config = config('auth.simple', []);
25
26
        if (! empty($config['enabled'])) {
27
            if ($request->getUser() !== $config['user'] || $request->getPassword() !== $config['password']) {
28
                $header = ['WWW-Authenticate' => 'Basic'];
29
30
                return response('You have to supply your credentials to access this resource.', Response::HTTP_UNAUTHORIZED, $header);
31
            }
32
        }
33
34
        return $next($request);
35
    }
36
}
37