<?php

namespace App\Http\Middleware;

use Closure;

class MtcBasicAuth
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */

    public function handle($request, Closure $next, $allowed_user, $allowed_pass)
    {
        $provided_user = $request->getUser();
        $provided_pass = $request->getPassword();

        if ($provided_user && $provided_pass && $provided_user == $allowed_user && $provided_pass == $allowed_pass) {
            return $next($request);
        }

        return response('Unauthorized', 401, ['WWW-Authenticate' => 'Basic']);
    }
}
