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

SimpleBasicAuth   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 4
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