Files
oficial/app/src/Service/API.php
2024-08-27 14:45:21 -04:00

24 lines
622 B
PHP

<?php
namespace Incoviba\Service;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Ideal;
use Incoviba\Exception\MissingAuthorizationHeader;
class API extends Ideal\Service
{
/**
* @throws MissingAuthorizationHeader
*/
public function getKey(ServerRequestInterface $request): string
{
$auth_headers = $request->getHeader('Authorization');
foreach ($auth_headers as $header) {
if (str_contains($header, 'Bearer')) {
return substr($header, strlen('Bearer '));
}
}
throw new MissingAuthorizationHeader();
}
}