123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace App\Http\Middleware;
- use App\Repositories\Enums\ResponseCodeEnum;
- use App\Repositories\Models\Log;
- use Closure;
- use Illuminate\Auth\Access\AuthorizationException;
- use Illuminate\Contracts\Auth\Factory as Auth;
- use Illuminate\Http\Request;
- use Illuminate\Support\Str;
- class Authenticate
- {
- /**
- * The authentication guard factory instance.
- *
- * @var Auth
- */
- protected $auth;
- /**
- * Create a new middleware instance.
- *
- * @param Auth $auth
- */
- public function __construct(Auth $auth)
- {
- $this->auth = $auth;
- }
- /**
- * Handle an incoming request.
- *
- * @param Request $request
- * @param Closure $next
- * @param string|null $guard
- *
- * @return mixed
- *
- * @throws AuthorizationException
- */
- public function handle($request, Closure $next, $guard = null)
- {
- if ($this->auth->guard($guard)->guest()) {
- abort(ResponseCodeEnum::HTTP_UNAUTHORIZED);
- }
- return $next($request);
- }
- }
|