API Service para manejo de token

This commit is contained in:
Juan Pablo Vial
2024-08-27 14:45:21 -04:00
parent f3d9b58ffb
commit f85af642d2

23
app/src/Service/API.php Normal file
View File

@ -0,0 +1,23 @@
<?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();
}
}