Completed
Push — master ( 46cd40...714c30 )
by Maxime
13:42
created

AuthenticateOnceWithBasicAuth::handle()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 17
c 2
b 0
f 0
ccs 0
cts 2
cp 0
rs 8.8571
cc 5
eloc 7
nc 4
nop 3
crap 30
1
<?php namespace Distilleries\Expendable\Http\Middleware;
2
3
use Closure;
4
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
5
6
class AuthenticateOnceWithBasicAuth extends AuthenticateWithBasicAuth {
7
8
9
    /**
10
     * Handle an incoming request.
11
     *
12
     * @param  \Illuminate\Http\Request  $request
13
     * @param  \Closure  $next
14
     * @param  string|null  $guard
15
     * @return mixed
16
     */
17
    public function handle($request, Closure $next, $guard = null)
18
    {
19
        $ipsAuth = env('BASIC_AUTH_IP','');
20
        $ipsAuth = explode(',',$ipsAuth);
21
22
23
        if (env('BASIC_AUTH',false) == true)
24
        {
25
            if(empty($ipsAuth) || !in_array($request->ip(),$ipsAuth))
26
            {
27
                return $this->auth->guard($guard)->basic() ?: $next($request);
28
            }
29
30
        }
31
32
        return $next($request);
33
    }
34
35
}