You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
750 B
32 lines
750 B
<?php |
|
|
|
namespace App\Http\Middleware; |
|
|
|
use App\Services\ApiAuthService; |
|
use Closure; |
|
use Illuminate\Http\Request; |
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
class ApiAuthenticate |
|
{ |
|
public function __construct( |
|
private readonly ApiAuthService $apiAuth |
|
) { |
|
} |
|
|
|
public function handle(Request $request, Closure $next): Response |
|
{ |
|
$actor = $this->apiAuth->authenticate($request); |
|
|
|
if ($actor === null) { |
|
return response()->json([ |
|
'error' => 'unauthorized', |
|
'message' => 'Valid API Token, LDAP JWT, or OAuth2 Bearer token required.', |
|
], 401); |
|
} |
|
|
|
$request->attributes->set('api_actor', $actor); |
|
|
|
return $next($request); |
|
} |
|
}
|
|
|